Not exactly sure if this should go here or mapping, since it's combined.
I am trying to create an object, that upon activation, changes the height of a sector and turns the sector's floor texture to something different, while also changing data of other objects. While i was able to get nearly everything done, I have no clue how to change the floor texture. Another problem is, i need to provide the texture as a property inside that object (probably a string variable, so i would probably need to use texture manager for that).
[ZS] Changing sector texture with ZScript
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!)
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: 1386
- Joined: Wed May 13, 2009 3:15 am
- Discord: Player701#8214
- OS Test Version: No (Using Stable Public Version)
- Graphics Processor: nVidia with Vulkan support
- Location: Russia
Re: [ZS] Changing sector texture with ZScript
It is possible to do a LineTrace straight down from the actor's position. If a 3D floor was hit, change the ceiling texture of that 3D floor's control sector; otherwise, change the floor of the sector that was hit.
Example code below. NB: 3D floor scenario not tested, please tell me if it doesn't work.
Example code below. NB: 3D floor scenario not tested, please tell me if it doesn't work.
Code: Select all
private void ChangeFloorTexture(string name, int maxdist = 1024)
{
let tex = TexMan.CheckForTexture(name);
if (!tex.IsValid())
{
return;
}
FLineTraceData t;
if (LineTrace(0, maxdist, 90, TRF_THRUACTORS, data: t) && t.HitType == TRACE_HitFloor)
{
if (t.Hit3DFloor != null)
{
t.Hit3DFloor.model.SetTexture(Sector.ceiling, tex);
}
else if (t.HitSector != null)
{
t.HitSector.SetTexture(Sector.floor, tex);
}
}
}
-
- Posts: 220
- Joined: Thu Aug 10, 2017 9:38 am
Re: [ZS] Changing sector texture with ZScript
Thanks for the example -I actually managed to resolve this myself using "SectorTagIterator". Since the project I am working on does not utilize any custom content, I can edit anything (You wouldn't want to change textures with weapons in custom map packs anyway though).
The line trace method would still be not very workable in my case, as the object is not neccesarrily in the same sector as the effect taking place.
Nevertheless, the way I resolved it:
It might not work with 3D Floors, but in the case of the project I am working on, it is not a problem - since no 3D floors will be ever present.
EDIT: Note that this method of creation is deprected starting 3.8 and "Level.CreateSectorTagIterator()" should be used in its place
The line trace method would still be not very workable in my case, as the object is not neccesarrily in the same sector as the effect taking place.
Nevertheless, the way I resolved it:
Code: Select all
SectorTagIterator SectorSearch = SectorTagIterator.Create(SectorTag);
int Vari;
while ((Vari = SectorSearch.Next)>0) // An empty "value" is -1, so we need to check for that
{
level.sectors[Vari].SetTexture(sector.floor, TexMan.CheckForTexture(TextureNameString, TexMan.Type_Any)
}
EDIT: Note that this method of creation is deprected starting 3.8 and "Level.CreateSectorTagIterator()" should be used in its place
-
-
- Posts: 1386
- Joined: Wed May 13, 2009 3:15 am
- Discord: Player701#8214
- OS Test Version: No (Using Stable Public Version)
- Graphics Processor: nVidia with Vulkan support
- Location: Russia
Re: [ZS] Changing sector texture with ZScript
Sorry, from your original post I thought you were referring to the sector where your object is located.
Handling 3D floors requires an understanding of what your exact intentions are, e.g. whether you want to affect all 3D floors or a specific 3D floor (in this case you have to determine the algorithm to choose this 3D floor). But since you say there won't be any 3D floors in any case, this is a moot point.Virathas wrote:It might not work with 3D Floors, but in the case of the project I am working on, it is not a problem - since no 3D floors will be ever present.
-
- Posts: 392
- Joined: Wed Dec 22, 2021 7:02 pm
- OS Test Version: No (Using Stable Public Version)
- Graphics Processor: Intel (Modern GZDoom)
- Location: Medellin, Colombia
Re: [ZS] Changing sector texture with ZScript
Found this thread while trying to do the same thing. Here's my working code (tested in 4.7.1):
Code: Select all
static void ChangeFloorTexture(int tag, string TextureName)
{
TextureId newTexture=TexMan.CheckForTexture(TextureName, TexMan.Type_Any);
SectorTagIterator sti = level.CreateSectorTagIterator(tag);
int i;
while ((i = sti.Next())>=0)
{
level.sectors[i].SetTexture(sector.floor, newTexture);
}
}