Page 1 of 1

How to find out in which sector player is?

Posted: Sun May 22, 2022 4:04 am
by ramon.dexter
So, I have a inventory item, that has to be used in one specific sector, let's say tagged '667'. How do I do that in zscript? Specifically, the action would be called by Using the item, so action would be put into 'Use:' state. Again, my knowledge of this part of zscript is zero to none, so I'm asking if anyone knows how to do this task.

I can imagine something like:

Code: Select all

if (player.sectorTag == 667) { doStuff; } else { dontDoStuff; }

Re: How to find out in which sector player is?

Posted: Sun May 22, 2022 5:54 pm
by Blue Shadow
Something like this:

Code: Select all

class Blah : Inventory
{
    Default
    
{
        Inventory.Icon "SOULA0";

        +INVENTORY.INVBAR
    
}

    override bool Use (bool pickup)
    {
        if (Owner)
        {
            let it = Level.CreateSectorTagIterator(667);
            int index;

            while ((index = it.Next()) > -1)
            {
                if (Owner.CurSector && Owner.CurSector.Index() == index)
                {
                    // Heal if standing in the desired sector.
                    Owner.GiveBody(200, 200);
                    return true;
                }
            }
        }

        return false;
    }

    States
    
{
    Spawn:
        SOUL ABCD 6 Bright;
        Loop;
    }

When used, it iterates over all the sectors with tag 667, comparing their index with the one for the sector the owner (the player if the item is used by the player) is standing in. If there's a match, the item does its thing, and is used up.

Re: How to find out in which sector player is?

Posted: Mon May 23, 2022 11:58 am
by ramon.dexter
Many thanks BlueShadow, works as expected. :D