Page 1 of 1

[ZS] Changing sector texture with ZScript

PostPosted: Tue Jan 11, 2022 1:36 am
by Virathas
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).

Re: [ZS] Changing sector texture with ZScript

PostPosted: Tue Jan 11, 2022 7:05 am
by Player701
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);
        }
    }
}

Re: [ZS] Changing sector texture with ZScript

PostPosted: Tue Jan 11, 2022 9:04 am
by Virathas
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

Re: [ZS] Changing sector texture with ZScript

PostPosted: Tue Jan 11, 2022 9:08 am
by Player701
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.