Lua script help - Change flags depending on rings

Status
Not open for further replies.

Goldenhog

Wandering Protagonist
Code:
// A_S1GRCheck
//
// Checks the current number of rings the player has.
// If below 50, it becomes invisible and intangible.
// If above or equal to 50, it can be seen and interacted with.

function A_S1GRCheck(actor, var1, var2)
    for player in players.iterate
        if player.health < 50
            actor.flags = ($1|MF_NOCLIPTHING)
            actor.flags2 = ($1|MF2_DONTDRAW)
        elseif player.health >= 50
            actor.flags = ~(MF_NOCLIPTHING)
            actor.flags2 = ~(MF2_DONTDRAW)
        end
    end
end
Well, the top part explains pretty well what I want to do. But for some reason, it's visible until the player has 50 or more rings, then it disappears! And even if you bring yourself down to less to 50 rings, it doesn't come back.
 
Code:
// A_S1GRCheck
//
// Checks the current number of rings the player has.
// If below 50, it becomes invisible and intangible.
// If above or equal to 50, it can be seen and interacted with.

function A_S1GRCheck(actor, var1, var2)
    for player in players.iterate
        if player.health < 50
            actor.flags = $1 & ~MF_NOCLIPTHING
            actor.flags2 = $1 & ~MF2_DONTDRAW
        elseif player.health >= 50
            actor.flags = $1 | MF_NOCLIPTHING
            actor.flags2 = $1 | MF2_DONTDRAW
        end
    end
end

That should work. "$1 & ~FLAGNAME" removes a flag, "$1 | FLAGNAME" adds it.
 
Sorry for the delay! Your script worked backwards for some reason, but switching the < for a >= and viceversa fixed it. Thanks!
 
Status
Not open for further replies.

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

Back
Top