SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Editing > Editing Help

Reply
 
Thread Tools Search this Thread
Old 08-06-2017   #1
Simon_T
Pyro the Hedgehog
 
Simon_T's Avatar
Default Problem with custom states

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?
__________________
O kurwa!

Last edited by Simon_T; 08-06-2017 at 12:23 AM.
Simon_T is offline   Reply With Quote
Old 08-06-2017   #2
ManimiFire
Meow Motherfuckers.
 
ManimiFire's Avatar
Default

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...
__________________
Check out my youtube channel: https://www.youtube.com/channel/UCd1...hUkNvNA93RPI8g
ManimiFire is offline   Reply With Quote
Old 08-06-2017   #3
Lach
Latch? Lock?? Lack???
 
Lach's Avatar
Default

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)
__________________
Check out my new SRB2 YouTube channel!
Cool mods I made:
Orb
Combine Ring Monitors
Lach is offline   Reply With Quote
Old 08-07-2017   #4
Simon_T
Pyro the Hedgehog
 
Simon_T's Avatar
Default

Quote:
Originally Posted by Lach View Post
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
__________________
O kurwa!
Simon_T is offline   Reply With Quote
Old 08-07-2017   #5
Lach
Latch? Lock?? Lack???
 
Lach's Avatar
Default

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.
__________________
Check out my new SRB2 YouTube channel!
Cool mods I made:
Orb
Combine Ring Monitors
Lach is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:51 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.