HiddenTradition_PRC8/_module/nss/ro_m_respawndrop.nss
2024-06-20 15:47:42 -04:00

289 lines
7.8 KiB
Plaintext

#include "nw_i0_plot"
//Drop items on death code
//Will give a percentage chance of each item in inventory being dropped
//Default = 5%
int GetIsDropItem(object oItem)
{
if (!GetIsObjectValid(oItem)) return FALSE;
string sTag = GetTag(oItem);
// items that are always dropped upon respawn
if (sTag == "HuraquaiSpawn" ||
sTag == "R_RodOfEvil" ||
sTag == "R_Test_Door_Key")
return TRUE;
// items that are dropped sometimes (1/3) on respawn
if (sTag == "DragonCrystal" ||
sTag == "LesserRingofRegeneration" ||
sTag == "R_Setable_Door_Key")
{
if (d6() >= 5)
return TRUE;
else
return FALSE;
}
return FALSE;
}
int GetIsNotDropItem(object oItem)
{
if (!GetIsObjectValid(oItem)) return FALSE;
string sTag = GetTag(oItem);
if (sTag == "R_TheStorySoFar" ||
sTag == "dmfi_pc_emote" ||
sTag == "dmfi_pc_dicebag")
return TRUE;
return FALSE;
}
void DropObjectOnGround(object oRespawner, object oDropObject, object oPlaceable)
{
if (!GetIsObjectValid(oDropObject)) return;
if (!GetIsObjectValid(oRespawner)) return;
if (!GetIsObjectValid(oPlaceable)) return;
//AssignCommand(oRespawner, ActionPutDownItem(oDropObject));
AssignCommand(oPlaceable, ActionTakeItem(oDropObject, oRespawner));
}
void DropObjects(object oRespawner)
{
object oPlaceable = CreateObject(OBJECT_TYPE_PLACEABLE, "r_dropobjectsong", GetLocation(oRespawner));
// Drop items that that can't be taken with you on a respawn
object oDropObject;
// Loop through each item in inventory and give a % chance that it will be dropped
// or drop it automatically if it's a "special" item.
object oItem = GetFirstItemInInventory(oRespawner);
while (GetIsObjectValid(oItem))
{
if (GetIsDropItem(oItem))
{
DropObjectOnGround(oRespawner, oItem, oPlaceable);
}
else if (GetIsNotDropItem(oItem))
{
// do nothing - this item can't be dropped no matter what. Skip over it.
}
else if (d100() <= 5) // 5% chance that the item will be dropped
{
DropObjectOnGround(oRespawner, oItem, oPlaceable);
}
oItem = GetNextItemInInventory(oRespawner);
}
int i;
for (i=0; i <= NUM_INVENTORY_SLOTS; i++)
{
oItem = GetItemInSlot(i, oRespawner);
if (GetIsDropItem(oItem))
{
DropObjectOnGround(oRespawner, oItem, oPlaceable);
}
}
// destroy dropped placeable
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), oPlaceable);
}
//End of drop on death code
// * Applies an XP and GP penalty
// * to the player respawning
void DeathPenalty(object oDead)
{
int nXP = GetXP(oDead);
int nPenalty = 50 * GetHitDice(oDead);
int nHD = GetHitDice(oDead);
// * You can not lose a level with this respawning
int nMin = ((nHD * (nHD - 1)) / 2) * 1000;
int nNewXP = nXP - nPenalty;
// Store Death-Penalty
if (nNewXP < nMin)
nNewXP = nMin;
SetXP(oDead, nNewXP);
int nGoldToTake = FloatToInt(0.10 * GetGold(oDead));
// * a cap of 10 000gp taken from you
if (nGoldToTake > 10000)
{
nGoldToTake = 10000;
}
AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));
}
void DeathPenaltyGrave(object oDead)
{
int nXP = GetXP(oDead);
int nPenalty = 50 * GetHitDice(oDead);
int nHD = GetHitDice(oDead);
// * You can not lose a level with this respawning
int nMin = ((nHD * (nHD - 1)) / 2) * 1000;
int nNewXP = nXP - nPenalty;
// Store Death-Penalty
if (nNewXP < nMin) nNewXP = nMin;
int nEffectiveLoss = nXP - nNewXP;
int bCreateGrave = FALSE;
int nXPRegain = GetLocalInt(GetModule(),"T1_MODULE_CFG_GRAVEEXPREGAIN");
if (nXPRegain==0) nXPRegain = 50; //default = 50
if (nXPRegain==-1) nXPRegain = 0;
if (nEffectiveLoss>0)
{
bCreateGrave = TRUE;
nEffectiveLoss = (nEffectiveLoss* nXPRegain)/100;
SetLocalInt(oDead,"T1_PLAYER_GRAVEEXP", nEffectiveLoss);
}
SetXP(oDead, nNewXP);
int nGoldToTake = FloatToInt(0.10 * GetGold(oDead));
// * a cap of 10 000gp taken from you
if (nGoldToTake > 10000)
{
nGoldToTake = 10000;
}
AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));
// Destroy Old Grave
if (GetIsObjectValid(GetLocalObject(oDead,"T1_PLAYER_LASTGRAVE")))
{
object oOldGrave = GetLocalObject(oDead,"T1_PLAYER_LASTGRAVE");
DestroyObject(oOldGrave,0.0f);
DeleteLocalObject(oDead,"T1_PLAYER_LASTGRAVE");
SendMessageToPC(oDead, "Your last grave has been destroyed");
}
if ( bCreateGrave == TRUE)
{
location lGraveLoc = GetLocation(oDead);
object oGrave = CreateObject(OBJECT_TYPE_PLACEABLE,"GZ_GRAVE_GENERIC",lGraveLoc);
SetLocalString(oGrave,"T1_OBJECT_GRAVEOWNER",GetName(oDead));
SetLocalObject(oGrave,"T1_OBJECT_PLAYER",oDead);
SetLocalObject(oDead,"T1_PLAYER_LASTGRAVE",oGrave);
SendMessageToPC(oDead, "A grave has been erected where you have been slain. Go back and pray to get back some experience");
}
else
{
DeleteLocalInt (oDead,"T1_PLAYER_GRAVEEXP"); // Destroy last GraveXP
SendMessageToPC(oDead, "You did not lose enough XP for a grave to be created");
}
}
void main()
{
object oRespawner = GetLastRespawnButtonPresser();
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oRespawner);
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oRespawner)), oRespawner);
RemoveEffects(oRespawner);
//Does drop item on death code
DropObjects(oRespawner);
//Determine which DeathMethod is being used
if (GetLocalInt(GetModule(), "T1_MODULE_CFG_NOGRAVES") == 0)
{
DeathPenaltyGrave(oRespawner);
}
else
{
DeathPenalty(oRespawner);
}
//Old Bindstone respawn code - replaced with respawn in Tuat
/*
// No Bindpoint set, use the Waypoint or Object with the following Tag
string sDestTag = GetLocalString(oRespawner,"T1_PLAYER_LASTBINDPOINT");
if (sDestTag == "" || GetLocalInt(GetModule(),"T1_MODULE_NOBINDSTONES") == TRUE)
{ // NO Bindpoint Set
sDestTag = "T1_MODULE_RESPAWN";
}
if (GetIsObjectValid(GetObjectByTag(sDestTag)))
{
object oSpawnPoint = GetObjectByTag(sDestTag);
if (GetLocalInt(oSpawnPoint,"T1_OBJECT_DISABLED") == TRUE)
{
sDestTag = "T1_MODULE_RESPAWN";
object oSpawnPoint = GetObjectByTag(sDestTag);
}
event evL = EventUserDefined(2222);
AssignCommand(oRespawner,JumpToLocation(GetLocation(oSpawnPoint)));
ActionWait(2.0f);
effect eFx = EffectVisualEffect(VFX_IMP_AURA_HOLY);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eFx, oRespawner);
SignalEvent(oSpawnPoint,evL);
}
*/
//Tuat respawn code
object oSpawnPoint = GetWaypointByTag("WP_TUAT");
AssignCommand(oRespawner,JumpToLocation(GetLocation(oSpawnPoint)));
ActionWait(2.0f);
effect eFx = EffectVisualEffect(VFX_IMP_AURA_HOLY);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eFx, oRespawner);
// This code takes the item called "death" out of the players inventory
// when they respawn.
object oItemToTake;
oItemToTake = GetItemPossessedBy(oRespawner, "Death");
if(GetIsObjectValid(oItemToTake) != 0)
DestroyObject(oItemToTake);
//PrC 2 stuff
ExecuteScript("prc_onrespawn", OBJECT_SELF);
}