//local zposlastframe = 0
//local addspeed = 0
//local goundtics = false
//local normallastframe = 0

addHook("PlayerThink", function(player)
	if player.mo and player.playerstate == PST_LIVE then
		
		if player.zposlastframe == nil then
		player.zposlastframe = 0
		end
		
		if player.addspeed == nil then
		player.addspeed = 0
		end
		
		if player.goundtics == nil then
		player.goundtics = 0
		end
		
		if player.normallastframe == nil then
		player.normallastframe = 0
		end
		
		if player.mo.state == S_PLAY_FALL and not (player.pflags & PF_THOKKED) or player.mo.state == S_PLAY_FALL and (player.pflags & PF_SHIELDABILITY) then
			player.mo.state = S_PLAY_RUN
		end
		if player.addspeed > 0 and player.addspeed < 300 then player.normalspeed = 30*FRACUNIT + player.addspeed*FRACUNIT end
		if player.normalspeed < 30*FRACUNIT then player.normalspeed = 30*FRACUNIT end
		
		if player.speed > 40*FRACUNIT then
		P_SpawnThokMobj(player)
		player.charflags = $1 |SF_DASHMODE
		player.dashmode = 4*TICRATE
		else
		player.charflags = $1 & ~SF_DASHMODE
		player.dashmode = 0*TICRATE
		end
		
		if player.goundtics == true and player.zposlastframe - player.mo.z > 0 then
		player.addspeed = $ + ((player.zposlastframe/(FRACUNIT*10)) - (player.mo.z/(FRACUNIT*10)))
		player.zposlastframe = player.mo.z
		elseif player.addspeed > 0 then
		player.addspeed = $ - 1
		end
		if player.zposlastframe ~= player.mo.z then
		player.zposlastframe = player.mo.z
		end
		
		if (player.speed/FRACUNIT) - (player.normallastframe/FRACUNIT) > 20 then
		player.addspeed = (player.speed/FRACUNIT) - 30
		end
		if player.normallastframe ~= player.speed then
		player.normallastframe = player.speed
		end
		
		if player.addspeed < 0 then
		player.addspeed = 0
		end
		if player.addspeed > 300 then
		player.addspeed = 300
		end
		
		player.goundtics = P_IsObjectOnGround(player.mo)
		//player.score = player.speed
		//if (player.powers[pw_shield] & SH_FORCE) or (player.powers[pw_shield] & SH_WHIRLWIND) or (player.powers[pw_shield] & SH_ARMAGEDDON) (player.powers[pw_shield] & SH_ATTRACT) or (player.powers[pw_shield] & SH_FLAMEAURA) or (player.powers[pw_shield] & SH_BUBBLEWRAP) or (player.powers[pw_shield] & SH_THUNDERCOIN) then
		//player.pflags = $ |PF_THOKKED
		//end

	end
end)

addHook("PlayerSpawn", function(player)
	if player.mo then

		player.normalspeed = 30*FRACUNIT
		player.mindash = 10*FRACUNIT
		player.maxdash = 200*FRACUNIT
		player.jumpfactor = 1*FRACUNIT + FRACUNIT/2 + FRACUNIT/6
		player.charflags = $1 & ~SF_NOJUMPSPIN
		player.charflags = $1 & ~SF_NOJUMPDAMAGE
		player.charflags = $1 & ~SF_MARIODAMAGE
		player.charflags = $1 & ~SF_STOMPDAMAGE
		player.charflags = $1 & ~SF_NOSUPERJUMPBOOST	
		player.charflags = $1 & ~SF_RUNONWATER
		player.charflags = $1 |SF_SUPER
		//player.charflags = $1 |SF_NOSHIELDABILITY
		//player.charflags = $1 & ~SF_MULTIABILITY
		player.revitem = 0
		player.charability2 = CA2_SPINDASH
		player.runspeed = 25*FRACUNIT
		//player.thrustfactor = 4
		
		if player.zposlastframe == nil then
		player.zposlastframe = 0
		end
		
		if player.addspeed == nil then
		player.addspeed = 0
		end
		
		if player.goundtics == nil then
		player.goundtics = 0
		end
		
		if player.normallastframe == nil then
		player.normallastframe = 0
		end
		
	end
end)
/*
hud.add(function(v,player)
	if player.mo then
		local xpos = hudinfo[HUD_RINGS].x
		local ypos = hudinfo[HUD_RINGS].y
		v.drawString(xpos, ypos + 20, ("ADDSPEED: " + (player.addspeed)), V_PERPLAYER|V_GREENMAP)
		v.drawString(xpos, ypos + 30, ("NORMALSPEED: " + (player.normalspeed/FRACUNIT)), V_PERPLAYER|V_GREENMAP)
		v.drawString(xpos, ypos + 40, ("Zlast: " + (player.zposlastframe/FRACUNIT)), V_PERPLAYER|V_GREENMAP)
		v.drawString(xpos, ypos + 50, ("Z: " + (player.mo.z/FRACUNIT)), V_PERPLAYER|V_GREENMAP)
		v.drawString(xpos, ypos + 60, ("DIFF: " + ((player.zposlastframe - player.mo.z)/FRACUNIT)), V_PERPLAYER|V_GREENMAP)
	end
end)
*/