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)

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)

addHook("PlayerThink", function(p)
	local pmo = p.mo
	
	if not pmo.skin == "pizzano"
		return
		    end
	if p.speed >= 60*FRACUNIT
	and not (p.pflags & PF_THOKKED)
	and not (p.pflags & PF_JUMPED)
	and p.dashmode >= 3*TICRATE then
				p.mo.state = S_PLAY_FLY
			end
	if p.mo.state == S_PLAY_FLY
	   and p.speed <= 50*FRACUNIT then
				p.mo.state = S_PLAY_STND
		end
end)

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

addHook("ThinkFrame", function()
    for player in players.iterate do
        if player.mo.skin == "pizzano"
			if ((player.mo.state == S_PLAY_MELEE_FINISH) or (player.mo.state == S_PLAY_MELEE) or (player.mo.state == S_PLAY_MELEE_LANDING))
			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)

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_KUNGFU6
		return true
	end
end)

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 then
	player.powers[pw_strong] = STR_HEAVY|STR_SPRING|STR_SPIKE|STR_ANIM
	end
end)

addHook("PlayerThink", function(player)
	    if player.mo.skin == "pizzano"
	    and (player.mo.state == S_PLAY_DASH)	
		and not S_SoundPlaying(player.mo, sfx_mach3) then
		S_StartSound(player.mo, sfx_mach3)
	end
	    if player.mo.skin == "pizzano"
	    and not (player.mo.state == S_PLAY_DASH)
		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"
	    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"
	    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"
	    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"
	    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"
	    and (player.mo.state == S_PLAY_FLY)	
		and not S_SoundPlaying(player.mo, sfx_mach4) then
		S_StartSound(player.mo, sfx_mach4)
	end
	    if player.mo.skin == "pizzano"
	    and not (player.mo.state == S_PLAY_FLY)
		or (player.mo.state == S_PLAY_WALK)
		and S_SoundPlaying(player.mo, sfx_mach4) then
		S_StopSoundByID(player.mo, sfx_mach4)
	end
end)

addHook("PlayerThink", do
	    for player in players.iterate do
		if player.mo.skin == "pizzano"
		and player.mo.state == S_PLAY_JUMP then 
			player.mo.state = S_PLAY_JUMPINITIAL
		end
	end
end)

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

  if not pmo.skin == "pizzano"
		return
		end
  if p.mo.state == S_PLAY_STND
	and (PTSR and PTSR.pizzatime)
		or (PizzaTime and PizzaTime.sync and PizzaTime.sync.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)

addHook("PlayerThink", do
	    for player in players.iterate do
		if player.mo and player.mo.skin == "pizzano"
		and not player.powers [pw_shield]
		and player.cmd.buttons & BT_JUMP
		and not P_IsObjectOnGround(player.mo)
		and (player.pflags & PF_THOKKED) then 
			player.mo.state = S_PLAY_ROLL
		end
	end
end)

addHook("ThinkFrame", function()
    for player in players.iterate do
        if player.mo.skin == "pizzano" and (player.cmd.buttons & BT_TOSSFLAG)
				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_taunt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
					elseif player.randomtaunt == 2
						player.mo.state = S_PLAY_TAUNT2
						S_StartSound(player.mo, sfx_taunt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
					elseif player.randomtaunt == 3
						player.mo.state = S_PLAY_TAUNT3
						S_StartSound(player.mo, sfx_taunt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
					elseif player.randomtaunt == 4
						player.mo.state = S_PLAY_TAUNT4
						S_StartSound(player.mo, sfx_chadt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
					elseif player.randomtaunt == 5
						player.mo.state = S_PLAY_TAUNT5
						S_StartSound(player.mo, sfx_taunt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
					elseif player.randomtaunt == 6
						player.mo.state = S_PLAY_TAUNT6
						S_StartSound(player.mo, sfx_taunt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
					elseif player.randomtaunt == 7
						player.mo.state = S_PLAY_TAUNT7
						S_StartSound(player.mo, sfx_taunt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
					elseif player.randomtaunt == 8
						player.mo.state = S_PLAY_TAUNT8
						S_StartSound(player.mo, sfx_taunt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
					elseif player.randomtaunt == 9
						player.mo.state = S_PLAY_TAUNT9
						S_StartSound(player.mo, sfx_taunt)
						player.powers[pw_invulnerability] = 5
						player.tossdelay = 15
				end
			end
		end
	end
end)

addHook("MusicChange", function(oldname, newname, mflags, looping, position, prefadems, fadeinms)
	if splitscreen
		return
	end
	if not (consoleplayer and consoleplayer.valid)
		return
		end
	local snikmus = skins[consoleplayer.skin].name
	if snikmus == "pizzano"
		if newname == "PIZTIM"
			newname = "LP1NO"
		elseif newname == "DEAOLI"
			newname = "LP2NO"
		elseif newname == "PIJORE" or newname == "LAP3LO"
			newname = "LP3NO"
		elseif newname == "GLUWAY"
			newname = "LP4NO"
		elseif newname == "EXTREM"
			newname = "LP4NO"
		end
		return newname, mflags, looping, position, prefadems, fadeinms
	end
end)