//kungfu
addHook("ThinkFrame", function()
    for player in players.iterate do
        if ((player.mo.skin == "pizzano") or (player.exiting))
			if ((player.mo.state == S_PLAY_MELEE_FINISH) or (player.mo.state == S_PLAY_MELEE) or (player.mo.state == S_PLAY_MELEE_LANDING))
			and not ((player.mo.state == S_PLAY_KUNGFU1) or (player.mo.state == S_PLAY_KUNGFU2) or (player.mo.state == S_PLAY_KUNGFU3) or (player.mo.state == S_PLAY_KUNGFU4) or (player.mo.state == S_PLAY_KUNGFU5) or (player.mo.state == S_PLAY_CHAINSAW) or (player.mo.state == S_PLAY_KUNGFU6))
			and P_IsObjectOnGround(player.mo) then 
					player.randomkungfu = P_RandomRange(1, 6)
					if player.randomkungfu == 1
					    player.mo.state = S_PLAY_KUNGFU1
						S_StartSound(player.mo, sfx_kungf)
					elseif player.randomkungfu == 2
						player.mo.state = S_PLAY_KUNGFU2
						S_StartSound(player.mo, sfx_kungf)
					elseif player.randomkungfu == 3
						player.mo.state = S_PLAY_KUNGFU3
						S_StartSound(player.mo, sfx_kungf)
					elseif player.randomkungfu == 4
					    player.mo.state = S_PLAY_KUNGFU4
						S_StartSound(player.mo, sfx_kungf)
					elseif player.randomkungfu == 5
						player.mo.state = S_PLAY_KUNGFU5
						S_StartSound(player.mo, sfx_kungf)
					elseif player.randomkungfu == 6
						player.mo.state = S_PLAY_KUNGFU6
						S_StartSound(player.mo, sfx_kungf)
				end
			end
		end
	end
end)

//can kungfu damage?
addHook("PlayerCanDamage", function(player)
	if player.mo.skin == "pizzano"
	and ((player.mo.state == S_PLAY_KUNGFU1)
	or (player.mo.state == S_PLAY_KUNGFU2)
	or (player.mo.state == S_PLAY_KUNGFU3)
	or (player.mo.state == S_PLAY_KUNGFU4)
	or (player.mo.state == S_PLAY_KUNGFU5)
	or (player.mo.state == S_PLAY_CHAINSAW)
	or (player.mo.state == S_PLAY_KUNGFU6)
	or (player.mo.state == S_PLAY_AIRKUNGFU1)
	or (player.mo.state == S_PLAY_AIRKUNGFU2))
	return true
	end
end)

//if you kungfu, you will be strong
addHook("PlayerThink", function(player)
 if player.mo.skin == "pizzano"
 	and player.mo.state == S_PLAY_KUNGFU1
	or player.mo.state == S_PLAY_KUNGFU2
	or player.mo.state == S_PLAY_KUNGFU3
	or player.mo.state == S_PLAY_KUNGFU4
	or player.mo.state == S_PLAY_KUNGFU5
	or player.mo.state == S_PLAY_KUNGFU6
	or player.mo.state == S_PLAY_AIRKUNGFU1
	or player.mo.state == S_PLAY_AIRKUNGFU2
	or player.mo.state == S_PLAY_CHAINSAW then
	player.powers[pw_strong] = STR_HEAVY|STR_SPRING|STR_SPIKE|STR_ANIM|STR_WALL
	end
end)

//kungfu in mid air (don´t work same the kungfu on ground)
addHook("ThinkFrame", function()
        for player in players.iterate do
        if player.mo.skin == "pizzano" and (player.cmd.buttons & BT_SPIN)
		and player.speed <= 30*FRACUNIT
		and ((player.mo.state == S_PLAY_JUMPINITIAL) or (player.mo.state == S_PLAY_FALL) or (player.mo.state == S_PLAY_PZNOMACH2JUMP) or (player.mo.state == S_PLAY_SPRING) or (player.mo.state == S_PLAY_PZNOMACH3JUMP)) then
                 player.randomkungfuair = P_RandomRange(1, 2)
					if player.randomkungfuair == 1
					and not (player.powers[pw_shield] == SH_ARMAGEDDON)
						player.mo.state = S_PLAY_AIRKUNGFU1
						P_Thrust(player.mo, player.mo.angle, 30*FRACUNIT)
						S_StartSound(player.mo, sfx_kungf)
					elseif player.randomkungfuair == 2
					and not (player.powers[pw_shield] == SH_ARMAGEDDON)
						player.mo.state = S_PLAY_AIRKUNGFU2
						P_Thrust(player.mo, player.mo.angle, 30*FRACUNIT)
						S_StartSound(player.mo, sfx_kungf)
			end
		end
	end
	for player in players.iterate do
		if player.mo.skin == "pizzano" and (player.cmd.buttons & BT_SPIN)
		and player.speed >= 30*FRACUNIT
		and ((player.mo.state == S_PLAY_JUMPINITIAL) or (player.mo.state == S_PLAY_FALL) or (player.mo.state == S_PLAY_PZNOMACH2JUMP) or (player.mo.state == S_PLAY_PZNOMACH3JUMP)) then
                 player.randomkungfuair = P_RandomRange(1, 2)
					if player.randomkungfuair == 1
					and not (player.powers[pw_shield] == SH_ARMAGEDDON)
						player.mo.state = S_PLAY_AIRKUNGFU1
						S_StartSound(player.mo, sfx_kungf)
					elseif player.randomkungfuair == 2
					and not (player.powers[pw_shield] == SH_ARMAGEDDON)
						player.mo.state = S_PLAY_AIRKUNGFU2
						S_StartSound(player.mo, sfx_kungf)
           end
		end
	end
end)

//slam
addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and player.mo.state == S_PLAY_BODYSLAM_INITIAL then
   P_SetObjectMomZ(player.realmo, 5*FRACUNIT, false)
   player.pflags = PF_THOKKED
end
end)

addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and player.mo.state == S_PLAY_BODYSLAM_FINAL then
   P_SetObjectMomZ(player.realmo, -65*FRACUNIT, false)
   player.pflags = PF_THOKKED
   player.powers[pw_nocontrol] = 1500000000000000000000
   player.pflags = PF_JUMPSTASIS
   player.powers[pw_strong] = STR_HEAVY|STR_SPRING|STR_SPIKE|STR_ANIM|STR_WALL
end
end)

addHook("ThinkFrame", do
    for player in players.iterate
        if (player.mo and player.mo.skin == "pizzano")
                if (player.cmd.buttons & BT_CUSTOM1) 
				and player.speed <= 32*FRACUNIT
				and not (player.mo.eflags & MFE_GOOWATER)
				and not P_IsObjectOnGround(player.mo) then
		            player.pstomp = true
					player.slamTimer = $+1
	                  else
					player.slamTimer = 0
					
					end
					if player.slamTimer == 1
					and not ((player.mo.state == S_PLAY_BODYSLAM_INITIAL) 
					or (player.mo.state == S_PLAY_SUPERJUMP_RELEASE) or (player.mo.state == S_PLAY_DEAD) or (player.mo.state == S_PLAY_PAIN) or (player.mo.state == S_PLAY_BODYSLAM_FINAL)) then
					     player.mo.state = S_PLAY_BODYSLAM_INITIAL
						 player.pflags = $|PF_FULLSTASIS
					end
				end
			end
end)

addHook ("PlayerThink",function(player)
if player.mo.skin == "pizzano"
and player.pstomp == true
and P_IsObjectOnGround(player.mo)

player.pstomp = false
player.powers[pw_nocontrol] = 1500000000000000000000
player.pflags = $|PF_FULLSTASIS
player.mo.state = S_PLAY_BODYSLAMLAND
P_NukeEnemies(player.mo, player.mo, 300*FRACUNIT)
S_StartSound(player.mo, sfx_slfnl)
P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
P_Thrust(player.mo, player.mo.angle, 0*FRACUNIT)
P_StartQuake(FRACUNIT*5, TICRATE/8*1)
end
end)

addHook ("PlayerThink",function(player)
if player.mo.skin == "pizzano"
and player.pstomp == true
and ((player.mo.state == S_PLAY_PAIN) or (player.mo.state == S_PLAY_DEAD) or (player.mo.state == S_PLAY_KUNGFU2) or (player.mo.state == S_PLAY_KUNGFU1)) then
 
player.pstomp = false
end
end)

addHook ("PlayerThink",function(player)
if player.mo.skin == "pizzano"
and player.pstomp == true
and player.mo.state == S_PLAY_SPRING then

player.pstomp = false
end 
end)

addHook ("PlayerThink",function(player)
if player.mo.skin == "pizzano"
and player.pstomp == true
and ((player.mo.state == S_PLAY_BODYSLAM_INITIAL) or (player.mo.state == S_PLAY_BODYSLAM_FINAL))
and (player.mo.eflags & MFE_GOOWATER)

player.pstomp = false
player.mo.state = S_PLAY_FALL
end
end)

//slam sounds effects(andsuperjump)
addHook("PlayerThink", function(player)
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and (player.mo.state == S_PLAY_BODYSLAM_INITIAL)
		and not S_SoundPlaying(player.mo, sfx_slstar) then
		S_StartSound(player.mo, sfx_slstar)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and not (player.mo.state == S_PLAY_BODYSLAM_INITIAL)
		and S_SoundPlaying(player.mo, sfx_slstar) then
		S_StopSoundByID(player.mo, sfx_slstar)
	end
		if ((player.mo.skin == "pizzano") or (player.exiting))
	    and (player.mo.state == S_PLAY_SUPERJUMP_PREPARE)	
		and not S_SoundPlaying(player.mo, sfx_sjhol) then
		S_StartSound(player.mo, sfx_sjhol)
    end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and not (player.mo.state == S_PLAY_SUPERJUMP_PREPARE)
		and S_SoundPlaying(player.mo, sfx_sjhol) then
		S_StopSoundByID(player.mo, sfx_sjhol)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and (player.mo.state == S_PLAY_SUPERJUMP_PREPARESIDE)	
		and not S_SoundPlaying(player.mo, sfx_sjcan) then
		S_StartSound(player.mo, sfx_sjcan)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and (player.mo.state == S_PLAY_SUPERJUMP_RELEASE)	
		and not S_SoundPlaying(player.mo, sfx_sjrel) then
		S_StartSound(player.mo, sfx_sjrel)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and (player.mo.state == S_PLAY_BODYSLAM_FINAL)	
		and not S_SoundPlaying(player.mo, sfx_slloop) then
		S_StartSound(player.mo, sfx_slloop)
    end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and not (player.mo.state == S_PLAY_BODYSLAM_FINAL)
		and S_SoundPlaying(player.mo, sfx_slloop) then
		S_StopSoundByID(player.mo, sfx_slloop)
	end
end)

//slam effect(superjumptoo)
addHook("ThinkFrame", do
	for p in players.iterate
		if ((p.mo.state == S_PLAY_BODYSLAM_FINAL) or (p.mo.state == S_PLAY_SUPERJUMP_RELEASE))
		and leveltime%5 == 0
			local ring = P_SpawnMobj(p.mo.x,p.mo.y,p.mo.z,MT_THOK)
			ring.state = S_MACH4RING
			ring.fuse = 999
			ring.tics = 20
			ring.angle = p.drawangle+ANGLE_90
			ring.scale = p.mo.scale-FRACUNIT/2
			ring.destscale = p.mo.scale*2
			ring.colorized = true
			ring.renderflags = $|RF_FLOORSPRITE
			ring.color = SKINCOLOR_WHITE
			if (p.mo.eflags & MFE_VERTICALFLIP)
				ring.flags2 = $|MF2_OBJECTFLIP
				ring.eflags = $|MFE_VERTICALFLIP
			end
		end
	end
end)

// Pizzano falling during a dive drop while diving. -Wiki
addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and ((player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE) or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE) or (player.mo.state == S_PLAY_DIVE))
and not (player.mo.eflags & MFE_UNDERWATER)
and (player.cmd.buttons & BT_CUSTOM2) then
	player.pstomp = true
	P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
	player.mo.state = S_PLAY_BODYSLAM_INITIAL
end
end) 

//POW!!
addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
    if target.player and target.player.valid and target.skin == "pizzano"
	and inflictor and inflictor.valid
    and ((target.player.mo.state == S_PLAY_TAUNT1)
	or (target.player.mo.state == S_PLAY_TAUNT2)
	or (target.player.mo.state == S_PLAY_TAUNT3)
	or (target.player.mo.state == S_PLAY_TAUNT4)
	or (target.player.mo.state == S_PLAY_TAUNT5)
	or (target.player.mo.state == S_PLAY_TAUNT6)
	or (target.player.mo.state == S_PLAY_TAUNT7)
	or (target.player.mo.state == S_PLAY_TAUNT8)
	or (target.player.mo.state == S_PLAY_TAUNT9))
    and (inflictor.flags & MF_ENEMY or inflictor.flags & MF_BOSS or inflictor.flags & MF_MISSILE or inflictor.flags & MF_PAIN or damagetype & DMG_SPIKE or damagetype & DMG_ELECTRIC)
		target.player.powers[pw_flashing] = 15
		P_DamageMobj(inflictor, target, target, DMG_WATER)
		target.player.score = $+500
		S_StartSound(target, sfx_parry)
		P_InstaThrust(target, target.angle, -9*FRACUNIT)
		P_SpawnMobj(target.x,target.y,target.z,MT_THOK)
		target.state = P_RandomRange(S_PLAY_PARRY, S_PLAY_PARRY1, S_PLAY_PARRY2)
		return false
    end
end, MT_PLAYER)

//MACH wow!1!!!11!!
//SPIIIIIIIIIIIIIIIN
addHook("PlayerThink", function(p)
	local pmo = p.mo
	
	  if pmo.skin == "pizzano"
	  and p.speed >= 32*FRACUNIT 
	  and p.mo.state == S_PLAY_JUMP then
	  p.mo.state = S_PLAY_PZNOMACH2JUMP
	  end
end)

//SPIIIIIIIN 2.0
addHook("PlayerThink", function(p)
	local pmo = p.mo
	
	  if pmo.skin == "pizzano"
	  and p.dashmode >= 3*TICRATE 
	  and p.mo.state == S_PLAY_PZNOMACH2JUMP then
	  p.mo.state = S_PLAY_PZNOMACH3JUMP
	  end
end)


//WAHOOOOOOOOOOO WE ARE EXTREMELY FAST
addHook("PlayerThink", function(p)
	local pmo = p.mo
	
	if not ((pmo.skin == "pizzano") or (p.exiting))
		return
		    end
	if p.speed >= 60*FRACUNIT
	and not (p.pflags & PF_THOKKED)
	and not (p.pflags & PF_JUMPED)
	and p.mo.state == S_PLAY_DASH then
				p.mo.state = S_PLAY_MACH4PZNO
			end
	if p.mo.state == S_PLAY_MACH4PZNO
	   and p.speed <= 30*FRACUNIT  then
				p.mo.state = S_PLAY_STND
		end
end)

//the momentum
addHook("PlayerThink", function(player)
    if (player.cmd.forwardmove or player.cmd.sidemove)
	and ((player.mo.skin == "pizzano") or (player.exiting))
    and player.normalspeed <= player.speed then
        player.mo.friction = FRACUNIT
    else
        player.mo.friction = 29*FRACUNIT/32
    end
end)

//the mach sounds
addHook("PlayerThink", function(player)
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and ((player.mo.state == S_PLAY_DASH) or (player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_FIRE_FINISH))
		and not S_SoundPlaying(player.mo, sfx_mach3) then
		S_StartSound(player.mo, sfx_mach3)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and not ((player.mo.state == S_PLAY_DASH) or (player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_FIRE_FINISH))
		or (player.mo.state == S_PLAY_WALK)
		and S_SoundPlaying(player.mo, sfx_mach3) then
		S_StopSoundByID(player.mo, sfx_mach3)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and (player.mo.state == S_PLAY_RUN)	
		and not S_SoundPlaying(player.mo, sfx_mach2) then
		S_StartSound(player.mo, sfx_mach2)
    end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and not (player.mo.state == S_PLAY_RUN)
		or (player.mo.state == S_PLAY_WALK)
		and S_SoundPlaying(player.mo, sfx_mach2) then
		S_StopSoundByID(player.mo, sfx_mach2)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and (player.mo.state == S_PLAY_WALK)	
		and not S_SoundPlaying(player.mo, sfx_mach1) then
		S_StartSound(player.mo, sfx_mach1)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and not (player.mo.state == S_PLAY_WALK)
		and S_SoundPlaying(player.mo, sfx_mach1) then
		S_StopSoundByID(player.mo, sfx_mach1)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and ((player.mo.state == S_PLAY_MACH4PZNO))
		and not S_SoundPlaying(player.mo, sfx_mach4) then
		S_StartSound(player.mo, sfx_mach4)
	end
	    if ((player.mo.skin == "pizzano") or (player.exiting))
	    and not ((player.mo.state == S_PLAY_MACH4PZNO))
		or (player.mo.state == S_PLAY_WALK)
		and S_SoundPlaying(player.mo, sfx_mach4) then
		S_StopSoundByID(player.mo, sfx_mach4)
	end
end)

//mach 4 effects
rawset(_G, "P_CreateRing", function(p)
    
	local ring = P_SpawnMobj(p.mo.x,p.mo.y,p.mo.z,MT_THOK)
	ring.state = S_MACH4RING
	ring.fuse = 999
	ring.tics = 20
	ring.angle = p.drawangle+ANGLE_90
	ring.scale = p.mo.scale-FRACUNIT/2
	ring.destscale = p.mo.scale*2
	ring.colorized = true
	ring.color = SKINCOLOR_WHITE
	if (p.mo.eflags & MFE_VERTICALFLIP)
		ring.flags2 = $|MF2_OBJECTFLIP
		ring.eflags = $|MFE_VERTICALFLIP
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		local mo = player.mo
		if P_IsObjectOnGround(mo)
		and ((player.mo.skin == "pizzano") or (player.exiting))
		and mo.state == S_PLAY_MACH4PZNO
		and leveltime%10 == 0
			for i = -1, 1, 2
				local ang = i * ANG10
				local factor = FixedMul(4*mo.scale, cos(ang))
				local x = P_ReturnThrustX(mo, player.drawangle + ANGLE_180 + ang, 24*mo.scale)
				local y = P_ReturnThrustY(mo, player.drawangle + ANGLE_180 + ang, 24*mo.scale)
				local dust = P_SpawnMobjFromMobj(mo, x, y, 0, MT_THOK)
				dust.scale = mo.scale
				dust.angle = R_PointToAngle2(dust.x, dust.y, mo.x, mo.y)
				dust.state = S_MACH4_FIRE
				dust.momx = FixedMul(factor, cos(dust.angle - i*ANGLE_90))
				dust.momy = FixedMul(factor, sin(dust.angle - i*ANGLE_90))
			end
		end
	end
end)

addHook("ThinkFrame", do
	for p in players.iterate
		if ((p.mo.skin == "pizzano") or (p.exiting))
		and ((p.mo.state == S_PLAY_MACH4PZNO))
		and leveltime%5 == 0
			P_CreateRing(p)
		end
	end
end)

//crounch and dive
//crounch
addHook("PlayerThink", function(player)
    if player.mo.skin ~= "pizzano"
        return
    end

    if (player.cmd.buttons & BT_CUSTOM1) and P_IsObjectOnGround(player.mo) and player.speed <= 30*FRACUNIT  then
        player.height = 30*FRACUNIT
		player.mo.state = S_PLAY_CROUNCH
        player.pflags = $|PF_FULLSTASIS
    else
        player.height = 58*FRACUNIT
    end
end)

//slide
addHook("PlayerThink", function(player)
    if player.mo.skin ~= "pizzano"
        return
    end

    if (player.cmd.buttons & BT_CUSTOM1) and P_IsObjectOnGround(player.mo) and player.speed >= 30*FRACUNIT 
	and not ((player.mo.state == S_PLAY_KUNGFU1)
	or (player.mo.state == S_PLAY_KUNGFU2)
	or (player.mo.state == S_PLAY_KUNGFU3)
	or (player.mo.state == S_PLAY_KUNGFU4)
	or (player.mo.state == S_PLAY_KUNGFU5)
	or (player.mo.state == S_PLAY_CHAINSAW)
	or (player.mo.state == S_PLAY_KUNGFU6)
	or (player.mo.state == S_PLAY_AIRKUNGFU1)
	or (player.mo.state == S_PLAY_AIRKUNGFU2)) then
        player.height = 30*FRACUNIT
		player.mo.state = S_PLAY_SLIDE
		player.pflags = $|PF_JUMPSTASIS
    else
        player.height = 58*FRACUNIT
    end
end)

addHook("PlayerThink", function(player)
    if player.mo.skin ~= "pizzano"
        return
    end

    if not (player.cmd.buttons & BT_CUSTOM1) and P_IsObjectOnGround(player.mo) and player.speed >= 30*FRACUNIT and player.mo.state == S_PLAY_SLIDE then
		player.mo.state = S_PLAY_STND
		end
end)

//"dive"
addHook("PlayerThink", function(player)
    if player.mo.skin ~= "pizzano"
        return
    end
	
      if (player.cmd.buttons & BT_CUSTOM1) 
		and player.speed >= 32*FRACUNIT
		and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_PZNOMACH2JUMP then
					P_SetObjectMomZ(player.realmo, -17*FRACUNIT, false)
					player.mo.state = S_PLAY_PZNOMACH2JUMPDIVE
					end
	 if (player.cmd.buttons & BT_CUSTOM1) 
		and player.speed >= 32*FRACUNIT
		and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_PZNOMACH3JUMP then
					P_SetObjectMomZ(player.realmo, -23*FRACUNIT, false)
					player.mo.state = S_PLAY_PZNOMACH3JUMPDIVE
					end
	 if (player.cmd.buttons & BT_CUSTOM1) 
		and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_SLIDE then
					P_SetObjectMomZ(player.realmo, -20*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					end
	 if (player.cmd.buttons & BT_CUSTOM1) 
		and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_RUN then
					P_SetObjectMomZ(player.realmo, -20*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					end
	 if (player.cmd.buttons & BT_CUSTOM1) 
		and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_DASH then
					P_SetObjectMomZ(player.realmo, -24*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					end
	 if (player.cmd.buttons & BT_CUSTOM1) 
	 	and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_MACH4PZNO then
					P_SetObjectMomZ(player.realmo, -28*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					end
end)

//YOOOOOOOOOO jump animation!
addHook("PlayerThink", do
	    for player in players.iterate do
		if ((player.mo.skin == "pizzano") or (player.exiting))
		and player.mo.state == S_PLAY_JUMP then 
			player.mo.state = S_PLAY_JUMPINITIAL
		end
	end
end)

// PANIC!!!
addHook("PlayerThink", function(p)
      local pmo = p.mo

  if not ((pmo.skin == "pizzano") or (p.exiting))
		return
		end
  if p.mo.state == S_PLAY_STND
	and (PTSR and PTSR.pizzatime) then
				p.mo.state = S_PLAY_PANIC
				end 
				
  if ((p.mo.state == S_PLAY_PANIC))
	   and p.speed >= 1*FRACUNIT then
				p.mo.state = S_PLAY_STND
	end
end)

//double jump animation
addHook("PlayerThink", do
	    for player in players.iterate do
		if player.mo and player.mo.skin == "pizzano"
		and player.cmd.buttons & BT_JUMP
		and not ((player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE) or (player.mo.state == S_PLAY_SUPERJUMP_SIDE) or (player.mo.state == S_PLAY_BODYSLAM_INITIAL) or (player.mo.state == S_PLAY_BODYSLAMLAND) or (player.mo.state == S_PLAY_BODYSLAM_FINAL) or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE) or (player.mo.state == S_PLAY_ROLL) or (player.mo.state == S_PLAY_AIRKUNGFU1) or (player.mo.state == S_PLAY_AIRKUNGFU2))
		and not P_IsObjectOnGround(player.mo)
		and player.charability == CA_DOUBLEJUMP
		and not player.pstomp == true
		and (player.pflags & PF_THOKKED) then 
			player.mo.state = S_PLAY_ROLL
		end
	end
end)

//he likes the blue licore
addHook("MusicChange", function(oldmus, newmus)
	if not consoleplayer
	or skins[consoleplayer.skin].name ~= "pizzano" return end
	
	local new = string.upper(newmus)
	local old = string.upper(oldmus)
	
	local mustable = {
		["PIZTIM"] = "LP1NO",
		["DEAOLI"] = "LP2NO",
		["PIJORE"] = "LP3NO",
		["GLUWAY"] = "LP4NO"
	}
	
	if mustable[new]
		if mustable[new] ~= old
			return mustable[new]
		else
			return true
		end
	end
end)

//dance (SUS)
addHook("PlayerThink", function(player)
    if player.mo.skin ~= "pizzano"
        return
    end

    if (player.cmd.buttons & BT_FIRENORMAL) and P_IsObjectOnGround(player.mo) 
	and player.speed <= 17*FRACUNIT then
		player.mo.state = S_PLAY_DANCE
        player.pflags = $1|PF_JUMPSTASIS
    end
end)

//taunts
addHook("ThinkFrame", function()
        for player in players.iterate do
        if ((player.mo.skin == "pizzano") or (player.exiting)) and (player.cmd.buttons & BT_TOSSFLAG) and not ((player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_FIRE_FINISH) or (player.mo.state == S_PLAY_ROLL) or (player.mo.state == S_PLAY_AIRKUNGFU1) or (player.mo.state == S_PLAY_BODYSLAMLAND) or (player.mo.state == S_PLAY_BODYSLAM_FINAL) or (player.mo.state == S_PLAY_BODYSLAM_INITIAL) or (player.mo.state == S_PLAY_SUPERJUMP_RELEASE) or (player.mo.state == S_PLAY_SUPERJUMP_PREPARESIDE) or (player.mo.state == S_PLAY_SUPERJUMP_PREPARE) or (player.mo.state == S_PLAY_SUPERJUMP_SIDE) or (player.mo.state == S_PLAY_AIRKUNGFU2))
				if player.tossdelay == 0
					player.randomtaunt = P_RandomRange(1, 9)
					if player.randomtaunt == 1
						player.mo.state = S_PLAY_TAUNT1
						S_StartSound(player.mo, sfx_tant1)
						player.tossdelay = 20
					elseif player.randomtaunt == 2
						player.mo.state = S_PLAY_TAUNT2
						S_StartSound(player.mo, sfx_tant2)
						player.tossdelay = 20
					elseif player.randomtaunt == 3
						player.mo.state = S_PLAY_TAUNT3
						S_StartSound(player.mo, sfx_tant3)
						player.tossdelay = 20
					elseif player.randomtaunt == 4
						player.mo.state = S_PLAY_TAUNT4
						S_StartSound(player.mo, sfx_chadt)
						player.tossdelay = 20
					elseif player.randomtaunt == 5
						player.mo.state = S_PLAY_TAUNT5
						S_StartSound(player.mo, sfx_tant4)
						player.tossdelay = 20
					elseif player.randomtaunt == 6
						player.mo.state = S_PLAY_TAUNT6
						S_StartSound(player.mo, sfx_tant5)
						player.tossdelay = 20
					elseif player.randomtaunt == 7
						player.mo.state = S_PLAY_TAUNT7
						S_StartSound(player.mo, sfx_tant6)
						player.tossdelay = 20
					elseif player.randomtaunt == 8
						player.mo.state = S_PLAY_TAUNT8
						S_StartSound(player.mo, sfx_tant7)
						player.tossdelay = 20
					elseif player.randomtaunt == 9
						player.mo.state = S_PLAY_TAUNT9
						S_StartSound(player.mo, sfx_tant8)
						player.tossdelay = 20
				end
			end
		end
	end
end)
					

//fly
addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and player.dashmode >= 3*TICRATE
and player.charability == CA_DOUBLEJUMP 
and not ((player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE) or (player.mo.state == S_PLAY_SUPERJUMP_SIDE) or (player.mo.state == S_PLAY_BODYSLAM_INITIAL) or (player.mo.state == S_PLAY_BODYSLAMLAND) or (player.mo.state == S_PLAY_BODYSLAM_FINAL) or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE) or (player.mo.state == S_PLAY_ROLL) or (player.mo.state == S_PLAY_AIRKUNGFU1) or (player.mo.state == S_PLAY_AIRKUNGFU2))
and not P_IsObjectOnGround(player.mo) then
   player.charability = CA_FLOAT
     end

if player.mo and player.mo.skin == "pizzano"
and not P_IsObjectOnGround(player.mo)
and player.speed <= 36*FRACUNIT 
and not ((player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE) or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE))
and player.charability == CA_FLOAT then
   player.charability = CA_DOUBLEJUMP
     end
 end)

addHook("PlayerThink", do
	    for player in players.iterate do
		if player.mo and player.mo.skin == "pizzano"
		and player.cmd.buttons & BT_JUMP
		and not P_IsObjectOnGround(player.mo)
		and not ((player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE) or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE) or (player.mo.state == S_PLAY_FALL))
		and player.charability == CA_FLOAT
		and (player.pflags & PF_THOKKED) then 
			player.mo.state = S_PLAY_FIRE
		end
	end
end)

 addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and ((player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_FIRE_FINISH))
and (player.cmd.buttons & BT_CUSTOM3) then
   P_SetObjectMomZ(player.realmo, 7*FRACUNIT, false)
end
end)

addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and ((player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_FIRE_FINISH))
and not (player.mo.eflags & MFE_UNDERWATER)
and (player.cmd.buttons & BT_CUSTOM2) then
   P_SetObjectMomZ(player.realmo, -7*FRACUNIT, false)
end
end)

//SUPER JUMP: this is perfect -Pizzano
 addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and player.dashmode >= 3*TICRATE 
and (player.cmd.buttons & BT_CUSTOM3) 
and not ((player.mo.state == S_PLAY_FALL) or (player.mo.state == S_PLAY_SUPERJUMP_SIDE) or (player.mo.state == S_PLAY_FIRE_FINISH)  or (player.mo.state == S_PLAY_ROLL) or (player.mo.state == S_PLAY_FIRE)) then
   player.mo.state = S_PLAY_SUPERJUMP_PREPARE
   P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
   P_Thrust(player.mo, player.mo.angle, 0*FRACUNIT)
   P_SetObjectMomZ(player.realmo, 0*FRACUNIT, false)
end
end)


 addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano" 
and player.mo.state == S_PLAY_SUPERJUMP_PREPARE then
   player.pflags = $|PF_FULLSTASIS
   P_SetObjectMomZ(player.realmo, 0*FRACUNIT, false)
end
end)

 addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano" 
and player.mo.state == S_PLAY_SUPERJUMP_RELEASE then
   P_SetObjectMomZ(player.realmo, 45*FRACUNIT, false)
end
end) 

rawset(_G, "CheckCel", function(player, dist)
	local cel = player.mo.ceilingz
	local celcheck = player.mo.z >= (cel - (player.mo.height+dist))
	if P_MobjFlip(player.mo) == 1
		cel = player.mo.ceilingz
		celcheck = player.mo.z >= (cel - (player.mo.height+dist))
	else
		cel = player.mo.floorz
		celcheck = player.mo.z+player.mo.height <= (cel + (player.mo.height+dist))
	end
	if celcheck
		return true
	else
		return false
	end
end)

addHook("PlayerThink", function(p)
	if p.celhit == nil
		p.celhit = false
	end
	if p.mo.state == S_PLAY_SUPERJUMP_RELEASE
	and CheckCel(p, FRACUNIT)
		p.celhit = true
		p.mo.state = S_PLAY_FALL
	end
end)

 addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano" 
and player.mo.state == S_PLAY_SUPERJUMP_RELEASE
and (player.cmd.buttons & BT_SPIN) then
   P_SetObjectMomZ(player.realmo, 0*FRACUNIT, false)
   P_Thrust(player.mo, player.mo.angle, 11*FRACUNIT)
   player.mo.state = S_PLAY_SUPERJUMP_PREPARESIDE
end
end) 

 addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano" 
and player.mo.state == S_PLAY_SUPERJUMP_SIDE then
   P_SetObjectMomZ(player.realmo, 0*FRACUNIT, false)
   P_InstaThrust(player.mo, player.mo.angle, 23*FRACUNIT)
   P_Thrust(player.mo, player.mo.angle, 23*FRACUNIT)
end
end) 


 addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and player.mo.state == S_PLAY_SUPERJUMP_SIDE
and (player.cmd.buttons & BT_CUSTOM3) then
   P_SetObjectMomZ(player.realmo, 7*FRACUNIT, false)
end
end)

 addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and player.mo.state == S_PLAY_SUPERJUMP_SIDE
and (player.cmd.buttons & BT_JUMP) then
   P_SetObjectMomZ(player.realmo, 10*FRACUNIT, false)
   player.mo.state = S_PLAY_PZNOMACH3JUMP
end
end)

addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and player.mo.state == S_PLAY_SUPERJUMP_SIDE
and (player.cmd.buttons & BT_CUSTOM2) then
   P_SetObjectMomZ(player.realmo, -7*FRACUNIT, false)
end
end)

addHook("PlayerThink",function(player)
if player.mo and player.mo.skin == "pizzano"
and player.mo.state == S_PLAY_SUPERJUMP_SIDE
and (player.cmd.buttons & BT_SPIN) then
    player.pstomp = true
	P_Thrust(player.mo,player.mo.angle, -30*FU)
	player.mo.state = S_PLAY_BODYSLAM_INITIAL
end
end)

//after images B)
freeslot("SKINCOLOR_AFTERIMAGEPINK","SKINCOLOR_AFTERIMAGECYAN")

skincolors[SKINCOLOR_AFTERIMAGEPINK] = {
    name = "After Image Pink",
    ramp = {202,202,202,202,202,202,202,202,202,202,202,204,204,204,204,204},
    invcolor = SKINCOLOR_AFTERIMAGECYAN,
    invshade = 9,
    chatcolor = V_REDMAP,
    accessible = false
}

skincolors[SKINCOLOR_AFTERIMAGECYAN] = {
    name = "After Image Cyan",
    ramp = {134,134,134,134,134,134,134,134,134,134,134,136,136,136,136,136},
    invcolor = SKINCOLOR_AFTERIMAGEPINK,
    invshade = 9,
    chatcolor = V_BLUEMAP,
    accessible = false
}

local function createafterimage(p)
	local afti = P_SpawnGhostMobj(p.mo)
	afti.colorized = true
	afti.fuse = 9999
	afti.tics = 6
	afti.frame = TR_TRANS10|p.mo.frame|FF_FULLBRIGHT
	afti.color = P_RandomRange(SKINCOLOR_AFTERIMAGECYAN,SKINCOLOR_AFTERIMAGEPINK)
	afti.scale = p.mo.scale
	afti.angle = p.drawangle
	return afti
end

local function Ghost(p)
	local afti = P_SpawnGhostMobj(p.mo)
	// afti.colorized = true
	afti.fuse = 8
	afti.tics = 8
	afti.color = p.mo.color
	afti.frame = TR_TRANS30|p.mo.frame
	afti.angle = p.drawangle
	afti.scale = p.mo.scale
	return afti
end

local function momz(p)
	if not (p.mo.eflags & MFE_VERTICALFLIP)
	and p.mo.momz < 0
	or (p.mo.eflags & MFE_VERTICALFLIP)
	and p.mo.momz > 0
		return true
	else
		return false
	end
end

addHook("PlayerThink", function(player)
	if player.playerstate == PST_DEAD return end
	
	if  player.mo and player.mo.skin == "pizzano"
	and leveltime%5 == 0
	and ((player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE) or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE) or (player.mo.state == S_PLAY_SUPERJUMP_RELEASE) or (player.mo.state == S_PLAY_DASH) or (player.mo.state == S_PLAY_MACH4PZNO)
	or (player.mo.state == S_PLAY_SUPERJUMP_SIDE)
	or (player.mo.state == S_PLAY_KUNGFU1) or (player.mo.state == S_PLAY_KUNGFU2) or (player.mo.state == S_PLAY_KUNGFU3) or (player.mo.state == S_PLAY_KUNGFU4) or (player.mo.state == S_PLAY_KUNGFU5) or (player.mo.state == S_PLAY_BODYSLAM_FINAL) or (player.mo.state == S_PLAY_KUNGFU6) or (player.mo.state == S_PLAY_RUN) or (player.mo.state == S_PLAY_PZNOMACH3JUMP) or (player.mo.state == S_PLAY_PZNOMACH2JUMP)
	or (player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_FIRE_FINISH) or (player.mo.state == S_PLAY_AIRKUNGFU1) or (player.mo.state == S_PLAY_AIRKUNGFU2))
		createafterimage(player)
	end
end)

addHook("PlayerThink", function(player)
	if player.playerstate == PST_DEAD return end
	
	if  player.mo and player.mo.skin == "pizzano"
	and not (leveltime % 4)
	and ((player.mo.state == S_PLAY_SLIDE) or (player.mo.state == S_PLAY_DIVE) or (player.mo.state == S_PLAY_CHAINSAW)) then
	     Ghost(player)
end
end)

//"wall check" of the superjump
addHook("PlayerThink", function(p)
		if  p.mo and p.mo.skin == "pizzano"
		and p.speed <= 10*FRACUNIT
	    and p.mo.state == S_PLAY_SUPERJUMP_SIDE then
  p.mo.state = S_PLAY_FALL
	end
end)

//chainsaw(idk)
addHook("PlayerThink", function(player)
		if  player.mo and player.mo.skin == "pizzano"
        and player.speed <= 57*FRACUNIT
		and P_IsObjectOnGround(player.mo)
		and (player.cmd.buttons & BT_CUSTOM2)
		and ((player.mo.state == S_PLAY_KUNGFU1) or (player.mo.state == S_PLAY_KUNGFU2) or (player.mo.state == S_PLAY_KUNGFU3) or (player.mo.state == S_PLAY_KUNGFU4) or (player.mo.state == S_PLAY_KUNGFU5) or (player.mo.state == S_PLAY_KUNGFU6))
			player.mo.state = S_PLAY_CHAINSAW
			S_StartSound(player.mo, sfx_chain)
			P_Thrust(player.mo, player.mo.angle, 20*FRACUNIT)
		end
end)

addHook("PlayerThink", function(player)
		if  player.mo and player.mo.skin == "pizzano"
        and player.speed >= 50*FRACUNIT
		and P_IsObjectOnGround(player.mo)
		and (player.cmd.buttons & BT_CUSTOM2)
		and ((player.mo.state == S_PLAY_KUNGFU1) or (player.mo.state == S_PLAY_KUNGFU2) or (player.mo.state == S_PLAY_KUNGFU3) or (player.mo.state == S_PLAY_KUNGFU4) or (player.mo.state == S_PLAY_KUNGFU5) or (player.mo.state == S_PLAY_KUNGFU6))
			player.mo.state = S_PLAY_CHAINSAW
			P_Thrust(player.mo, player.mo.angle, 4*FRACUNIT)
			S_StartSound(player.mo, sfx_chain)
		end
end)

//ded
addHook ("PlayerThink",function(player)
if player.mo.skin == "pizzano"
and player.mo.state == S_PLAY_DEAD
and player.playerstate == PST_DEAD
and not P_CheckDeathPitCollide(player.mo,true)
and P_IsObjectOnGround(player.mo) then
 
 player.mo.state = S_PLAY_DEDXD
 player.mo.flags = $ & ~MF_NOCLIPHEIGHT
 player.mo.flags = $ & ~MF_NOGRAVITY
 player.mo.flags2 = $ & ~MF2_DONTDRAW
 P_StartQuake(FRACUNIT*5, TICRATE/8*1)
 S_StartSound(player.mo, sfx_slfnl)
 P_Thrust(player.mo, player.mo.angle, 0*FRACUNIT)
end
end)

//super taunt :0
addHook ("PlayerThink",function(player)
if player.mo.skin == "pizzano"
and ((player.powers[pw_shield] == SH_ARMAGEDDON) or (player.powers[pw_shield] == SH_THUNDERCOIN) or (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_ELEMENTAL))
and (player.cmd.buttons & BT_CUSTOM2)
and not ((player.mo.state == S_PLAY_BODYSLAMLAND) or (player.mo.state == S_PLAY_FIRE_FINISH) or (player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_SUPERJUMP_PREPARE) or (player.mo.state == S_PLAY_SUPERJUMP_RELEASE) or (player.mo.state == S_PLAY_SUPERJUMP_PREPARESIDE) or (player.mo.state == S_PLAY_SUPERJUMP_SIDE) or (player.mo.state == S_PLAY_SUPERTAUNT_3) or (player.mo.state == S_PLAY_SUPERTAUNT_2) or (player.mo.state == S_PLAY_SUPERTAUNT_1) or (player.mo.state == S_PLAY_BODYSLAM_FINAL) or (player.mo.state == S_PLAY_BODYSLAM_INITIAL)) then
 
S_StartSound(player.mo, sfx_sptnt)
P_NukeEnemies(player.mo, player.mo, 2700*FRACUNIT)
player.powers[pw_shield] = SH_NONE
player.mo.state = P_RandomRange(S_PLAY_SUPERTAUNT_1, S_PLAY_SUPERTAUNT_2, S_PLAY_SUPERTAUNT_3)
end
end)

addHook ("PlayerThink",function(player)
if player.mo.skin == "pizzano"
and ((player.mo.state == S_PLAY_SUPERTAUNT_1)
or (player.mo.state == S_PLAY_SUPERTAUNT_2)
or (player.mo.state == S_PLAY_SUPERTAUNT_3)) then
P_StartQuake(FRACUNIT*50, TICRATE/4*1)
P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
P_SetObjectMomZ(player.realmo, 0*FRACUNIT, false)
end
end)

addHook ("PlayerThink",function(player)
if player.mo.skin == "pizzano"
and player.speeddash == true then
player.mo.state = S_PLAY_DASH
end
end)