Force shield issue in Lua and question about player health

Status
Not open for further replies.
First thing: I am trying to set an ability when the player has the Force shield, but it only sets it after I get hit once.

Script:
Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.powers[pw_shield]==SH_FORCE
            player.charability = CA_TELEKINESIS
        elseif player.powers[pw_shield]!=SH_FORCE
            player.charability = skins[player.mo.skin].ability
        end
    end
end)
Wolfy suggested to specify the lower 8 bits of the shield or something, but I have no clue how to do that.

Second question: what's the difference between player.health and player.mo.health? Do I need to list both, or do they reference the same thing?
 
Last edited:
First thing: I am trying to set an ability when the player has the Force shield, but it only sets it after I get hit once.

Script:
Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.powers[pw_shield]==SH_FORCE
            player.charability = CA_TELEKINESIS
        elseif player.powers[pw_shield]!=SH_FORCE
            player.charability = skins[player.mo.skin].ability
        end
    end
end)
Wolfy suggested to specify the lower 8 bits of the shield or something, but I have no clue how to do that.
The lower 8 bits of the value set the hit points that the shield has left, so the value will only be exactly equal to SH_FORCE if there are 0 hit points left - which is why it's only working after you get hit once. What you want to do is check if the SH_FORCE has been set at all, so you use "if player.powers[pw_shield] & SH_FORCE". Also, you can leave out the check in the else block - if the player doesn't have the shield, you don't need to check again if he doesn't have it.

Second question: what's the difference between player.health and player.mo.health? Do I need to list both, or do they reference the same thing?
player.health is used for the ring counter on the HUD, so use player.mo.health.
 
Probably a good idea to modify both values, if you wanted to change the player's ring count. Otherwise, for checking the current ring count value, player.mo.health is probably best.
 
Status
Not open for further replies.

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

Back
Top