Change floor texture with lua

metalharbor

Member
I want to use lua to change a floor texture after checking the player's ring count. I'm guessing it's something like this.


Lua:
addHook("ThinkFrame", do

 for player in players.iterate
    if player.rings >= 10
        sector.floorpic = GFZFLR02
    end
 end
end)


However I don't know how to identify the sector to change the height. I assume that I need to use sector.tag somehow but I don't quite know how. I'm not sure if I'm using sector.floorpic right either.
 
You get the player's current sector with player.mo.subsector.sector. Change that variable's floorpic.

Of course, it gets a little more complex when the player's standing on an FOF. In that case, you'll need to iterate over that sector's ffloors, like for ffloor in sector.ffloors() do, and find the first FOF that's below your player in terms of ceiling height, then change its ceiling pic.
 
Thanks for your help. Unfortunately that doesn't really get me any farther.

I actually mean to change floor flats for sectors with a specific tag (eg. tag 100), not the sector the player is actually in. Is there a way to do that?

(I think I know how to limit it to my own maps using level headers to stop it from affecting the main game.)
 
Then just

Lua:
for sector in sectors.iterate do
    if (sector.tag == tag_you_want) then
        sector.floorpic = newfloorpic
    end
end

Of course, you probably shouldn't run this every tic, that would be resource intensive. You might want to run it whenever a player's ring count changes, either with a boolean check for enabled/disabled during ThinkFrame or MobjDamage on MT_PLAYER.

You can also run it once at the start, save all the matching sectors in a new table, and iterate over that table instead, to save even more resources.

Apparently you can also do sectors.tagged(tag_you_want) to skip the tag check entirely? Though I've never tried it myself.
 
I now have:

Lua:
addHook("ThinkFrame", do

    for sector in sectors.iterate do
        if (sector.tag == 1) then
            sector.floorpic = GFZFLR02
        end
    end
end)


Not worrying about checking rings yet...but it doesn't seem to do anything. Not sure if this is the way I've structured it or an outright error on my part.

I also tried with sectors.tagged( ) without results.
 
"GFZFLR02". Put it in quotation marks, otherwise Lua will think it's a variable and throw an error since you never defined it (or do nothing, dunno what happens when you assign nil to a floorpic.)

Posting your latest log.txt file may be helpful if you ever see any errors show up. You probably didn't get any for this, just saying in advance.
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top