Skip to content

Reset Encounters when area is empty?

I'm not sure how the stack is ordered when a player enters or exits an area. When a player enters an area, will an on enter script count them as a player?

Each encounter in this area is a one shot. So once the area is empty, I would like to reset (or set all encounters in the area) back to Active.

How can I go about this?

Comments

  • ForSeriousForSerious Member Posts: 446
    edited September 2021
    I believe you have to check if the object is a PC.

    Here's one way you can do it:
    void main()
    {
        // Check if the area is empty of players.
        object oPC = GetFirstPC();
        while(GetIsObjectValid(oPC))
        {
            if(GetArea(oPC) == OBJECT_SELF)
            {
                // Found a player in the exited area. Stop the script.
                return;
            }
            oPC = GetNextPC();
        }
        // No players found. Reset all the encounters.
        object oObject = GetFirstObjectInArea();
        while(GetIsObjectValid(oObject))
        {
            // Only pay attention to encounter objects.
            if(GetObjectType(oObject) == OBJECT_TYPE_ENCOUNTER)
            {
                // Here's where the magic happens.
                SetEncounterActive(TRUE, oObject);
            }
            oObject = GetNextObjectInArea();
        }
    }
    

    I don't love that two while loops have to be used. If your areas usually have more objects than players on the server, this way should be slightly less performance impactful. Otherwise you could just loop through all the objects in the area twice.

    I tested this with one encounter and one player, but it should work with more of both.

    There's a warning in the lexicon that OnExit does not fire when a player leaves the game.
  • BuddywarriorBuddywarrior Member Posts: 62
    awesome. To confirm, the process order would go

    Player begins to enter area ---> player is in area --->script runs.
    Player begins to leave area --->player is not in area ---> script runs.

    I plan on having the script door/entrance and the OnEnter of the area will move the PC to a waypoint at the 'start' of the dungeon. This way if somebody tries to be sneaky and logs off they will be moved.


  • ForSeriousForSerious Member Posts: 446
    That process order is correct.
Sign In or Register to comment.