Aller au contenu

Photo

Telling a script to stop doing something?


  • Veuillez vous connecter pour répondre
10 réponses à ce sujet

#1
Xeneize

Xeneize
  • Members
  • 133 messages

Hello. I am experiencing a problem with trigger scripts. What I'm trying to do is to make a series of things to happen when someone enters an area(trigger) but to stop doing the stuff when he exits it. How can I tell a script such a thing?

 

So far what's happening is that while the effects of exiting the area are happening, the effects that were writen to have place on the OnEnter event still carry on, something that I only want to happen if the person stays inside the trigger the whole time.

 

What can I do?



#2
kamal_

kamal_
  • Members
  • 5 254 messages

The OnExit script should check to see if the player is affected by whatever you're doing in the OnEnter, and stop it if the player is.



#3
Xeneize

Xeneize
  • Members
  • 133 messages

For some reason it doesn't. Is it because of the Delaycommand script perhaps? When the player enters the area, several things happen in a delayed manner. When I have them exit, it seems the commands behind the few Delaycommand scripts still effect them. They are gaining XP in the timely manner they would while being within the trigger.



#4
kevL

kevL
  • Members
  • 4 070 messages

If you have delayed commands in the trigger's onEnter script, they will continue to run as long as the trigger exists.

A possible way of dealing with this, is to create an invisible object (iPoint) via the onEnter, and wrap the delayed commands in a subfunction that is assigned to execute by the iPoint. Then, in the onExit script of trigger, destroy the ipoint

- as soon as PC leaves the trigger, iPoint goes poof and the delayed commands go poof with it,


other than that ... need to see the script itself.



#5
Xeneize

Xeneize
  • Members
  • 133 messages

For the OnEnter:

Spoiler

 

OnExit:

Spoiler

 

I need it so what's in On the first script stops when the PC exits the trigger(And what's on the second script happens)



#6
kevL

kevL
  • Members
  • 4 070 messages
onEnter:
#include "nwnx_sql"

//
void ExecuteThis(object oPC)
{
    int nProgressQuestTo = 861251;
    AddJournalQuestEntry("xenq_ud_yathrinquest", nProgressQuestTo, oPC, FALSE);
    SetPersistentInt(oPC, "xenq_ud_yathrinquest", nProgressQuestTo);

    object oPassport = GetItemPossessedBy(oPC,"pc_tracker");
    SetLocalInt(oPassport,"xenq_ud_yathrinquest", nProgressQuestTo);

    int nCurrentRank = GetPersistentInt(oPC, "RANK", "RP_Rank");
    SetPersistentInt(oPC, "RANK", (nCurrentRank + 1), 0, "RP_Rank");

    DelayCommand(10.0, SendMessageToPC(oPC, "You are in the Melee Magthere; rich with lore about the Drow race, Underdark and the Dark Seldarine. Take your time..."));

    DelayCommand(60.0, SendMessageToPC(oPC, "You learn some new interesting lore that you did not know of before"));
    DelayCommand(60.01, GiveXPToCreature(oPC, 200));

    DelayCommand(120.0, SendMessageToPC(oPC, "Your continuous study reveals new knowledge"));
    DelayCommand(120.01, GiveXPToCreature(oPC, 200));
    DelayCommand(180.02, SendMessageToPC(oPC, "Your dedicated study bears precious fruits of knowledge"));
    DelayCommand(180.03, GiveXPToCreature(oPC, 200));

    DelayCommand(300.0, SendMessageToPC(oPC, "You have learned and revised all you can, you best not let the Yathrin wait forever."));
    DelayCommand(300.01, AddJournalQuestEntry("xenq_ud_yathrinquest", 861252, oPC, FALSE));
    DelayCommand(300.02, SetPersistentInt(oPC, "xenq_ud_yathrinquest", 861252));
    DelayCommand(300.03, SetLocalInt(oPassport,"xenq_ud_yathrinquest", 861252));
    DelayCommand(300.04, SetPersistentInt(oPC, "RANK", (nCurrentRank + 1), 0, "RP_Rank"));
}


void main()
{
    object oPC = GetEnteringObject();
    if (!GetIsPC(oPC))
        return;

    location lLoc = GetLocation(OBJECT_SELF);
    object oExecutor = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_ipoint ", lLoc, FALSE, "executor_" + GetName(oPC));
    // should use something better than GetName ... eg, ObjectToString(oPC), perhaps ...
    // ( names can have funny characters that should need to be filtered )
    // there's a thread on the Bioware forums here about the persistency of ObjectToString() ..... somewhere.

    int nQuestEntry = 861250;
    if (GetJournalEntry("xenq_ud_yathrinquest", oPC) == nQuestEntry)
    {
        AssignCommand(oExecutor, ExecuteThis(oPC));
    }
}
onExit:
#include "nwnx_sql"

void main()
{
    object oPC = GetExitingObject();
//  if (!GetIsPC(oPC)) return;
    if (!GetIsOwnedByPlayer(oPC))
        return;

    object oExecutor = GetNearestObjectByTag("executor_" + GetName(oPC));
    if (GetIsObjectValid(oExecutor))
    {
        DestroyObject(oExecutor, 0.01);

        int nQuestEntry = 861251;
        if (GetJournalEntry("xenq_ud_yathrinquest", oPC) == nQuestEntry)
        {
            int nProgressQuestTo = 861252;
            AddJournalQuestEntry("xenq_ud_yathrinquest", nProgressQuestTo, oPC, FALSE);
            SetPersistentInt(oPC, "xenq_ud_yathrinquest", nProgressQuestTo);

            object oPassport = GetItemPossessedBy(oPC, "pc_tracker");
            SetLocalInt(oPassport,"xenq_ud_yathrinquest", nProgressQuestTo);

            int nCurrentRank = GetPersistentInt(oPC, "RANK", "RP_Rank");
            SetPersistentInt(oPC, "RANK", (nCurrentRank + 1), 0, "RP_Rank");
        }
    }
}

I don't have "nwnx_sql" so can't compile this, but the idea is there. ( with a few extra things that may or may not be relevant )

#7
Xeneize

Xeneize
  • Members
  • 133 messages

Tried this out, and didn't work. It still didn't work out :(



#8
Dann-J

Dann-J
  • Members
  • 3 161 messages

This would be better achieved using the trigger's heartbeat script. Each round you could check whether a party member is within the trigger, and if so the script can increment an integer variable on the trigger itself. A switch/case list could award XP and send a message at specific intervals (10, 20, 30 and 50 rounds). If all party members leave the trigger, the variable would stop updating.



#9
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages

Instead of a heartbeat script, you could wrap all of your delay commands in a function that checks whether the PC is still within the trigger (use the on-exit to toggle a variable on the trigger to keep track). 

 

void StudyPC() {

    if (GetLocalInt(OBJECT_SELF, "iPCinTrigger")) {

          //Give XP, Give Quest, Send Message

         }

    }

 

....

 

    DelayCommand(180.0, StudyPC());



#10
Loki_999

Loki_999
  • Members
  • 430 messages

Interesting, i didn't know destroying the object that created a delay command would cause the delay command to not run.  I think i might be able to find a use for that little nugget.



#11
kevL

kevL
  • Members
  • 4 070 messages

... the object that *runs* a Delayed command

 

i haven't tested it, but the theory sounds good; no OBJECT_SELF, no execution.