PDA

View Full Version : How to make a trigger fire once?


R2-X2
07-29-2009, 04:01 PM
How can I make a trigger to fire just once, twice (...) ?

newbiemodder
07-29-2009, 04:26 PM
I've used these script conditionals before:
// ST: Check if it's the player entering the trigger, and that it hasn't already fired
if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC())) {

and:

// ST: Make sure the trigger only fires once.
SetLocalBoolean(OBJECT_SELF, 40, TRUE);


Don't know if that helps at all.

R2-X2
07-29-2009, 06:17 PM
I think there's a mistake in your script. You've got a {, but no }, so there will be Syntax errors.

newbiemodder
07-29-2009, 07:52 PM
I'm sorry, it was part of a larger script. Here is the full script I use to fire a dialog only once when a trigger is entered:

void main() {
// ST: Check if it's the player entering the trigger, and that it hasn't already fired
if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC())) {
// ST: Get the two NPCs who should converse, set their tags below.
object oNPC1 = GetObjectByTag("xyz");
object oNPC2 = GetObjectByTag("abc");
// ST: Check if both NPCs who should converse are present in the area
if (GetIsObjectValid(oNPC1) && GetIsObjectValid(oNPC2)) {
// ST: Make sure the trigger only fires once.
SetLocalBoolean(OBJECT_SELF, 40, TRUE);
// ST: Start the dialog.
AssignCommand(oNPC1, ActionStartConversation(GetFirstPC(), "dialog name", FALSE, CONVERSATION_TYPE_CINEMATIC, TRUE));
}
}
}

R2-X2
07-30-2009, 03:56 PM
Sorry, but can you do a script that only checks, and doesn't do anything else? I need it for other things, which I'm going to insert in the script.

Star Admiral
07-30-2009, 09:55 PM
Try this.

void main() {
if( !GetLocalBoolean( OBJECT_SELF, 40 ) && GetEnteringObject() == GetFirstPC() ) {
// Stuff
SetLocalBoolean( OBJECT_SELF, 40, TRUE );
}
else {
// Stuff
}
}

- Star Admiral

R2-X2
07-31-2009, 10:27 AM
That's what I was looking for. Thanks for your help you two.

Edit: Is there a way to modify the script so it can be triggered by friendly2 and hostile2 (only f. and h. 2, not hostile1/friendly1) NPCs?