Problem with custom states

Status
Not open for further replies.

Simon_T

Pyro the Setsuna Fan
I'm trying to imitate the Vanilla Super Sonic's ability to float with Lua and custom states to allow him to uncurl and fly, but he gets stuck into a frame :'V

Here's the Lua

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "supersonic")
			if player.cmd.buttons & BT_USE
			and not P_IsObjectOnGround(player.mo)
				player.mo.momz = 0
				player.mo.state = S_PLAY_FLOAT1
			end
		end
	end
end)

And the SOC for custom states

Code:
FREESLOT
S_PLAY_FLOAT1
S_PLAY_FLOAT2

STATE S_PLAY_FLOAT1
SPRITENAME = PLAY
SPRITEFRAME = U|FF_FULLBRIGHT
DURATION =  3
NEXT = S_PLAY_FLOAT2

STATE S_PLAY_FLOAT2
SPRITENAME = PLAY
SPRITEFRAME = V|FF_FULLBRIGHT
DURATION =  3
NEXT = S_PLAY_FLOAT1

What I'm doing wrong?
 
Last edited:
You see, when you press the spin button while you with this skin, you're being forced to change your state to S_PLAY_FLOAT1. However, if you find a way to command the lua to force this state only when you press the button and not when the button is down like this:

Code:
if player.usekeydown == nil
player.usekeydown = 0
end
if (player.cmd.buttons & BT_USE)
   player.usekeydown = $1+1
   else
   player.usekeydown = 0
end

And then when you replace the - "if player.cmd.buttons & BT_USE" with
Code:
if player.usekeydown == 1
so whenever you hold your spin button, you raise the player.usekeydown and when you release the button, it becomes 0, so when the "player.usekeydown" touches the 1, it will change to this state.
I don't know though, I might be wrong, but I hope that's the solution...
 
Here's a simpler solution. All you have to do is check that the player is not already in one of the floating states before you set the new state:

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "supersonic")
			if player.cmd.buttons & BT_USE
			and not P_IsObjectOnGround(player.mo)
				player.mo.momz = 0
				if not (player.mo.state >= S_PLAY_FLOAT1 and player.mo.state <= S_PLAY_FLOAT2)
					player.mo.state = S_PLAY_FLOAT1
				end
			end
		end
	end
end)
 
Here's a simpler solution. All you have to do is check that the player is not already in one of the floating states before you set the new state:

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "supersonic")
			if player.cmd.buttons & BT_USE
			and not P_IsObjectOnGround(player.mo)
				player.mo.momz = 0
				if not (player.mo.state >= S_PLAY_FLOAT1 and player.mo.state <= S_PLAY_FLOAT2)
					player.mo.state = S_PLAY_FLOAT1
				end
			end
		end
	end
end)

Sadly, he's still getting stuck in the first floating frame :"V
 
Oh, my bad. I forgot that the game probably resets his animation to the jumping animation every tic. You can get around this by setting one of the two states based on the leveltime. Assuming you want to keep your state duration of 3 tics:

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "supersonic")
			if player.cmd.buttons & BT_USE
			and not P_IsObjectOnGround(player.mo)
				player.mo.momz = 0
				if (leveltime % 6) > 2
					player.mo.state = S_PLAY_FLOAT2
				else
					player.mo.state = S_PLAY_FLOAT1
				end
			end
		end
	end
end)

It's a little hacky but it's probably the simplest way to get the effect you want.
 
Status
Not open for further replies.

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

Back
Top