Lua help: Harmful dash ability

Status
Not open for further replies.

Puppyfaic

Member
EDIT: Got the animation playing now, sort of...if anyone can help me with the actual ability, I basically want the player to move at a fixed speed for as long as he holds down the Spindash button, and when he lets go he stops moving completely.
Things I need to figure out how to do:
Figure out how to make the player hurt enemies without being in a spin state/disable the spin trail
Make all momentum stop only when the button is let go, not just when not being pressed.

Code:
freeslot("SPR_ATTK","S_PLAY_ATTACK1", "S_PLAY_ATTACK2", "S_PLAY_ATTACK3", "S_PLAY_ATTACK4", "S_PLAY_ATTACK5", "S_PLAY_ATTACK6", "S_PLAY_ATTACK7", "S_PLAY_ATTACK8")

states[S_PLAY_ATTACK1] = {SPR_ATTK, 0, 1, nil, 0, 0, S_PLAY_ATTACK2}
states[S_PLAY_ATTACK2] = {SPR_ATTK, 1, 1, nil, 0, 0, S_PLAY_ATTACK3}
states[S_PLAY_ATTACK3] = {SPR_ATTK, 2, 1, nil, 0, 0, S_PLAY_ATTACK4}
states[S_PLAY_ATTACK4] = {SPR_ATTK, 3, 1, nil, 0, 0, S_PLAY_ATTACK5}
states[S_PLAY_ATTACK5] = {SPR_ATTK, 4, 1, nil, 0, 0, S_PLAY_ATTACK6}
states[S_PLAY_ATTACK6] = {SPR_ATTK, 5, 1, nil, 0, 0, S_PLAY_ATTACK7}
states[S_PLAY_ATTACK7] = {SPR_ATTK, 6, 1, nil, 0, 0, S_PLAY_ATTACK8}
states[S_PLAY_ATTACK8] = {SPR_ATTK, 7, 1, nil, 0, 0, S_PLAY_ATTACK1}

addHook("ThinkFrame", function()
        for player in players.iterate do
                if player.mo.skin ~= "sharp" then
                        continue
                end

                if (player.cmd.buttons & BT_USE)
                and not player.powers[pw_super]
		and not (player.pflags & PF_NIGHTSMODE)
		and not (player.pflags & PF_ROPEHANG)
		and not (player.pflags & PF_MACESPIN)
		and not (player.pflags & PF_TAGGED)
		and not (player.pflags & PF_STASIS)
		and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT)
		and not (player.exiting)
		and (player.health) then
                        A_Thrust(player.mo, 30, 1)
                        S_StartSound(player.mo, sfx_s3kd8s)
                        player.pflags = $1|PF_SPINNING
		        player.mo.state = S_PLAY_ATTACK1
                end
        end
end)
 
Last edited:
Make all momentum stop only when the button is let go, not just when not being pressed.
In essence, the information you need is whether the button is not pressed now, but was pressed last tic. To do that, add something like this to the end of your function:

Code:
if (player.cmd.buttons & BT_USE)
    player.buttonpressed = true
else
    player.buttonpressed = false
end

Now you can check if the button has been released with "if player.buttonpressed and not player.cmd.buttons & BT_USE".
 
It should look like this, then, right?
Code:
addHook("ThinkFrame", function()
        for player in players.iterate do
                if player.mo.skin ~= "sharp" then
                        continue
                end

                if (player.cmd.buttons & BT_USE)
                        player.buttonpressed = true
                else
                        player.buttonpressed = false
                end

                if (player.cmd.buttons & BT_USE)
                and not player.powers[pw_super]
		and not (player.pflags & PF_NIGHTSMODE)
		and not (player.pflags & PF_ROPEHANG)
		and not (player.pflags & PF_MACESPIN)
		and not (player.pflags & PF_TAGGED)
		and not (player.pflags & PF_STASIS)
		and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT)
		and not (player.exiting)
		and (player.health) then
                        A_Thrust(player.mo, 30, 1)
                elseif player.buttonpressed
                and not (player.cmd.buttons & BT_USE)
                        A_Thrust(player.mo, 0, 1)
                end
        end
end)

I'm asking because that's not working for me. I think I just did something wrong with the A_Thrust though.
 
Last edited:
You have to set player.buttonpressed at the end of your function. Right now it tells you if the button is pressed now, not if it was pressed last tic (which is what you want to know).
 
Like this?
Code:
addHook("ThinkFrame", function()
        for player in players.iterate do
                if player.mo.skin ~= "sharp" then
                        continue
                end

                if (player.cmd.buttons & BT_USE)
                and not player.powers[pw_super]
		and not (player.pflags & PF_NIGHTSMODE)
		and not (player.pflags & PF_ROPEHANG)
		and not (player.pflags & PF_MACESPIN)
		and not (player.pflags & PF_TAGGED)
		and not (player.pflags & PF_STASIS)
		and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT)
		and not (player.exiting)
		and (player.health) then
                        A_Thrust(player.mo, 30, 1)
                end
                if (player.cmd.buttons & BT_USE)
                        player.buttonpressed = true
                else
                        player.buttonpressed = false
                end
        end       
end)
 
Yes, but now you're not actually checking if player.buttonpressed is true, which is why you added the variable to begin with.
 
EDIT: Nevermind. I got it working now. Like this, right?

Code:
addHook("ThinkFrame", function()
        for player in players.iterate do
                if player.mo.skin ~= "sharp" then
                        continue
                end

                if (player.cmd.buttons & BT_USE)
                and not player.powers[pw_super]
		and not (player.pflags & PF_NIGHTSMODE)
		and not (player.pflags & PF_ROPEHANG)
		and not (player.pflags & PF_MACESPIN)
		and not (player.pflags & PF_TAGGED)
		and not (player.pflags & PF_STASIS)
		and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT)
		and not (player.exiting)
		and (player.health) then
                        A_Thrust(player.mo, 30, 1)
                        player.pflags = $1|PF_SPINNING
                elseif player.buttonpressed
                and not (player.cmd.buttons & BT_USE)
                        A_Thrust(player.mo, 0, 1)
                        player.pflags = $1 & ~PF_SPINNING
                        player.mo.state = S_PLAY_STND
                end
                if (player.cmd.buttons & BT_USE)
                        player.buttonpressed = true
                else
                        player.buttonpressed = false
                end
        end       
end)

Now I just need to figure out how to make the player hurt enemies without being in a spin state.
 
Last edited:
Looks correct, although "and not (player.cmd.buttons & BT_USE)" is superfluous. The elseif block is only executed if BT_USE is not pressed anyway.
 
One last question: Would it be possible to add more frames to the spinning animation via Lua?

I have extended running animations before, so spinning should also be possible, just create custom states, then check for the skin, after that check if the player is spinning, if he is, change the states using player.mo.state or P_SetMobjStateNF(player.mo, customstate)
 
I have extended running animations before, so spinning should also be possible, just create custom states, then check for the skin, after that check if the player is spinning, if he is, change the states using player.mo.state or P_SetMobjStateNF(player.mo, customstate)

That only repeats the first frame of the state over and over.
 
Status
Not open for further replies.

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

Back
Top