Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Dark Dreams of Furiae - a new module for NWN:EE! Buy now
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

A little help with a script

I've had troubles with two onhearbeat scripts, one that keeps damaging you when you enter an area or trigger and one that rewards you, as long as you are within the area/trigger.
The issue is when I leave the area or trigger, they keep firing. I am not quite sure how to stop it.
Be it either within the script itself or another onexit script that stops it, I would appreciate the help.
Here's an example of what I used: (I used it on onheartbeat event of the area/trigger)

#include "nw_i0_tool"
void main()

object oPC = GetEnteringObject();

if (!GetIsPC(oPC)) return;

if (GetItemPossessedBy(oPC, "Item01")!= OBJECT_INVALID)
RewardPartyXP(10, oPC, FALSE);



I usually download already made scripts for different purposes and learn from them, but the ones I found are far to complex to be used for such a simple event. Thanks in advance.


  • PhantasmaPhantasma Member Posts: 76
    edited August 2018
    You have nothing to stop the heartbeat running, so it's continuing to execute regardless of who is in it. Additionally, GetEnteringObject returns the *last* creature to enter, so will abort when another creature enters even if the PC is still in the trigger.

    You could fire off a custom heartbeat script from the OnEnter script, but to keep things simple change your heartbeat script to something like -

    object oCreature = GetFirstInPersistentObject();

    while(oCreature != OBJECT_INVALID)
    //do your stuff here
    oCreature = GetNextInPersistentObject();

    Note this will work for triggers - areas use GetFirst/NextInArea rather than the commands above, but that would be a fairly inefficient way to do things, especially in an area with lots of creatures. You could also control things better with variable setting/unsetting in OnEnter/Exit and checking for that variable in your heartbeat (e.g. set variable to 1 when PC enters, set to 0 when PC leaves, check that value in your heartbeat script). Shout if you need more info :-)

  • MelhoodMelhood Member Posts: 5
    It worked, much appreciated. Thank you for explaining the GetEnteringObject function also, never really considered the downfall of using that.

Sign In or Register to comment.