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!)
Post Reply
User avatar
CBM
Posts: 373
Joined: Wed Oct 09, 2019 3:39 am
Graphics Processor: nVidia with Vulkan support
Location: The Shores of Hell

sector height

Post by CBM »

is it possible to use a zscript to control the height of a sector on the fly?
User avatar
Caligari87
Admin
Posts: 6234
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: sector height

Post by Caligari87 »

Yes, though figuring out how requires some code-diving because ZScript isn't really ideal for map scripting. Here are the methods available to sector planes in gzdoom.pk3/zscript/mapdata.zs at line 199, including ChangeHeight().

Code: Select all

struct SecPlane native play
{
	native Vector3 Normal;
	native double D;
	native double negiC;
	
	native bool isSlope() const;
	native int PointOnSide(Vector3 pos) const;
	native clearscope double ZatPoint (Vector2 v) const;
	native double ZatPointDist(Vector2 v, double dist) const;
	native bool isEqual(Secplane other) const;
	native void ChangeHeight(double hdiff);
	native double GetChangedHeight(double hdiff) const;
	native double HeightDiff(double oldd, double newd = 1e37) const;
	native double PointToDist(Vector2 xy, double z) const;
}
In that same file at line 340 you can see that a Sector struct has two SecPlane members:

Code: Select all

	native readonly @secplane floorplane;
	native readonly @secplane ceilingplane;
So in zscript, you can do something like:

Code: Select all

level.sectors[sectornumber].floorplane.ChangeHeight(hdiff);
I believe hdiff is a relative amount to the plane normal (may be either positive or negative depending on floor or ceiling?), so you'll need to do some math and experimentation.

8-)
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: sector height

Post by Sir Robin »

Hi, I know this is an old thread but found it because I'm trying to do the same thing - change the floor height in zscript.

I tried Caligari87's way but I get told that the object on the left side of ChangeHeight is read-only (this is on 4.7.1 so maybe it was not on earlier versions?)

Anyway, I got mine working by calling special 37:

Code: Select all

	static void ChangeFloorHeight(int tag, int height)
	{
		Level.ExecuteSpecial(37, null, null, false, tag, int.max, abs(height), height < 0 ? 1 : 0);
	}
Post Reply

Return to “Scripting”