DMH-Online

Dungeon Masters Helper · Est. 2005

Creatures Scripts

NWN Script: create_unique_objectIDs.htm

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.

⌂ All Scripts ← PreviousNext → 👁 Category List

All Creatures Scripts

📄 apply_spell_effect 📄 aurak_draconian 📄 baaz_draconian 📄 boss_spawner 📄 change_light_spawn_pt_on_death 📄 clone_mob 📄 collect_loot 📄 create_unique_objectIDs 📄 creature_proc 📄 explode_ondeath 📄 explode_ondeath_002 📄 explode_ondeath_003 📄 exploding_chickens 📄 fire_death 📄 inverse_mob 📄 iron_statue 📄 lich 📄 lootable_corpse 📄 lootable_corpse_002 📄 lootable_corpse_002a 📄 lootable_corpse_oo2 📄 mob_respawn 📄 mob_respawn_002 📄 multi_creature_spawn 📄 night_time 📄 random_death_effect 📄 random_drops 📄 random_drops_002 📄 random_drops_003 📄 random_enc_onrest 📄 random_hps 📄 sivac_draconian 📄 spawn 📄 spawn_on_hearbeat 📄 summon_last_hostile 📄 summon_mob 📄 trolls 📄 trolls_002 📄 vampire_coffin 📄 werewolf