Spawning a monster depending on sector height?

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!)
Posts: 95
Joined: Wed May 26, 2010 11:10 am

Spawning a monster depending on sector height?

Post by bowserknight »

So I have a script in my map that, after entering a room, prints a message and at the same time, spawns a monster via SpawnSpot. But I want the monster to only appear when a certain sector has reached a specific height or higher.

Like, let's say sector 50 has a height of 8 and there are mechanisms in the map that raise this sector. If you enter this one room and the height of sector 50 hasn't been changed, only the text message will appear. If the sector has reached a height of at least 32, the script will also spawn a monster. How do I do that? I know you have to do it with the "if()" expression somehow but I don't know exactly what you have to type in. Is it even possible to do stuff like this? Or alternatively, is it possible to do the same depending on the position of the player? Like, the monster only spawns if you're in a specific sector. What exactly do you have to type, the tag of the sector or just its number?
User avatar
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: Spawning a monster depending on sector height?

Post by gwHero »

Do you use ACS or ZScript?

I'll give you an example of the first case you mention, which is not too difficult.
Assuming you use ACS for scripting, you can retrieve the height of the sector in this way:

Code: Select all

int floorz = GetSectorFloorZ(1, getactorX(2),getactorY(2)) >> 16;
int ceilz = GetSectorCeilingZ(1, getactorX(2),getactorY(2)) >> 16;
int height = ceilz - floorz;
if (height >= 32)
    //.. do something
   // .. do something else
GetSectorFloorZ as well as GetSectorCeilingZ need X and Y coordinates; in this example, the sector has tag 1, and tag 2 is the tid of a mapspot. Now you do not necessarily need a mapspot; instead you could specify the x,y coordinates hard coded, but using a mapspot is better, because if you would move the sectors around in the editor, your code would still work.

[Edit]: acs functions mostly need tags, never sector numbers.

Return to “Scripting”