/// Ability: Super Jump
// allows you to charge a very high leap

// CUSTOMIZE SECTION START
local skin = "kaysonic" // your character here
local thebutton = BT_ATTACK // the button needed to do the super jump
local sound = sfx_cannon // the sound of the super jump
local superjumpcap = 150 // the cap of super jump charge you can gain
// CUSTOMIZE SECTION END PROCCED BELOW IF YOU KNOW WHAT YOUR DOING

addHook("PlayerThink", function(player)
	if not player then return end
	if not player.mo then return end
	if player.mo.superjumping == nil
		player.mo.superjumping = false
	end
	if player.mo.sjtime == nil
		player.mo.sjtime = 0
	end
	if not (player.cmd.buttons & thebutton) 
		player.buttontappready = true
		player.buttontapping = false
	elseif player.buttontappready
		player.buttontapping = true
		player.buttontappready = false
	else
		player.buttontapping = false
	end
	if player.mo.superjumping == true
		player.pflags = $|PF_FULLSTASIS
		P_InstaThrust(player.mo, player.mo.angle, 0)
		player.mo.sjtime = $ + 1
		player.mo.state = S_PLAY_ROLL
	end
	if player.mo.sjtime == superjumpcap-1
		local ghost = P_SpawnGhostMobj(player.mo) 
		ghost.scale = player.mo.scale*player.mo.sjtime/5
		ghost.destscale = player.mo.scale
		ghost.scalespeed = $*2
		ghost.z = player.mo.z-ghost.scale
	end
	if player.mo.sjtime == superjumpcap
		player.mo.sjtime = superjumpcap
	end
	if player.mo and player.mo.skin == skin
	and player.buttontapping
	and P_IsObjectOnGround(player.mo)
	and player.mo.superjumping == false
	and not player.weapondelay
		player.mo.superjumping = true
		player.weapondelay = 10
	end
	if player.mo and player.mo.skin == skin
	and player.buttontapping
	and P_IsObjectOnGround(player.mo)
	and player.mo.superjumping == true
	and not player.weapondelay
		player.weapondelay = 10
		player.mo.superjumping = false
		S_StartSound(player.mo, sound)
		P_SetObjectMomZ(player.mo, player.mo.sjtime*FRACUNIT)
		player.mo.sjtime = 0
		player.mo.state = S_PLAY_ROLL
		player.pflags = $ |PF_JUMPED
		player.pflags = $ & ~PF_THOKKED
	end
end)