[ZS] Changing sector texture with ZScript

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

[ZS] Changing sector texture with ZScript

Postby Virathas » Tue Jan 11, 2022 1:36 am

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).
User avatar
Virathas
 
Joined: 10 Aug 2017

Re: [ZS] Changing sector texture with ZScript

Postby Player701 » Tue Jan 11, 2022 7:05 am

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.

Code: Select allExpand view
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);
        }
    }
}
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
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: [ZS] Changing sector texture with ZScript

Postby Virathas » Tue Jan 11, 2022 9:04 am

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:

Code: Select allExpand view
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)
}


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
User avatar
Virathas
 
Joined: 10 Aug 2017

Re: [ZS] Changing sector texture with ZScript

Postby Player701 » Tue Jan 11, 2022 9:08 am

Sorry, from your original post I thought you were referring to the sector where your object is located.

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.

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.
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
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 1 guest