CREATE UNIQUE OBJECT ID's FOR YOUR SPAWNS.

Here is a trick that I hope will help everyone .

I used this trick in an Major Image script I wrote. I can store the saving throws of each pc, npc, and familiar vs each figment I summon. it's awesome. (yes I have illusions working as per pg 158 of the PHB! )

This trick allows you to create a unique object id for every object you spawn.

Anyway.. here it is.


add this function before main() of the on spawn event

string CreateObjectID(object o)
{
return (GetTag(o) + IntToString(GetTimeHour()) + IntToString(GetTimeMinute()) + IntToString(GetTimeSecond()) + IntToString(GetTimeMillisecond()) );
}

now in the main() function of the on spawn event type this.

SetLocalString(OBJECT_SELF, "OBJECTID", CreateObjectID(OBJECT_SELF));

then for every other event or function that needs to access the creatures local variables do this.

string sObjectID = GetLocalString(OBJECT_SELF, "MY_VAR_" + sObjectID);

to set a local variable do this.

SetLocalInt(OBJECT_SELF,"MY_VAR_" + sObjectID, 666);

now every time you get a local object variable do this:

int x = GetLocalInt(OBJECT_SELF, "MY_VAR_" + sObjectID);


In the context of my figment script, I store the saving throw result on each pc for each figment spawned.