xtrick8
Joined: 31 Jul 2006 Posts: 8 Location: Melbourne, Australia
|
Posted: Mon Jul 31, 2006 1:08 Post subject: Perisistent Storage data corruption problem |
|
|
Ok I wrote some code for some persistent storage on containers in the Persistent Player housing in my mod and it all works well. I just need to add these two scripts to onopen and onclose. Everything works great, except that every now and then an item gets substituted for something else. I suspect that it is related to some sort of string concatenation in NWNx or in the APS system. Can someone please tell me how I can make this more bullet proof please !
//::///////////////////////////////////////////////
//:: Name "HN_DRAWER_OPEN"
//:://////////////////////////////////////////////
/*
Persistent Storage Cabinet.
Place this file in the Cabinet's OnOpen event.
*/
//:://////////////////////////////////////////////
//:: Created By: Xtrick8
//:: Created On: 27 Jul 2006
//:://////////////////////////////////////////////
#include "aps_include"
void main()
{
int iItem;
int bContinue = TRUE;
object oCreated;
object oSelf = OBJECT_SELF;
string sCase = GetStringRight(GetTag(OBJECT_SELF), 3);
object oChest1 = GetObjectByTag("PCDrawer"+sCase);
// First destroy all the contents of the container
if (GetHasInventory(oSelf) == TRUE) {
object oItem = GetFirstItemInInventory(oSelf);
// destroy everything in the inventory first
while (oItem != OBJECT_INVALID)
{
DestroyObject(oItem);
oItem = GetNextItemInInventory(oSelf);
}
}
while (bContinue)
{
oCreated = GetPersistentObject(oChest1, "Item_" + IntToString(iItem), oChest1);
if (!GetIsObjectValid(oCreated))
bContinue = FALSE;
else
iItem++;
}
SendMessageToPC(GetFirstPC(), "Retrieved " + IntToString(iItem) + " objects from database.");
}
//::///////////////////////////////////////////////
//:: Name "HN_DRAWER_CLOSE"
//:://////////////////////////////////////////////
/*
Persistent Storage Cabinet.
Place this file in the Cabinet's OnClose event.
*/
//:://////////////////////////////////////////////
//:: Created By: Xtrick8
//:: Created On: 27 Jul 2006
//:://////////////////////////////////////////////
#include "aps_include"
void main()
{
int iItem;
object oSelf = OBJECT_SELF;
string sCase = GetStringRight(GetTag(OBJECT_SELF), 3);
object oChest = GetObjectByTag("PCDrawer"+sCase);
object oItem = GetFirstItemInInventory(oChest);
// Delete all entries for this object in the DB
SQLExecDirect("Delete from pwobjdata where tag = '"+"PCDrawer"+sCase+"'");
while (GetIsObjectValid(oItem))
{
SetPersistentObject(oChest, "Item_" + IntToString(iItem), oItem);
oItem = GetNextItemInInventory(oChest);
iItem++;
}
SendMessageToPC(GetFirstPC(), "Stored " + IntToString(iItem) + " objects in database.");
} _________________ - xtrick8 (Lead Writer for Noreshia)
http://www.noreshia.com/ |
|