Reset sector floor texture after it's changed by a linetrace

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
Night Falls
Posts: 47
Joined: Mon Mar 09, 2020 4:32 pm
Location: A hole in the bottom of the sea

Reset sector floor texture after it's changed by a linetrace

Post by Night Falls »

I'm working on a top-downish game that looks down at the map at a 45 degree angle. I've made some code that makes the floor of any sector the player is standing behind null so you can see through it.
This is executed by the camera, which fires a linetrace at the player constantly, and if it hits a sector instead of the player, it sets that sector's floor texture to null.

Code: Select all

FLineTraceData BehindSector;
        bool hit = LineTrace(90,9000,45,TRF_THRUBLOCK,0,0,0,data: BehindSector);
			
	if (hit && BehindSector.HitType == TRACE_HitFloor)
      {
			if(BehindSector.HitSector.GetTexture(sector.floor) != TexMan.CheckForTexture("null",TexMan.Type_Any))
			{
				textureid behindtexture;
				behindtexture = BehindSector.HitSector.GetTexture(sector.floor);
				BehindSector.HitSector.SetTexture(sector.floor,TexMan.CheckForTexture("null",TexMan.Type_Any));
			}
      }
The issue I have is getting the floor to revert to it's previous texture once the player is no longer behind it.

Also if there's a way to make the lines in the sector transparent when the player stands behind them that'd be cool, but first I need to figure out the above issue.
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Reset sector floor texture after it's changed by a linet

Post by Kzer-Za »

Hi! If this problem isn't solved yet, I suggest this:

Code: Select all

textureid behindtexture;
Sector LastAffectedSector;
FLineTraceData BehindSector;
bool hit = LineTrace(90,9000,45,TRF_THRUBLOCK,0,0,0,data: BehindSector);

if (hit && LastAffectedSector && behindtexture && BehindSector.HitType != TRACE_HitFloor)
{
	LastAffectedSector.SetTexture(sector.floor, TexMan.GetGameTexture(behindtexture);
	behindtexture = null;
	LastAffectedSector = null;
}

if (hit && BehindSector.HitType == TRACE_HitFloor)
{
	if(BehindSector.HitSector.GetTexture(sector.floor) != TexMan.CheckForTexture("null",TexMan.Type_Any))
	{
		LastAffectedSector.SetTexture(sector.floor, TexMan.GetGameTexture(behindtexture);
		
		LastAffectedSector = BehindSector.HitSector;
		behindtexture = BehindSector.HitSector.GetTexture(sector.floor);
		BehindSector.HitSector.SetTexture(sector.floor, TexMan.CheckForTexture("null",TexMan.Type_Any));
	}
}
User avatar
Night Falls
Posts: 47
Joined: Mon Mar 09, 2020 4:32 pm
Location: A hole in the bottom of the sea

Re: Reset sector floor texture after it's changed by a linet

Post by Night Falls »

Thanks for the code! I've been trying it out, though GZDoom doesn't recognize the function GetGameTexture. I looked inside gzdoom.pk3 and couldn't find it (including with development builds), and barely anything came up on Google.
I'm currently looking for some way to work around it, but haven't had much luck so far.
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Reset sector floor texture after it's changed by a linet

Post by Kzer-Za »

Oh, I was looking for a suitable function by grepping the code and it seems that GetGameTexture came in the results from cpp code, not from zscript. Then I don't know a function that sets a texture by textureid, only by name, and it requires more steps. Add

Code: Select all

string behindtexturename;
to the section with variables.

And after you get behindtexture, do also

Code: Select all

behindtexturename = TexMan.GetName(behindtexture);
And instead of

Code: Select all

LastAffectedSector.SetTexture(sector.floor, TexMan.GetGameTexture(behindtexture);
do

Code: Select all

LastAffectedSector.SetTexture(sector.floor, TexMan.CheckForTexture(behindtexturename, TexMan.Type_Any));
User avatar
Night Falls
Posts: 47
Joined: Mon Mar 09, 2020 4:32 pm
Location: A hole in the bottom of the sea

Re: Reset sector floor texture after it's changed by a linet

Post by Night Falls »

Update: I found a workaround by replacing TexMan.GetGameTexture(behindtexture); with TexMan.CheckForTexture(Texman.Getname(behindtexture),TexMan.Type_Any));

I also had to put textureid behindtexture; and Sector LastAffectedSector; outside of the tick() area, which threw me off for a while but I figured it out

Edit: I didn't reload this page so I didn't see your comment, sorry
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Reset sector floor texture after it's changed by a linet

Post by Kzer-Za »

No prob, glad it's working now.
Post Reply

Return to “Scripting”