We are going to need some parallels between some events. For example, a spawning NPC should throw the same even as a PC entering a server for the first time. I think this will just be an issue of nomenclature, though. We also need to know if it will be possible to catch NPC events on PCs in NWN2, and if it will be any easier than using the default.nss hack.
I don't know that the default BW events will be used. The custom ones start at 100.
Code: Select all
////////////////////////////////////////////////////////////////////////////////
//
// System Name : ALFA Core Scripts
// Filename : _event_i.nss
// Version : 0.1
// Date : 3/31/06
// Author : Ronan
//
// Local Variable Prefix = COR_EVN_
//
// Description
// For information on how to use the events system, please see:
// cor_event_exmple.nss.
// This file contains the ALFA Events system, which is called directly by
// core ALFA scripts. In a nutshell, this system allows us to define our own
// event hooks, and defines a system by which scripts can be easily added
// to run on these events. Events can be attached to any "caller", items,
// feats, areas, creatures, etc.
// Revision History
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Includes ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constants ///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// NWN Events:
// Module Events:
const int NW_MOD_EVENT_ON_CLIENT_ENTER = 1; // Players ONLY.
const int NW_MOD_EVENT_ON_CLIENT_LEAVE = 2; // Players ONLY.
const int NW_MOD_EVENT_ON_EQUIP = 3; // Players ONLY.
const int NW_MOD_EVENT_ON_UNEQUIP = 4; // Players ONLY.
const int NW_MOD_EVENT_CUT_SCENE_ABORT = 5; // Players ONLY.
const int NW_MOD_EVENT_ON_AQUIRE_ITEM = 6; // Players ONLY.
const int NW_MOD_EVENT_ON_UNAQUIRE_ITEM = 7; // Players ONLY.
const int NW_MOD_EVENT_ON_ACTIVATE_ITEM = 8;
const int NW_MOD_EVENT_ON_PLAYER_DEATH = 9; // Players ONLY.
const int NW_MOD_EVENT_ON_PLAYER_DYING = 10; // Players ONLY.
const int NW_MOD_EVENT_ON_HEART_BEAT = 11; // Unused.
const int NW_MOD_EVENT_ON_LEVEL_UP = 12; // Players ONLY.
const int NW_MOD_EVENT_ON_MODULE_LOAD = 13; // Unused.
const int NW_MOD_EVENT_ON_RESPAWN = 14; // Players ONLY.
const int NW_MOD_EVENT_ON_REST = 15; // Players ONLY.
// Area Events:
const int NW_AREA_EVENT_ON_AREA_ENTER = 16;
const int NW_AREA_EVENT_ON_AREA_EXIT = 17;
const int NW_AREA_EVENT_ON_HEART_BEAT = 18;
// Creature Events: These ONLY act on NPC creatures and objects, never PCs.
const int NW_CREATURE_EVENT_ON_PERCEPTION = 19;
const int NW_CREATURE_EVENT_ON_SPELL_CAST_AT = 20; // Covered by ALFA_EVENT_SPELL_CAST_AT.
const int NW_CREATURE_EVENT_ON_PHYSICAL_ATTACKED = 21; // Covered by ALFA_EVENT_PHYSICAL_ATTACKED.
const int NW_CREATURE_EVENT_ON_DAMAGED = 22; // Covered by ALFA_EVENT_DAMAGED.
const int NW_CREATURE_EVENT_ON_DISTURBED = 23; // Covered by ALFA_EVENT_(UN)AQUIRE_ITEM.
const int NW_CREATURE_EVENT_ON_COMBAT_ROUND_END = 24;
const int NW_CREATURE_EVENT_ON_CONVERSATION = 25; // Covered by ALFA_EVENT_ON_CONVERSATION.
const int NW_CREATURE_EVENT_ON_RESTED = 26; // Covered by ALFA_EVENT_ON_RESTED.
const int NW_CREATURE_EVENT_ON_DEATH = 27; // Covered by ALFA_EVENT_ON_DEATH.
const int NW_CREATURE_EVENT_ON_BLOCKED = 28;
const int NW_CREATURE_EVENT_ON_HEART_BEAT = 29; // Covered by ALFA_EVENT_ON_HEART_BEAT.
//const int NW_CREATURE_EVENT_ON_DAMAGED = 31;
//const int NW_CREATURE_EVENT_ON_DEATH = 32;
//const int NW_CREATURE_EVENT_ON_HEART_BEAT = 33;
// Placable Events:
const int NW_PLACE_EVENT_ON_DISTURBED = 34;
const int NW_PLACE_EVENT_ON_LOCK = 35;
const int NW_PLACE_EVENT_ON_PHYSICAL_ATTACKED = 36;
const int NW_PLACE_EVENT_ON_OPEN = 37;
const int NW_PLACE_EVENT_ON_SPELL_CAST_AT = 38;
const int NW_PLACE_EVENT_ON_UNLOCK = 39;
const int NW_PLACE_EVENT_ON_USED = 40;
// Trigger Events:
const int NW_TRIGGER_EVENT_ON_CLICK = 41;
const int NW_TRIGGER_EVENT_ON_ENTER = 42;
const int NW_TRIGGER_EVENT_ON_EXIT = 43;
const int NW_TRIGGER_EVENT_ON_HEART_BEAT = 44;
// Door Events:
const int NW_DOOR_EVENT_ON_OPEN = 45;
const int NW_DOOR_EVENT_ON_CLOSE = 46;
const int NW_DOOR_EVENT_ON_FAIL_TO_OPEN = 47;
const int NW_DOOR_EVENT_ON_LOCK = 48;
const int NW_DOOR_EVENT_ON_UNLOCK = 49;
const int NW_DOOR_EVENT_ON_PHYSICAL_ATTACKED = 50;
const int NW_DOOR_EVENT_ON_DAMAGED = 51;
const int NW_DOOR_EVENT_SPELL_CAST_AT = 52;
const int NW_DOOR_EVENT_ON_HEART_BEAT = 53;
// ALFA Events:
// Caller: Module.
// Called when: A PC enters the server, but has entered before since last reset.
const int CUST_EVENT_CLIENT_ENTER = 100;
// Caller: Module.
// Called when: A PC leaves.
const int CUST_EVENT_CLIENT_LEAVE = 101;
// Caller: A creature.
// Called when: A PC equips an item, or an NPC's AI script equips an item.
const int CUST_EVENT_ON_EQUIP = 102;
// Caller: A creature.
// Called when: A PC unequips an item, or an NPC's AI script unequips an item.
const int CUST_EVENT_ON_UNEQUIP = 103;
// Caller: Module.
// Called when: A player aborts cut-scene.
const int CUST_EVENT_CUT_SCENE_ABORT = 104;
// Caller: Object which gained the item.
// Called when: A PC or object gains an item, or a non-DM-posessed NPC gains an item.
const int CUST_EVENT_AQUIRE_ITEM = 105;
// Caller: Object which lost the item.
// Called when: A PC or object looses an item, or a non-DM-posessed NPC looses an item.
const int CUST_EVENT_UNAQUIRE_ITEM = 106;
// Caller: Item activator.
// Called when: A PC or NPC activates an item or placable.
const int CUST_EVENT_ACTIVATE_ITEM = 107;
// Caller: Dead object.
// Called when: Anything is killed or destroyed.
const int CUST_EVENT_DEATH = 108;
// Caller: Dying creature.
// Called when: Anything is given enough lethal damage to be dying, but not yet dead.
const int CUST_EVENT_DYING = 109;
// Caller: Leveling-up creature.
// Called when: A PC levels-up
const int CUST_EVENT_LEVEL_UP = 110;
// Caller: The module.
// Called when: The module loads.
const int CUST_EVENT_MODULE_LOAD = 111;
// Caller: The module.
// Called when: The player hits the "respawn" button after death.
const int CUST_EVENT_RESPAWN = 112;
// Caller: The resting creature.
// Called when: Anything is done resting.
const int CUST_EVENT_REST = 113;
// Caller: The area or trigger entered.
// Called when: Something enters a trigger or area.
const int CUST_EVENT_ENTER = 114;
// Caller: The area or trigger exited.
// Called when: Something exits a trigger or area.
const int CUST_EVENT_EXIT = 115;
// Caller: The creature who could perceive something.
// Called when: A creature has a chance to see or hear something.
const int CUST_EVENT_PERCEPTION = 116;
// Caller: Target of the spell.
// Called when: Any object is direct targeted by a spell.
const int CUST_EVENT_SPELL_CAST_AT = 117;
// Caller: The attacked object.
// Called when: Any non-PC object is attacked physically.
const int CUST_EVENT_PHYSICAL_ATTACKED = 118;
// Caller: The damaged object.
// Called when: Any object is damaged.
const int CUST_EVENT_DAMAGED = 119;
// Caller: The NPC who hears speach.
// Called when: An NPC hears speach, or is clicked on to talk to.
const int CUST_EVENT_CONVERSES = 120;
// Caller: The creature.
// Called when: A creature's pathfinding is blocked by a door.
const int CUST_EVENT_BLOCKED = 121;
// Caller: The locked object.
// Called when: Something is locked in any way other than the DM using force-lock.
const int CUST_EVENT_LOCK = 122;
// Caller: The opened object.
// Called when: Something is opened.
const int CUST_EVENT_OPEN = 123;
// Caller: The unlocked object.
// Called when: Something is unlocked in any way other than the DM using force-unlock.
const int CUST_EVENT_UNLOCK = 124;
// Caller: The using creature.
// Called when: Any item or placable is used.
const int CUST_EVENT_USED = 125;
// Caller: The clicked trigger.
// Called when: A trigger is clicked on.
const int CUST_EVENT_CLICK = 126;
// Caller: The creature who failed to open.
// Called when: Any creature fails to open a door.
const int CUST_EVENT_FAIL_TO_OPEN = 127;
// Caller: The object with the heartbeat script.
// Called when: That script is fired.
const int CUST_EVENT_HEART_BEAT = 128;
// Caller: The equiped item.
// Called when: An item is equiped by a PC or a creature's AI script.
const int CUST_EVENT_EQUIPS = 129;
// Caller: The unequiped item.
// Called when: An item is unequiped by a PC or a creature's AI script.
const int CUST_EVENT_UNUEQUIPS = 130;
// Caller: The spell caster.
// Called when: When a spell, spell-like ability, or anything using a spell-script is called.
const int CUST_EVENT_SPELL_CAST_BY = 131;
// Caller: The damager.
// Called when: When an object damages a non-PC object.
const int CUST_EVENT_DAMAGES = 132;
// Caller: The killer.
// Called when: When an object kills or destroys another object/creature/player/etc.
const int CUST_EVENT_KILLS = 133;
// Caller: The object that knocked-out the creature.
// Called when: An object knocks something out with non-lethal damage.
const int CUST_EVENT_KNOCKS_OUT = 134;
// Caller: The object that left the creature dying.
// Called when: An object damages a creature and leaves it bleeding.
const int CUST_EVENT_LEAVES_DYING = 135; // Called when an object leaves a creature/player bleeding (with lethal damage).
// Caller: The object that attacked.
// Called when: A non-PC object is physically attacked.
const int CUST_EVENT_PHYSICAL_ATTACKS = 136; // Called when an object physically attacks another non-PC object.
// Caller: The module.
// Called when: A PC enters the server, this event is called on each object in
// their inventory.
const int CUST_EVENT_ENTERED_WITH = 137;
// Caller: The module.
// Called when: A PC enters, this event is called on each equiped item.
const int CUST_EVENT_ENTERED_WITH_EQUIPED = 138;
// Caller: The module.
// Called when: A PC enters a module for the first time since the server's last
// reset. This event is called on each object in their inventory.
const int CUST_EVENT_FIRST_ENTERED_WITH = 139;
// Caller: The module.
// Called when: A PC enters a module for the first time since the server's last
// reset. This event is called on each of their equiped items.
const int CUST_EVENT_FIRST_ENTERED_WITH_EQUIPED = 140;
// Caller: The spell caster.
// Called when: A spell effects an object in any way.
const int CUST_EVENT_SPELL_EFFECTS = 141;
// Caller: Module.
// Called when: A PC enters the server, but has NOT entered before since last
// reset.
const int CUST_EVENT_CLIENT_FIRST_ENTER = 142;
// The prefix for the array of event scripts on an object.
// DO NOT CHANGE THESE without first considering the changes required to every
// item using these scripts.
const string LSA_CUST_EVENT_LIST = "CES_";
const string LI_CUST_EVENT_LIST_LENGTH = "CESL";
// The prefix for the array of links to another object.
const string LOA_CUST_EVENT_LINKS = "CEL_";
const string LI_CUST_EVENT_LINKS_LENGTH = "CELL";
// The local variable name of the event type, passed to each event script when
// an event is triggered.
const string LI_CUST_EVENT_TYPE = "CET_";
////////////////////////////////////////////////////////////////////////////////
// Structures //////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Global Variables ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The debug id for this system.
int debugId;
////////////////////////////////////////////////////////////////////////////////
// Function Prototypes /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// This function signals a custom event. After calling this function, the events
// system will run any and all event scripts stored on the caller object with
// the same type as event_type.
// caller: The owner of the event script.
// event_type: The integer value coresponding to the type of event fired. See
// The cor_event_inc.nss script.
void SignalCustomEvent(object caller, int event_type);
// This function links a custom event fron one object to another. It is used
// when an object must apply an event to another object for whatever reason.
// Only event scripts of event_type will be linked. All linked scripts of that
// type are executed when an event of that type is signaled on the target.
// oCaller: The owner of the event script.
// oTarget: The target which will receive the event script.
// eventType: The type of event script(s) to be added.
//
// For example, a ring of spell-reflection has an CUST_EVENT_SPELL_CAST_AT
// script, which would oridinarily only function if a spell was cast on the ring
// itself. However, the ring's CUST_EVENT_ENTERED_WITH_EQUIPED and
// CUST_EVENT_EQUIPS scripts call,
// AddCustomEvent(oRing, oRingOwner, CUST_EVENT_SPELL_CAST_AT);
// This adds the ring's spell reflection script to the owner, making the ring's
// wearer reflect spells.
void LinkCustomEvent(object oCaller, object oTarget, int eventType);
// The opposite of LinkCustomEvent, this function removes any links between the
// events of caller on target of type eventType.
void UnlinkCustomEvent(object oCaller, object oTarget, int eventType);
// Called once to initialize the custom events system.
void CorEventsOnModuleLoad();
// Runs all event on that object, and that object only.
// Not for external use, as it does not pass parameters.
// See SignalCustomEvent().
void RunEventsOnObject(object caller, int eventType);
// Calls the event eventType on all items equiped by creature oTarget,
// even creature items.
void SignalCustomEventOnEquiped(object oTarget, int eventType);