How to find out in which sector player is?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

How to find out in which sector player is?

Post 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; }
Blue Shadow
Posts: 5043
Joined: Sun Nov 14, 2010 12:59 am

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

Post 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.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

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

Post by ramon.dexter »

Many thanks BlueShadow, works as expected. :D
Post Reply

Return to “Scripting”