How to make a character float

Rodriv64

Member
Hello, i'm trying to make a lua script that makes sonic float and move in any direction whenever using the Whirlwind shield, but i don't know to to make a character float, can someone help me?
Btw, here's the code:
Whirwind Float:
addHook("PlayerThink", function(player)
    if player.powers[pw_shield] == SH_WHIRLWIND
        if player.pflags & PF_SHIELDABILITY
        and p.mo.state == S_PLAY_JUMP
            p.float = true
I am struggling with this, ok?
 
Hello, i'm trying to make a lua script that makes sonic float and move in any direction whenever using the Whirlwind shield, but i don't know to to make a character float, can someone help me?
Btw, here's the code:
Whirwind Float:
addHook("PlayerThink", function(player)
    if player.powers[pw_shield] == SH_WHIRLWIND
        if player.pflags & PF_SHIELDABILITY
        and p.mo.state == S_PLAY_JUMP
            p.float = true
I am struggling with this, ok?

Here you go:
Whirlwind Float:
addHook("PlayerThink", function(player)
    if player.mo
    and player.mo.valid
        if player.powers[pw_shield] == SH_WHIRLWIND
            if player.pflags & PF_SHIELDABILITY
            and player.mo.state == S_PLAY_JUMP
                player.float = true
            end
        end
        if player.float
            if P_PlayerInPain(player.mo)
            or player.playerstate != PST_LIVE
            or not (player.pflags & PF_SHIELDABILITY
            and player.mo.state == S_PLAY_JUMP)
            or player.powers[pw_shield] != SH_WHIRLWIND
            or P_IsObjectOnGround(player.mo)
            or player.exiting
            or (player.cmd.buttons & BT_JUMP
            and player.cmd.buttons & BT_USE)
                player.pflags = $|PF_THOKKED & ~PF_SHIELDABILITY
                player.float = false
            end
            if player.cmd.buttons & BT_JUMP
                player.mo.momz = 10*player.mo.scale*P_MobjFlip(player.mo)
            elseif player.cmd.buttons & BT_USE
                player.mo.momz = -(10*player.mo.scale*P_MobjFlip(player.mo))
            else
                player.mo.momz = $*5/6
            end
        end
    end
end)
It wasn't tested, but there shouldn't be any errors. (please credit me :threat:)
 
Here you go:
Whirlwind Float:
addHook("PlayerThink", function(player)
    if player.mo
    and player.mo.valid
        if player.powers[pw_shield] == SH_WHIRLWIND
            if player.pflags & PF_SHIELDABILITY
            and player.mo.state == S_PLAY_JUMP
                player.float = true
            end
        end
        if player.float
            if P_PlayerInPain(player.mo)
            or player.playerstate != PST_LIVE
            or not (player.pflags & PF_SHIELDABILITY
            and player.mo.state == S_PLAY_JUMP)
            or player.powers[pw_shield] != SH_WHIRLWIND
            or P_IsObjectOnGround(player.mo)
            or player.exiting
            or (player.cmd.buttons & BT_JUMP
            and player.cmd.buttons & BT_USE)
                player.pflags = $|PF_THOKKED & ~PF_SHIELDABILITY
                player.float = false
            end
            if player.cmd.buttons & BT_JUMP
                player.mo.momz = 10*player.mo.scale*P_MobjFlip(player.mo)
            elseif player.cmd.buttons & BT_USE
                player.mo.momz = -(10*player.mo.scale*P_MobjFlip(player.mo))
            else
                player.mo.momz = $*5/6
            end
        end
    end
end)
It wasn't tested, but there shouldn't be any errors. (please credit me :threat:)
For some reason, it still makes me do a double jump, instead of floating, i thought the behavior would be similar to the wind shield from sonic time twisted. Did you write the code right?
 
For some reason, it still makes me do a double jump, instead of floating, i thought the behavior would be similar to the wind shield from sonic time twisted. Did you write the code right?

Found that and other issues. Now it's fixed, and this time I tested it.
Whirlwind Float:
addHook("PlayerThink", function(player)
    if player.mo
    and player.mo.valid
        if player.powers[pw_shield] == SH_WHIRLWIND
        and player.pflags & PF_SHIELDABILITY
            player.float = true
        end
    end
    if player.float
        player.mo.flags = $|MF_NOGRAVITY
        if player.cmd.buttons & BT_JUMP
            player.mo.state = S_PLAY_SPRING
            player.mo.momz = 10*player.mo.scale*P_MobjFlip(player.mo)
        elseif player.cmd.buttons & BT_USE
            player.mo.state = S_PLAY_FALL
            player.mo.momz = -(10*player.mo.scale*P_MobjFlip(player.mo))
        else
            player.mo.state = S_PLAY_ROLL
            player.mo.momz = $*5/6
        end
        if P_PlayerInPain(player)
        or player.playerstate != PST_LIVE
        or not (player.pflags & PF_SHIELDABILITY)
        or player.powers[pw_shield] != SH_WHIRLWIND
        or P_IsObjectOnGround(player.mo)
        or player.exiting
        or (player.cmd.buttons & BT_JUMP
        and player.cmd.buttons & BT_USE)
            player.mo.flags = $ & ~MF_NOGRAVITY
            player.pflags = $|PF_THOKKED & ~PF_SHIELDABILITY
            player.float = false
        end
    end
end)
 
Hello, i'm trying to make a lua script that makes sonic float and move in any direction whenever using the Whirlwind shield, but i don't know to to make a character float, can someone help me?
Btw, here's the code:
Whirwind Float:
addHook("PlayerThink", function(player)
    if player.powers[pw_shield] == SH_WHIRLWIND
        if player.pflags & PF_SHIELDABILITY
        and p.mo.state == S_PLAY_JUMP
            p.float = true
I am struggling with this, ok?
Lua:
addHook("PlayerThink", function(player)
    if player.powers[pw_shield] == SH_WHIRLWIND
        if player.pflags & PF_SHIELDABILITY
        and player.mo.state == S_PLAY_JUMP
            player.float = true
        end
    end
end)

Hasn't been tested, but it should do the trick.
 
Now it works properly, but there's a little problem: It doesn't have time limit, so it makes the shield too overpowered. Is there a way to make the shield ability deactivate when passed 10 seconds?
 
Now it works properly, but there's a little problem: It doesn't have time limit, so it makes the shield too overpowered. Is there a way to make the shield ability deactivate when passed 10 seconds?

The local variable float_timelimit at the start defines the time limit in seconds. Don't multiply it by TICRATE (35), the code will do that automatically.
Whirlwind Float:
local float_timelimit = 10

addHook("PlayerThink", function(player)
    if player.mo
    and player.mo.valid
        if player.powers[pw_shield] == SH_WHIRLWIND
        and player.pflags & PF_SHIELDABILITY
            player.float = true
        end
    end
    if player.float
        player.mo.flags = $|MF_NOGRAVITY
        player.float_time = $-1
        if player.cmd.buttons & BT_JUMP
            player.mo.state = S_PLAY_SPRING
            player.mo.momz = 10*player.mo.scale*P_MobjFlip(player.mo)
        elseif player.cmd.buttons & BT_USE
            player.mo.state = S_PLAY_FALL
            player.mo.momz = -(10*player.mo.scale*P_MobjFlip(player.mo))
        else
            player.mo.state = S_PLAY_ROLL
            player.mo.momz = $*5/6
        end
        if P_PlayerInPain(player)
        or player.playerstate != PST_LIVE
        or not (player.pflags & PF_SHIELDABILITY)
        or player.powers[pw_shield] != SH_WHIRLWIND
        or P_IsObjectOnGround(player.mo)
        or player.exiting
        or (player.cmd.buttons & BT_JUMP
        and player.cmd.buttons & BT_USE)
        or not player.float_time
            player.mo.state = S_PLAY_PAIN
            player.mo.flags = $ & ~MF_NOGRAVITY
            player.pflags = $|PF_THOKKED & ~PF_SHIELDABILITY
            player.float = false
        end
    else
        player.float_time = float_timelimit*35
    end
end)
 

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

Back
Top