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!)

How to find out in which sector player is?

Postby ramon.dexter » Sun May 22, 2022 4:04 am

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 allExpand view
if (player.sectorTag == 667) { doStuff; } else { dontDoStuff; }
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

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

Postby Blue Shadow » Sun May 22, 2022 5:54 pm

Something like this:

Code: Select allExpand view
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
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

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

Postby ramon.dexter » Mon May 23, 2022 11:58 am

Many thanks BlueShadow, works as expected. :D
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests