I'm trying to write a simple script for a storage system but it doesn't seems to work well ^^ here are the onopen and onclose scripts:
onopen():
void main()
{
string sPC = GetPCPlayerName(GetLastOpenedBy()) + GetName(GetLastOpenedBy());
int nItems = 0;
int nTotal = GetCampaignInt("Origin", sPC);
if (nTotal == 0) return;
object oItem = RetrieveCampaignObject("Origin", sPC + IntToString(nItems), GetLocation(OBJECT_SELF), OBJECT_SELF);
while(GetIsObjectValid(oItem) && (nItems < nTotal))
{
DeleteCampaignVariable("Origin", sPC + IntToString(nItems));
nItems++;
oItem = RetrieveCampaignObject("Origin", sPC + IntToString(nItems), GetLocation(OBJECT_SELF), OBJECT_SELF);
}
SetCampaignInt("Origin", sPC, 0);
}
////
onclose():
void main()
{
string sPC = GetPCPlayerName(GetLastClosedBy()) + GetName(GetLastClosedBy());
int nItems = 0;
object oItem = GetFirstItemInInventory(OBJECT_SELF);
while (GetIsObjectValid(oItem))
{
if (GetHasInventory(oItem) == FALSE)
{
StoreCampaignObject("Origin", sPC + IntToString(nItems), oItem);
DestroyObject(oItem);
nItems++;
}
oItem = GetNextItemInInventory(OBJECT_SELF);
}
SetCampaignInt("Origin", sPC, nItems);
}
If you can point me in the right direction of how to do this plz!!