Rune_PRC8/_module/nss/opa_clse_packbox.nss
Jaysyn904 d1c309ae63 Initial commit
Initial commit
2024-09-13 09:10:39 -04:00

76 lines
2.2 KiB
Plaintext

////////////////////////////////////////////////////////////////////////////////
//
// Olander's Pack Animals
// opa_clse_packbox
// By Don Anderson
// dandersonru@msn.com
//
// Saves Pack Animal Box Inventory
//
////////////////////////////////////////////////////////////////////////////////
#include "opa_inc"
void EndSaveRoutine(object oStore, string sDB, object oPC)
{
StoreCampaignObject(sDB, "PackBox", oStore, oPC );
DestroyObject(oStore);
SetLocked(OBJECT_SELF, TRUE);
DelayCommand(10.0, SetLocked(OBJECT_SELF, FALSE));
}
void RecursiveChestSave(object oStore, string sDB, object oPC, int iFirst=TRUE)
{
object oItem = GetFirstItemInInventory();
while(oItem != OBJECT_INVALID)
{
if(!iFirst || GetHasInventory(oItem))
{
ActionGiveItem(oItem, oStore);
}
oItem = GetNextItemInInventory();
}
if(iFirst)
{
AssignCommand(OBJECT_SELF, ActionDoCommand(RecursiveChestSave(oStore, sDB, oPC, FALSE)));
return;
}
AssignCommand(OBJECT_SELF,ActionDoCommand(EndSaveRoutine(oStore, sDB, oPC)));
}
void main()
{
object oBox = OBJECT_SELF;
object oPC = GetLastClosedBy();
object oAnimal = GetLocalObject(oBox,"PackAnimal");
string sName = GetName(oPC);
string sLeft = GetStringLeft(sName,4);
string sDB = "PACKBOX_" + sLeft;
//Check out the New Weight of Pack Box and Adjust Animal Weight
int nBoxWeight = BoxWeight(oBox)/10;
int nStones = nBoxWeight/5;
//Now we Destroy all the objects in the Animal Inventory
object oItem = GetFirstItemInInventory(oAnimal);
while (oItem != OBJECT_INVALID)
{
DestroyObject(oItem);
oItem = GetNextItemInInventory(oAnimal);
}
//Now Give Enough Stones to Set Weight on Animal
SetAnimalWeight(oAnimal, nStones);
//Now Save the Pack Box Inventory
object oStore = CreateObject(OBJECT_TYPE_CREATURE, "packanimal", GetLocation(oBox), FALSE);
effect eVis = EffectInvisibility(INVISIBILITY_TYPE_IMPROVED);
effect eImm = EffectCutsceneImmobilize();
ApplyEffectToObject(DURATION_TYPE_INSTANT,eVis,oStore);
ApplyEffectToObject(DURATION_TYPE_INSTANT,eImm,oStore);
RecursiveChestSave(oStore, sDB, oPC);
DelayCommand(10.0,SetLocalInt(oPC,"OPA_TRANSFERRED",TRUE));
}