Sonic 06 style thok?

Status
Not open for further replies.

MarioFreak2001

that one gal
I'm trying to make a Sonic 06 style thok, and I need some help.
Here's the code:

addHook("ThinkFrame", do
for player in players.iterate
if player.mo and player.mo.skin == player.mo.skin
if not (player.mo.thoktimer)
player.mo.thoktimer = 0
end
if player.mo.thoktimer > 0
player.mo.thoktimer = $1 - 1
end
if player.pflags & PF_THOKKED
and (not(player.homing))
and player.powers[pw_super] == 0
//P_InstaThrust(player.mo, player.mo.angle, 50*FRACUNIT)
A_Thrust(player.mo, 50, 1)
local thok = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_THOK)
thok.color = player.mo.color
thok.scale = player.mo.scale
thok.fuse = 3
player.mo.momz = 0
end
end
end
end)

Sonic keeps getting thrusted forward, which is the desired effect, but I want him to stop 1 second after thoking. And I don't know how to do that.
EDIT: Ignore the code not looking right.
EDIT: Also I want him to drop like a rock when the thok ends like in Sonic 06
 
Last edited:
You have the right idea with thoktimer, you're just not doing anything with it.
Set thoktimer to however many tics you want it to last when the player thoks (i.e. if you wanted it to last 1 second you'd set it to 35) and add a check if player.mo.thoktimer == 0 directly after player.mo.thoktimer = $1 - 1 so it's in the player.mo.thoktimer > 0 if-end, set the players momx and momy to 0 and momz to what ever you may deem necessary if thoktimer is 0.

You may also wish to keep the players momz to 0 during the thok, which you could do by adding player.mo.momz = 0 in with the code that decrements thoktimer.
 
You have the right idea with thoktimer, you're just not doing anything with it.
Set thoktimer to however many tics you want it to last when the player thoks (i.e. if you wanted it to last 1 second you'd set it to 35) and add a check if player.mo.thoktimer == 0 directly after player.mo.thoktimer = $1 - 1 so it's in the player.mo.thoktimer > 0 if-end, set the players momx and momy to 0 and momz to what ever you may deem necessary if thoktimer is 0.

You may also wish to keep the players momz to 0 during the thok, which you could do by adding player.mo.momz = 0 in with the code that decrements thoktimer.

I'm getting a bit confused...
I'm not that great with coding, so could you explain it a bit clearer?
 
Code:
			if player.pflags & PF_THOKKED
			and (not(player.homing))
			and player.powers[pw_super] == 0
				//P_InstaThrust(player.mo, player.mo.angle, 50*FRACUNIT)
				A_Thrust(player.mo, 50, 1)
				local thok = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_THOK)
				thok.color = player.mo.color
				thok.scale = player.mo.scale
				thok.fuse = 3
				player.mo.momz = 0
			end

At this part, you'd want to add player.mo.thoktimer = 35, so it'd look like this:

Code:
			if player.pflags & PF_THOKKED
			and (not(player.homing))
			and player.powers[pw_super] == 0
				//P_InstaThrust(player.mo, player.mo.angle, 50*FRACUNIT)
				A_Thrust(player.mo, 50, 1)
				local thok = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_THOK)
				thok.color = player.mo.color
				thok.scale = player.mo.scale
				thok.fuse = 3
				player.mo.momz = 0
				player.mo.thoktimer = 35
			end

Then at this part
Code:
			if player.mo.thoktimer > 0
				player.mo.thoktimer = $1 - 1
			end
You'd want to add
if player.mo.thoktimer == 0
player.mo.momx = 0
player.mo.momy = 0
player.mo.momz = -20*FRACUNIT
end

so it'd look like:

Code:
			if player.mo.thoktimer > 0
				player.mo.thoktimer = $1 - 1
				if player.mo.thoktimer == 0
					player.mo.momx = 0
					player.mo.momy = 0
					player.mo.momz = -20*FRACUNIT
				end
			end

This makes it so when you thok you set thoktimer to 35, which is equivelant to 1 second because srb2 has 35 tics in 1 second. It decrements thoktimer until it reaches 0, and when it does, it resets your momentum and makes you drop faster.
 
So, should it look like this?

addHook("ThinkFrame", do
for player in players.iterate
if player.mo and player.mo.skin == player.mo.skin
if not (player.mo.thoktimer)
player.mo.thoktimer = 0
end
if player.mo.thoktimer > 0
player.mo.thoktimer = $1 - 1
if player.mo.thoktimer == 0
player.mo.momx = 0
player.mo.momy = 0
player.mo.momz = -20*FRACUNIT
end
end
if player.pflags & PF_THOKKED
and (not(player.homing))
and player.powers[pw_super] == 0
//P_InstaThrust(player.mo, player.mo.angle, 50*FRACUNIT)
A_Thrust(player.mo, 50, 1)
local thok = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_THOK)
thok.color = player.mo.color
thok.scale = player.mo.scale
thok.fuse = 3
player.mo.momz = 0
player.mo.thoktimer = 35
end
end
end
end)

EDIT: It's not working. I just end up with the same result as the original code.
 
Last edited:
Oh, I mis-read the code. My apologies. You'd want to add a seperate variable to dictate whether or not you've already thokked in that jump, and set thoktimer to 35 in that instead. This could be achieved by changing a variable depending on whether or not the player's got PF_THOKKED already, and code before that checking for both PF_THOKKED and that variable, which sets thoktimer to 35, and only thrusting if thoktimer is above 0.

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == player.mo.skin
			if not (player.mo.thoktimer)
				player.mo.thoktimer = 0
			end
			if not (player.mo.canthok)
				player.mo.canthok = 0
			end
			if player.mo.thoktimer > 0
				player.mo.thoktimer = $1 - 1
				if player.mo.thoktimer == 0
					player.mo.momx = 0
					player.mo.momy = 0
					player.mo.momz = -20*FRACUNIT
				end
			end
			if player.pflags & PF_THOKKED
			and (not(player.homing))
			and player.powers[pw_super] == 0
			and player.mo.thoktimer > 0
				//P_InstaThrust(player.mo, player.mo.angle, 50*FRACUNIT)
				A_Thrust(player.mo, 50, 1)
				local thok = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_THOK)
				thok.color = player.mo.color
				thok.scale = player.mo.scale
				thok.fuse = 3
				player.mo.momz = 0
			end
			if player.pflags & PF_THOKKED and player.mo.canthok == 1
				player.mo.thoktimer = 35
			end
			if player.pflags & PF_THOKKED
				player.mo.canthok = 0
			else
				player.mo.canthok = 1
			end
		end
	end
end)

This should work, for instance.
 
Status
Not open for further replies.

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

Back
Top