As the title suggests, I want a creature to be assigned new scripts after it is summoned, in various positions, heartbeat, spawnin, perception, etc …
Is there a way to assign a specific script, for example, to the creature’s heartbeat, via script?
///////////////////////////////////////////////////////////////////////////////
// SetEventHandler
///////////////////////////////////////////////////////////////////////////////
// Created By: Brock Heinz - OEI
// Created On: 12/20/05
//
// Description: These commands will allow you to bind any script to the
// to an exisiting event for a given object.
// Arguments:
// oObject - The object to which you want to bind a new script
// iEventID - The event ID which you are binding the script to.
// sScriptName - The name of the script that you want to bind to the event.
// Note that it is valid to pass "" to have this creature ignore
// the event.
///////////////////////////////////////////////////////////////////////////////
void SetEventHandler( object oObject, int iEventID, string sScriptName );
///////////////////////////////////////////////////////////////////////////////
// GetEventHandler
///////////////////////////////////////////////////////////////////////////////
// Created By: Brock Heinz - OEI
// Created On: 12/20/05
//
// Description: Retrieves the name of a script bound to a given event ID
// Arguments
// oObject - The object to which you want to bind a new script
// iEventID - The event ID which you are binding the script to.
//
// Returns: Returns a string with the script name which the object has bound
// to the event. This will be empty if the creature or event ID is
// invalid.
///////////////////////////////////////////////////////////////////////////////
string GetEventHandler( object oObject, int iEventID );
// Brock H. - OEI 03/26/06 These are the script event types
// Supported by SetEventHandler() / GetEventHandler
int CREATURE_SCRIPT_ON_HEARTBEAT = 0;
int CREATURE_SCRIPT_ON_NOTICE = 1;
int CREATURE_SCRIPT_ON_SPELLCASTAT = 2;
int CREATURE_SCRIPT_ON_MELEE_ATTACKED = 3;
int CREATURE_SCRIPT_ON_DAMAGED = 4;
int CREATURE_SCRIPT_ON_DISTURBED = 5;
int CREATURE_SCRIPT_ON_END_COMBATROUND = 6;
int CREATURE_SCRIPT_ON_DIALOGUE = 7;
int CREATURE_SCRIPT_ON_SPAWN_IN = 8;
int CREATURE_SCRIPT_ON_RESTED = 9;
int CREATURE_SCRIPT_ON_DEATH = 10;
int CREATURE_SCRIPT_ON_USER_DEFINED_EVENT = 11;
int CREATURE_SCRIPT_ON_BLOCKED_BY_DOOR = 12;
// Trigger
int SCRIPT_TRIGGER_ON_HEARTBEAT = 0;
int SCRIPT_TRIGGER_ON_OBJECT_ENTER = 1;
int SCRIPT_TRIGGER_ON_OBJECT_EXIT = 2;
int SCRIPT_TRIGGER_ON_USER_DEFINED_EVENT = 3;
int SCRIPT_TRIGGER_ON_TRAPTRIGGERED = 4;
int SCRIPT_TRIGGER_ON_DISARMED = 5;
int SCRIPT_TRIGGER_ON_CLICKED = 6;
// Area
int SCRIPT_AREA_ON_HEARTBEAT = 0;
int SCRIPT_AREA_ON_USER_DEFINED_EVENT = 1;
int SCRIPT_AREA_ON_ENTER = 2;
int SCRIPT_AREA_ON_EXIT = 3;
int SCRIPT_AREA_ON_CLIENT_ENTER = 4;
// Door
int SCRIPT_DOOR_ON_OPEN = 0;
int SCRIPT_DOOR_ON_CLOSE = 1;
int SCRIPT_DOOR_ON_DAMAGE = 2;
int SCRIPT_DOOR_ON_DEATH = 3;
int SCRIPT_DOOR_ON_DISARM = 4;
int SCRIPT_DOOR_ON_HEARTBEAT = 5;
int SCRIPT_DOOR_ON_LOCK = 6;
int SCRIPT_DOOR_ON_MELEE_ATTACKED = 7;
int SCRIPT_DOOR_ON_SPELLCASTAT = 8;
int SCRIPT_DOOR_ON_TRAPTRIGGERED = 9;
int SCRIPT_DOOR_ON_UNLOCK = 10;
int SCRIPT_DOOR_ON_USERDEFINED = 11;
int SCRIPT_DOOR_ON_CLICKED = 12;
int SCRIPT_DOOR_ON_DIALOGUE = 13;
int SCRIPT_DOOR_ON_FAIL_TO_OPEN = 14;
// Encounter
int SCRIPT_ENCOUNTER_ON_OBJECT_ENTER = 0;
int SCRIPT_ENCOUNTER_ON_OBJECT_EXIT = 1;
int SCRIPT_ENCOUNTER_ON_HEARTBEAT = 2;
int SCRIPT_ENCOUNTER_ON_ENCOUNTER_EXHAUSTED = 3;
int SCRIPT_ENCOUNTER_ON_USER_DEFINED_EVENT = 4;
// Module
int SCRIPT_MODULE_ON_HEARTBEAT = 0;
int SCRIPT_MODULE_ON_USER_DEFINED_EVENT = 1;
int SCRIPT_MODULE_ON_MODULE_LOAD = 2;
int SCRIPT_MODULE_ON_MODULE_START = 3;
int SCRIPT_MODULE_ON_CLIENT_ENTER = 4;
int SCRIPT_MODULE_ON_CLIENT_EXIT = 5;
int SCRIPT_MODULE_ON_ACTIVATE_ITEM = 6;
int SCRIPT_MODULE_ON_ACQUIRE_ITEM = 7;
int SCRIPT_MODULE_ON_LOSE_ITEM = 8;
int SCRIPT_MODULE_ON_PLAYER_DEATH = 9;
int SCRIPT_MODULE_ON_PLAYER_DYING = 10;
int SCRIPT_MODULE_ON_RESPAWN_BUTTON_PRESSED = 11;
int SCRIPT_MODULE_ON_PLAYER_REST = 12;
int SCRIPT_MODULE_ON_PLAYER_LEVEL_UP = 13;
int SCRIPT_MODULE_ON_PLAYER_CANCEL_CUTSCENE = 14;
int SCRIPT_MODULE_ON_EQUIP_ITEM = 15;
int SCRIPT_MODULE_ON_UNEQUIP_ITEM = 16;
// Placeable
int SCRIPT_PLACEABLE_ON_CLOSED = 0;
int SCRIPT_PLACEABLE_ON_DAMAGED = 1;
int SCRIPT_PLACEABLE_ON_DEATH = 2;
int SCRIPT_PLACEABLE_ON_DISARM = 3;
int SCRIPT_PLACEABLE_ON_HEARTBEAT = 4;
int SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED = 5;
int SCRIPT_PLACEABLE_ON_LOCK = 6;
int SCRIPT_PLACEABLE_ON_MELEEATTACKED = 7;
int SCRIPT_PLACEABLE_ON_OPEN = 8;
int SCRIPT_PLACEABLE_ON_SPELLCASTAT = 9;
int SCRIPT_PLACEABLE_ON_TRAPTRIGGERED = 10;
int SCRIPT_PLACEABLE_ON_UNLOCK = 11;
int SCRIPT_PLACEABLE_ON_USED = 12;
int SCRIPT_PLACEABLE_ON_USER_DEFINED_EVENT = 13;
int SCRIPT_PLACEABLE_ON_DIALOGUE = 14;
// AOE
int SCRIPT_AOE_ON_HEARTBEAT = 0;
int SCRIPT_AOE_ON_USER_DEFINED_EVENT = 1;
int SCRIPT_AOE_ON_OBJECT_ENTER = 2;
int SCRIPT_AOE_ON_OBJECT_EXIT = 3;
// Store
int SCRIPT_STORE_ON_OPEN = 0;
int SCRIPT_STORE_ON_CLOSE = 1;
Also see ginc_event_handlers
, the stock script library, it has some utility functions to work with event handlers.
P.S. Known bugs: the functions above don’t work for Module and Area objects.
Well… I love you?
Can you confirm if it works?
Last time I tried these functions, it did not work and I ended up adding a new line in nwn2_scriptsets.2da
and using SetCreatureScriptsToSet
to change the entire script set for a creature
I haven’t tried it yet.
If I use it, it will be something I will implement later in my project still under construction.
in my experience, they work, with caveats
there are other things to take into account like the fact that controlled characters always run a minimal scriptset: hb, death, ud only
And that if a character’s OnDialog slot is blank, the engine is hardcoded to run a default dialog-script; so if you really want a null dialog-handler, set the creature’s OnDialog eventscript to (literal)“blank” or a bodyless script.
and as Aqvilinus mentioned, Areas and Modules can’t change their scripts
And there are some events that just don’t work as advertised: I don’t remember exactly but it’s like doors’ OnUsed and OnClicked … (so fallback on OnOpen/OnClosed events, eg.)
basically, they work :)