This is mostly a poke at VB's question. It's my onrespawn with a buch of extraneous stuff but also a take equipped item feature, where the higher level you are the more likely you are to lose one or more items.
#include "nw_i0_plot"
#include "x3_inc_horse"
// * Applies an XP and GP penalty chance of item loss
// * to the player respawning based on level ffbj. Help from Guyfensen of this one.
void DestroyMajorItem(object oPC)
{
object oItem;
switch(d12())
{
case 1: oItem = GetItemInSlot(INVENTORY_SLOT_ARMS,oPC); break;
case 2: oItem = GetItemInSlot(INVENTORY_SLOT_CHEST,oPC); break;
case 3: oItem = GetItemInSlot(INVENTORY_SLOT_HEAD,oPC); break;
case 4: oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC); break;
case 5: oItem = GetItemInSlot(INVENTORY_SLOT_NECK,oPC); break;
case 6: oItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oPC); break;
case 7: oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTRING,oPC); break;
case 8: oItem = GetItemInSlot(INVENTORY_SLOT_LEFTRING,oPC); break;
case 9: oItem = GetItemInSlot(INVENTORY_SLOT_BOOTS,oPC); break;
case 10: oItem = GetItemInSlot(INVENTORY_SLOT_CLOAK,oPC); break;
case 11: oItem = GetItemInSlot(INVENTORY_SLOT_BELT,oPC); break;
case 12: oItem = GetItemInSlot(INVENTORY_SLOT_ARROWS,oPC); break;
}
if ((GetIsObjectValid(oItem))&&(!GetPlotFlag(oItem)))
DestroyObject(oItem);
}
void ApplyPenalty(object oDead)
{
int nXP = GetXP(oDead);
int nPenalty = 100 * 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;
if (nNewXP < nMin)
nNewXP = nMin;
SetXP(oDead, nNewXP);
DelayCommand(5.0, FloatingTextStringOnCreature("XP Loss", oDead, FALSE));
}
void main()
{
object oPC = GetLastRespawnButtonPresser();
object oHorse = HorseGetHorse(oPC,1);
object oDatabase = GetItemPossessedBy(oPC, "database");
effect eRaise = EffectResurrection();
object oSpawnPoint = GetWaypointByTag ("WP_CCFB");
object oSpawnPoint1 = GetWaypointByTag ("WP_JailCFB");
int iHD = GetHitDice(oPC);
HorseIfNotDefaultAppearanceChange(oPC);
if (GetCreatureTailType(oPC) == 0)
{
SetCreatureTailType(14, oPC);
}
if (GetLocalInt(oDatabase, "MountI") > 0)
{
HorseDismount(TRUE, TRUE);
HorseRemoveOwner(oHorse);
DeleteLocalInt(oDatabase,"MountI");
//delete and dismount
DestroyObject(oHorse, 1.0f);
}
effect eEffect = EffectAbilityDecrease(ABILITY_CONSTITUTION, 4);
DelayCommand (2.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eRaise, oPC));
DelayCommand(6.0, FloatingTextStringOnCreature("You must rest after your recent exploits", oPC, FALSE));
DelayCommand(8.0, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oPC, 100.0 + (iHD * 4)));
//Apply the heal, raise dead and VFX impact effect
FloatingTextStringOnCreature("Miraculous Recovery",oPC,FALSE);
DeleteLocalInt(oDatabase, "Expired");
if (GetLocalInt(oDatabase, "Jailed") == 1)
{
DelayCommand(2.2, AssignCommand(oPC, JumpToLocation(GetLocation(oSpawnPoint1))));
DelayCommand(4.0, FloatingTextStringOnCreature("Incarcerated", oPC, FALSE));
DelayCommand (300.0, (DeleteLocalInt (oDatabase, "Jailed")));
return;
}
if ((oSpawnPoint!=OBJECT_INVALID) && (GetItemPossessedBy(oPC, "CoffinReceipt")!= OBJECT_INVALID))
{
DelayCommand(2.2, AssignCommand(oPC, JumpToLocation(GetLocation(oSpawnPoint))));
DelayCommand (4.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(d6(iHD)),oPC));
}
//Apply the heal, raise dead and VFX impact effect
else DelayCommand (3.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(d4(iHD)),oPC));
if (GetLocalInt(oDatabase,"NaggingWound") > 10)
{
DelayCommand(25.0 + (iHD * 2), ExecuteScript("naggingwound",oPC));
}
if (iHD < 5)
return;
ApplyPenalty(oPC);
//set local based on level of PC
if (iHD <
SetLocalInt(oPC,"TakeItem",1);
else if (iHD < 12)
SetLocalInt(oPC,"TakeItem",2);
else if (iHD < 20)
SetLocalInt(oPC,"TakeItem",3);
else if (iHD < 25)
SetLocalInt(oPC,"TakeItem",4);
else
SetLocalInt(oPC,"TakeItem",5);
while (GetLocalInt(oPC,"TakeItem")> 0)
if (d6()> 5)//1 in 6 chance you lose something on each loop
{
DestroyMajorItem(oPC);
SetLocalInt(oPC,"TakeItem", GetLocalInt(oPC,"TakeItem")-1);
}
}