Lua scripting help

Sir Thoksalot

What the thok
I attempted scripting mach-speed animations. It makes the players state "S_PLAY_DASH" when they're at 60 FRACUNITS. But the player stays in the DASH state despite not being at the required speed until the player jumps or uses one of their abilities

srb20092.gif


Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo.valid
		and P_IsObjectOnGround
		and player.mo.state == S_PLAY_RUN
		and (player.speed > 60*FRACUNIT)
		and not (player.mo.skin == "whirl")
		and not (player.mo.skin == "modernsonic")
		and not (player.mo.skin == "altsonic")
		and not (player.mo.skin == "metalsonic") then
			player.mo.state = S_PLAY_DASH
		end
	end
end)

And no surprise, it works fine with "SF_DASHMODE" characters. I'm assuming I have to use
Code:
else
or
Code:
elseif
I'm just not sure how I should do it
 
You have to restore the player's animation back to what it should be yourself.

Though really, I don't see why you shouldn't be using the built-in SF_DASHMODE here.
 
You have to restore the player's animation back to what it should be yourself.

So something like this?

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo.valid
		and P_IsObjectOnGround
		and player.mo.state == S_PLAY_RUN
		and (player.speed > 60*FRACUNIT)
		and not (player.mo.skin == "whirl")
		and not (player.mo.skin == "modernsonic")
		and not (player.mo.skin == "altsonic")
		and not (player.mo.skin == "metalsonic") then
			player.mo.state = S_PLAY_DASH
		else
		      player.mo.state = player.mo.state
	      end
	end
end)
 
That doesn't solve the problem.
If player.mo.state IS S_PLAY_DASH already (which is set in the script as you know), it keeps player.mo.state as it is. So if you reach 60 Fracunits per tic and then stop, you'll never come out of the S_PLAY_DASH state, unless you jump.
 
That doesn't solve the problem.
If player.mo.state IS S_PLAY_DASH already (which is set in the script as you know), it keeps player.mo.state as it is. So if you reach 60 Fracunits per tic and then stop, you'll never come out of the S_PLAY_DASH state, unless you jump.
Instead you can probably set a prevstate variable that changes to your state ONLY if you're not in S_PLAY_DASH, then change to that once the conditions are no longer met.
 
Turn else into an elseif which also uses and to consider the following criertia:
- Below 60*FRACUNITS speed.
- Is in the dash frames.
- On the ground.

Also, P_IsObjectOnGround requires a mo field, so it should be:
Code:
P_IsObjectOnGround(player.mo)
 
Last edited:

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

Back
Top