//pizzano checking bc yes
addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid
	and (player.mo.skin == "pizzano")
		player.pizzanoreal = true
	else
		player.pizzanoreal = false
	end
end)

//damage
addHook("PlayerCanDamage", function(player,target)
	 if player.pizzanoreal
 	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)
	or (player.mo.state == S_PLAY_PZNO_REDIRECT)
	or (player.mo.state == S_PLAY_MACH4PZNO)
	or (player.mo.state == S_PLAY_DASH)
	or (player.mo.state == S_PLAY_MACH3_PAD)
	or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE)
	or (player.mo.state == S_PLAY_PZNOMACH3JUMP)
	or (player.mo.state == S_PLAY_MACH5PZNO)
	or (player.mo.state == S_PLAY_PZNOMACH3JUMP)
	or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE))then
	player.randomscreamsound = P_RandomRange(1, 11)
	if (target.flags & MF_ENEMY)
    and not (target.flags & MF_BOSS)
	          P_StartQuake(FRACUNIT*11, TICRATE/4*2)
	                if player.randomscreamsound == 1
					S_StartSoundAtVolume(player.mo, sfx_enscr1,100)
					elseif player.randomscreamsound == 2
					S_StartSoundAtVolume(player.mo, sfx_enscr2,100)
					elseif player.randomscreamsound == 3
					S_StartSoundAtVolume(player.mo, sfx_enscr3,255)
					elseif player.randomscreamsound == 4
					S_StartSoundAtVolume(player.mo, sfx_enscr4,255)
					elseif player.randomscreamsound == 5
					S_StartSoundAtVolume(player.mo, sfx_enscr5,255)
					elseif player.randomscreamsound == 6
					S_StartSoundAtVolume(player.mo, sfx_enscr6,255)
					elseif player.randomscreamsound == 7
					S_StartSoundAtVolume(player.mo, sfx_kill,255)
					elseif player.randomscreamsound == 8
					S_StartSoundAtVolume(player.mo, sfx_kill,255)
					elseif player.randomscreamsound == 9
					S_StartSoundAtVolume(player.mo, sfx_kill,255)
					elseif player.randomscreamsound == 10
					S_StartSoundAtVolume(player.mo, sfx_kill,255)
					elseif player.randomscreamsound == 11
					S_StartSoundAtVolume(player.mo, sfx_kill,255)
				end
			end
	return true
	end
	if player.pizzanoreal
 	and ((player.mo.state == S_PLAY_FALL)
	or (player.mo.state == S_PLAY_PARRY1)
	or (player.mo.state == S_PLAY_PARRY)
	or (player.mo.state == S_PLAY_PARRY2))
	return true
	end
end)

//kungfu strongs and checks
addHook("PlayerThink", function(player)
	 if player.pizzanoreal
 	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_SPRING|STR_ANIM|STR_WALL|STR_SPIKE
	player.DoingKungfu = true
	else
	player.DoingKungfu = false
	end
end)

//machrun by me YAY!
addHook("ThinkFrame", do
    for player in players.iterate
        if player.pizzanoreal
                if (player.cmd.buttons & BT_SPIN)
				and P_IsObjectOnGround(player.mo)
				and player.machxdtimerr <= 160
				
				or ((player.mo.state == S_PLAY_FIRE)
				or (player.mo.state == S_PLAY_SUPERJUMP_SIDE)
				or (player.mo.state == S_PLAY_FIRE_FINISH))
				and player.machxdtimerr <= 160
				and not (player.mo.state == S_PLAY_SLIDE) then
					player.machxdtimerr = $+2
					player.machrunningcheck = true
					end
				if (player.cmd.buttons & BT_SPIN)
				and player.machxdtimerr >= 161
				and P_IsObjectOnGround(player.mo)
				
				or ((player.mo.state == S_PLAY_FIRE)
				or (player.mo.state == S_PLAY_SUPERJUMP_SIDE)
				or (player.mo.state == S_PLAY_FIRE_FINISH))
				and player.machxdtimerr >= 161
				and not (player.mo.state == S_PLAY_SLIDE) then
					player.machxdtimerr = $+1
					player.machrunningcheck = true
					end
					if player.mo.state == S_PLAY_WALLCLIMBB then
					player.machxdtimerr = $+3
					player.machrunningcheck = true
					end
					if (player.mo.state == S_PLAY_SLIDE) then
					player.machxdtimerr = $+0
					player.machrunningcheck = true
					end
					
					if ((player.mo.state == S_PLAY_WALLCRASSH)
					or (player.mo.state == S_PLAY_WALLCRASSH_AIR_START)
					or (player.mo.state == S_PLAY_SKID_STOP))
					
					or ((player.mo.state == S_PLAY_ROLL)
					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_KUNGFU6)
	                or (player.mo.state == S_PLAY_STND)
					or (player.mo.state == S_PLAY_WALK)
	                or (player.mo.state == S_PLAY_AIRKUNGFU1)
	                or (player.mo.state == S_PLAY_AIRKUNGFU2)
	                or (player.mo.state == S_PLAY_CHAINSAW))
					and player.speed <= 12*FRACUNIT then
					player.machxdtimerr = 0
					player.machrunningcheck = false
					end
					
					if player.machxdtimerr == 0 then
					player.normalspeed = FRACUNIT*20
					end
					
					if player.machxdtimerr >= 10 then
					player.normalspeed = FRACUNIT*32
					end
					
					if player.machxdtimerr >= 60
					and P_IsObjectOnGround(player.mo) then
					player.normalspeed = FRACUNIT*38
					end
					
					if player.machxdtimerr >= 160
					and P_IsObjectOnGround(player.mo) then
					player.normalspeed = FRACUNIT*55
					end
					
					if player.machxdtimerr >= 350
					and P_IsObjectOnGround(player.mo) then
					player.normalspeed = FRACUNIT*75
					end
					//MACH 5 :SKULL:
					if player.machxdtimerr >= 900
					and P_IsObjectOnGround(player.mo) then
					player.normalspeed = FRACUNIT*100
					end
					if (player.cmd.buttons & BT_SPIN)
			        and P_IsObjectOnGround(player.mo) 
					and not ((player.mo.state == S_PLAY_DASH)
					or (player.mo.state == S_PLAY_SKID_STOP)
					or (player.mo.state == S_PLAY_SKID)
					or (player.mo.state == S_PLAY_PARRY2) 
					or (player.mo.state == S_PLAY_PARRY)
					or (player.mo.state == S_PLAY_TAUNT1)
					or (player.mo.state == S_PLAY_TAUNT2)
					or (player.mo.state == S_PLAY_TAUNT3)
					or (player.mo.state == S_PLAY_TAUNT4)
					or (player.mo.state == S_PLAY_TAUNT5)
					or (player.mo.state == S_PLAY_TAUNT6)
					or (player.mo.state == S_PLAY_TAUNT7)
					or (player.mo.state == S_PLAY_TAUNT8)
					or (player.mo.state == S_PLAY_TAUNT9)
					or (player.mo.state == S_PLAY_PARRY1)
					or (player.mo.state == S_PLAY_BODYSLAMLAND)) 
					and player.DoingKungfu == false
			        and player.machxdtimerr <= 60 then
			        player.mo.state = S_PLAY_MACHC1
					end
             end
		end
end)

//all buttons timer
addHook("PlayerThink", function(p)
	if p.c1timr == nil
		p.c1timr = 0
	end
	if (p.cmd.buttons & BT_CUSTOM1)
		p.c1timr = $1+1
	else
		p.c1timr = 0
	end
end)

addHook("PlayerThink", function(p)
	if p.c2timr == nil
		p.c2timr = 0
	end
	if (p.cmd.buttons & BT_CUSTOM2)
		p.c2timr = $1+1
	else
		p.c2timr = 0
	end
end)

addHook("PlayerThink", function(p)
	if p.jmptimr == nil
		p.jmptimr = 0
	end
	if (p.cmd.buttons & BT_JUMP)
		p.jmptimr = $1+1
	else
		p.jmptimr = 0
	end
end)

addHook("PlayerThink", function(p)
	if p.c3timr == nil
		p.c3timr = 0
	end
	if (p.cmd.buttons & BT_CUSTOM3)
		p.c3timr = $1+1
	else
		p.c3timr = 0
	end
end)

//walcrash
addHook("MobjMoveBlocked", function(mo)
	if mo and mo.valid
	and mo.player and mo.player.valid
and (mo.skin == "pizzano")
and ((mo.state == S_PLAY_DASH)
or (mo.state == S_PLAY_MACH4PZNO)
or (mo.state == S_PLAY_MACH5PZNO)
or (mo.state == S_PLAY_MACH3_PAD)
or (mo.state == S_PLAY_SUPERJUMP_SIDE)
or (mo.state == S_PLAY_KUNGFU1)
or (mo.state == S_PLAY_KUNGFU2)
or (mo.state == S_PLAY_KUNGFU3)
or (mo.state == S_PLAY_KUNGFU4)
or (mo.state == S_PLAY_KUNGFU5)
or (mo.state == S_PLAY_KUNGFU6)
or (mo.state == S_PLAY_FIRE)
or (mo.state == S_PLAY_FIRE_FINISH))
and P_IsObjectOnGround(mo) 
        P_InstaThrust(mo, mo.player.cmd.angleturn << 16 + R_PointToAngle2(0, 0, mo.player.cmd.forwardmove*FRACUNIT, mo.player.cmd.sidemove*FRACUNIT), -12*FRACUNIT) 
		P_SetObjectMomZ(mo, 5*FRACUNIT, false)
		S_StartSound(mo, sfx_slfnl, 255)
		P_StartQuake(FRACUNIT*11, TICRATE/4*2)
		mo.pznoFlying = false
		mo.state = S_PLAY_WALLCRASSH
		end
end, MT_PLAYER)

//longjump
addHook("JumpSpecial", function(p)
	if p.DoingKungfu
	and P_IsObjectOnGround(p.mo)
	and not (p.pflags & PF_JUMPDOWN)
		P_SetObjectMomZ(p.mo, 13*FRACUNIT)
		S_StartSound(p.mo, sfx_jump)
		p.mo.state = S_PLAY_PZNOLONGJUMP
		p.DoingKungfu = false
		p.pflags = $|PF_JUMPED
		return true
	end
end)

//kungfu
addHook("ThinkFrame", function()
    for player in players.iterate do
        if player.pizzanoreal
		and player.c1timr == 1
		and not (player.cmd.buttons & BT_TOSSFLAG) 
			if not ((player.mo.state == S_PLAY_KUNGFU1) or (player.mo.state == S_PLAY_CROUNCH_AIR) or (player.mo.state == S_PLAY_CROUNCH_MOVE) or (player.mo.state == S_PLAY_CROUNCH) or (player.mo.state == S_PLAY_DANCE)or (player.mo.state == S_PLAY_PZNO_REDIRECT) or (player.mo.state == S_PLAY_SKID_STOP) or (player.mo.state == S_PLAY_SUPERJUMP_PREPARE) or (player.mo.state == S_PLAY_PZNO_REDIRECT) 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 not player.pznocrounch and not player.sliding
			and ((player.pznotutorial == 0) or (player.pznotutorial == nil))
			and player.machxdtimerr <= 160 and P_IsObjectOnGround(player.mo) then 
			        P_CreateRing(player)
					player.randomkungfu = P_RandomRange(1, 6)
					player.machxdtimerr = 160
					P_InstaThrust(player.mo, player.drawangle , 55*FRACUNIT) 
					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
		if not ((player.mo.state == S_PLAY_KUNGFU1) or (player.mo.state == S_PLAY_CROUNCH_AIR) or (player.mo.state == S_PLAY_CROUNCH_MOVE) or (player.mo.state == S_PLAY_CROUNCH) or (player.mo.state == S_PLAY_DANCE) or (player.mo.state == S_PLAY_SUPERJUMP_PREPARE) or (player.mo.state == S_PLAY_PZNO_REDIRECT) 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 player.machxdtimerr >= 160 and not player.pznocrounch
			and not player.sliding
			and P_IsObjectOnGround(player.mo) then 
			        P_CreateRing(player)
					player.randomkungfu = P_RandomRange(1, 6)
					P_InstaThrust(player.mo, player.drawangle, 55*FRACUNIT) 
					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)

//kungfu in mid air (don´t work same the kungfu on ground)
addHook("ThinkFrame", function()
        for player in players.iterate do
        	 if player.pizzanoreal and player.c1timr == 1
			 and not (player.cmd.buttons & BT_CUSTOM3) 
		and ((player.mo.state == S_PLAY_JUMPINITIAL) or (player.mo.state == S_PLAY_PZNO_REDIRECT) 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))
		and player.machxdtimerr <= 160
				player.randomkungfuair = P_RandomRange(1, 2)
				 P_CreateRing(player)
					if player.randomkungfuair == 1
						player.mo.state = S_PLAY_AIRKUNGFU1
                        P_Thrust(player.mo, player.drawangle, 30*FRACUNIT)
						player.machxdtimerr = 160
						S_StartSound(player.mo, sfx_kungf)
					elseif player.randomkungfuair == 2
						player.mo.state = S_PLAY_AIRKUNGFU2
						P_Thrust(player.mo, player.drawangle, 30*FRACUNIT)
						player.machxdtimerr = 160
						S_StartSound(player.mo, sfx_kungf)
			end
		end
	end
end)

addHook("ThinkFrame", function()
        for player in players.iterate do
        	 if player.pizzanoreal
			 and ((player.mo.state == S_PLAY_KUNGFU1) or (player.mo.state == S_PLAY_KUNGFU6) or (player.mo.state == S_PLAY_KUNGFU5) or (player.mo.state == S_PLAY_KUNGFU4) or (player.mo.state == S_PLAY_KUNGFU3) or (player.mo.state == S_PLAY_KUNGFU1))
             and not P_IsObjectOnGround(player.mo) then 
			 player.ranomkungfuair = P_RandomRange(1, 2)
			 if player.ranomkungfuair == 1
						player.mo.state = S_PLAY_AIRKUNGFU1
					elseif player.ranomkungfuair == 2
						player.mo.state = S_PLAY_AIRKUNGFU2
			end
	    end
    end
end)

//jumpeffect
freeslot("S_SLOWJUMPCLOUD","SPR_SJCL")
states[S_SLOWJUMPCLOUD] = {
	sprite = SPR_SJCL,
	frame = A|FF_ANIMATE,
	tics = 14,
	var1 = 7,
	var2 = 2,
}

addHook("PlayerThink", function(player)
	if player.pizzanoreal
	and player.mo.state == S_PLAY_JUMP
		local jump = P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_THOK)
		jump.state = S_SLOWJUMPCLOUD
		if (player.mo.eflags & MFE_VERTICALFLIP)
			jump.flags2 = $|MF2_OBJECTFLIP
			jump.eflags = $|MFE_VERTICALFLIP
		end
	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

addHook("PlayerThink", function(player)
	if player.playerstate == PST_DEAD return end
	
		 if player.pizzanoreal
	and leveltime%5 == 0
	and ((player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE)or (player.mo.state == S_PLAY_MACH3_PAD)
	or (player.mo.state == S_PLAY_PREVPZNOMACH3JUMP) 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_PZNOLONGJUMP) or (player.mo.state == S_PLAY_PZNOLONGJUMP_FINAL) or (player.mo.state == S_PLAY_SUPERJUMP_SIDE) or (player.mo.state == S_PLAY_MACH5PZNO)
	 or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL) or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL_FINISH) 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_MACHC1) 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)

//dash animation yay
addHook("PlayerThink", function(player)
	if player.pizzanoreal
    and ((player.mo.state == S_PLAY_MACHC1)
	or (player.mo.state == S_PLAY_WALK))
	and player.machxdtimerr >= 60 then 
	player.mo.state = S_PLAY_RUN
end
	if player.pizzanoreal
    and ((player.mo.state == S_PLAY_RUN)
	or (player.mo.state == S_PLAY_MACHC1)
	or (player.mo.state == S_PLAY_WALK))
	and player.machxdtimerr >= 160 then 
	player.mo.state = S_PLAY_DASH
end
    if player.pizzanoreal
    and ((player.mo.state == S_PLAY_RUN)
	or (player.mo.state == S_PLAY_WALK)
	or (player.mo.state == S_PLAY_MACHC1)
	or (player.mo.state == S_PLAY_DASH))
	and player.machxdtimerr >= 350 then 
	player.mo.state = S_PLAY_MACH4PZNO
end
	if player.pizzanoreal
    and ((player.mo.state == S_PLAY_RUN)
	or (player.mo.state == S_PLAY_RUN)
	or (player.mo.state == S_PLAY_WALK)
	or (player.mo.state == S_PLAY_MACHC1)
	or (player.mo.state == S_PLAY_DASH)
	or (player.mo.state == S_PLAY_MACH4PZNO))
	and player.machxdtimerr >= 900 then 
	player.mo.state = S_PLAY_MACH5PZNO
end
end)

//you can destroy spikes and walls if you are dashing
addHook("PlayerThink", function(player)
	 if player.pizzanoreal
 	and ((player.mo.state == S_PLAY_MACH4PZNO)
	or (player.mo.state == S_PLAY_DASH)
	or (player.mo.state == S_PLAY_MACH3_PAD)
	or (player.mo.state == S_PLAY_MACH5PZNO)
	or (player.mo.state == S_PLAY_PZNOMACH3JUMP)
	or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE))
		player.powers[pw_strong] = STR_SPIKE|STR_ANIM|STR_WALL
		player.charflags = $|SF_RUNONWATER
	end
end)

//YOOOOOOOOOO jump animation!
addHook("ThinkFrame", function()
     for player in players.iterate do
	 	 if player.pizzanoreal
		and ((player.mo.state == S_PLAY_JUMP)
		or (player.mo.state == S_PLAY_SPRING)) then 
			player.mo.state = S_PLAY_JUMPINITIAL
		end
	end
end)

// PANIC!!!
addHook("ThinkFrame", function()
     for player in players.iterate do
	 	 if not player.pizzanoreal
		return
		end
  if ((player.mo.state == S_PLAY_STND))
	and ((PTSR and PTSR.pizzatime)
	or (PTV3 and PTV3.pizzatime)) then
				player.mo.state = S_PLAY_PANIC
				end 
if ((player.mo.state == S_PLAY_STND))
	and ((PTSR and PTSR.pizzatime and PTSR.timeover)
	or (player.ptv3 and player.ptv3.extreme))
	and player.mo.state == S_PLAY_PANIC then
				player.mo.state = S_PLAY_PANIC_OVERTIME
		end
  if ((player.mo.state == S_PLAY_PANIC))
	   and player.speed >= 1*FRACUNIT then
				player.mo.state = S_PLAY_WALK
	end
	end
end)

//wallcling yay
addHook("MobjMoveBlocked", function(mo)
if mo and mo.valid
	    if mo.player and mo.player.valid
    	and mo.skin == "pizzano"
		and mo.player.jmptimr == 1
		and mo.player.machxdtimerr <= 10
		and not P_IsObjectOnGround(mo) 
		and ((mo.state == S_PLAY_ROLL)
		or (mo.state == S_PLAY_FALL)) then 
			mo.state = S_PLAY_WALLEDXD
		end
	end
end)

addHook("PlayerThink", function(player)
if player.wallclingtimr == nil
player.wallclingtimr = 0
end
		if player.pizzanoreal
		and (player.mo.state == S_PLAY_WALLEDXD) then 
            P_InstaThrust(player.mo, player.drawangle, 0*FRACUNIT)
		    P_SetObjectMomZ(player.realmo, 0*FRACUNIT, false)
			player.wallclingtimr = $+1
						end
		if	player.paddashidk == true
		and P_IsObjectOnGround(player.mo)
		
		or player.RedirectPad == true
		and P_IsObjectOnGround(player.mo)then 
			P_InstaThrust(player.mo, player.drawangle, 50*FRACUNIT)
			player.wallclingtimr = 0
			player.machxdtimerr = 160
			P_CreateRing(player)
			player.paddashidk = false
			player.RedirectPad = false
			player.mo.state = S_PLAY_MACH3_PAD
			S_StartSound(player.mo, sfx_turbik)
	end
end)

addHook("PlayerThink", function(player)
		if player.pizzanoreal
		and ((player.mo.state == S_PLAY_WALLEDXD_FINISH)) then 
			P_InstaThrust(player.mo, player.drawangle, 0*FRACUNIT)
			
	end
end)

addHook("PlayerThink", function(player)
		if player.pizzanoreal
		and player.wallclingtimr >= 2
		and not (player.cmd.buttons & BT_JUMP) then 
		   P_InstaThrust(player.mo, player.drawangle , player.speed*3/2)
		   P_SetObjectMomZ(player.realmo, 20*FRACUNIT, false)
		   player.paddashidk = true
		   player.wallclingtimr = 0
	end
	if	player.paddashidk == true
	and player.DoingKungfu == false
	and not P_IsObjectOnGround(player.mo) then 
	player.mo.state = S_PLAY_PREVPZNOMACH3JUMP
	player.machxdtimerr = 160
	  if player.c1timr == 1
	  player.mo.state = S_PLAY_FALL
	end
	end
end)

//double jump animation
addHook("PlayerThink", do
	    for player in players.iterate do
			 if player.pizzanoreal
		and player.cmd.buttons & BT_JUMP
		and not ((player.mo.state == S_PLAY_SUPERJUMP_RELEASE) or (player.mo.state == S_PLAY_WALLEDXD_FINISH) or (player.mo.state == S_PLAY_WALLEDXD) or (player.mo.state == S_PLAY_SKID_STOP) or (player.mo.state == S_PLAY_SUPERJUMP_PREPARESIDE) or (player.mo.state == S_PLAY_SUPERJUMP_PREPARE) or (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",
		["GFZ1"] = "POBOR",
		["DEAOLI"] = "LP2NO",
		["PIJORE"] = "LP3NO",
		["GLUWAY"] = "LP3NO",
		["PASTVI"] = "LP3NO",
		["LAP3LO"] = "LP3NO",
		["FUNFRE"] = "LP3NO"
	}
	
	if mustable[new]
		if mustable[new] ~= old
			return mustable[new]
		else
			return true
		end
	end
end)
 
 //escape candys
freeslot("S_ESCAPECANDY","S_ESCAPECANDY_COLLECT","S_ESCAPECANDY_SOUND","SPR_CNDE","sfx_colesc")
states[S_ESCAPECANDY] = {SPR_CNDE,FF_ANIMATE,-1,nil,P,3,S_ESCAPECANDY}
states[S_ESCAPECANDY_COLLECT] = {SPR_CNDE,A|FF_ANIMATE,8,nil,D,2,S_ESCAPECANDY_SOUND}
states[S_ESCAPECANDY_SOUND] = {SPR_NULL,0,16,nil,0,0,S_NULL}
sfxinfo[sfx_colesc].caption = "Candy Collect"

local function EscapeCandy(mo)
	if displayplayer.valid
	and displayplayer.mo and displayplayer.mo.valid
	and displayplayer.mo.skin == "pizzano"
	and ((PTSR and PTSR.pizzatime)
	or (PTV3 and PTV3.pizzatime))
		if mo.health
			if mo.state != S_ESCAPECANDY
				mo.state = S_ESCAPECANDY
			end
		elseif mo.state != S_ESCAPECANDY_COLLECT
		and mo.state != S_ESCAPECANDY_SOUND
			mo.state = S_ESCAPECANDY_COLLECT
		end
	else
		if mo.health
			if mo.state == S_ESCAPECANDY
				mo.state = mo.info.spawnstate
			end
		elseif mo.state == S_ESCAPECANDY_COLLECT
		or mo.state == S_ESCAPECANDY_SOUND
			mo.state = mo.info.deathstate
		end
	end
end
addHook("MobjThinker",EscapeCandy,MT_RING)
addHook("MobjThinker",EscapeCandy,MT_COIN)

local function PZNO_ReplaceFlings(mo)
	if displayplayer.valid
	and displayplayer.mo and displayplayer.mo.valid
	and ((PTSR and PTSR.pizzatime)
	or (PTV3 and PTV3.pizzatime))
	and displayplayer.mo.skin == "pizzano"
		if mo.state != S_ESCAPECANDY
		and mo.health
			mo.state = S_ESCAPECANDY
		end
	elseif mo.state == S_ESCAPECANDY
	and mo.health
		mo.state = mo.info.spawnstate
	end
end
addHook("MobjSpawn",PZNO_ReplaceFlings,MT_FLINGRING)
addHook("MobjSpawn",PZNO_ReplaceFlings,MT_FLINGCOIN)

local function PZ_CandyCollect(mo,mobj) 
	if displayplayer.valid
	and displayplayer.mo and displayplayer.mo.valid
	and ((PTSR and PTSR.pizzatime)
	or (PTV3 and PTV3.pizzatime))
	and displayplayer.mo.skin == "pizzano"
		S_StopSound(mo)
		S_StartSound(mo,sfx_colesc)
	end
end
addHook("MobjDeath",PZ_CandyCollect,MT_RING)
addHook("MobjDeath",PZ_CandyCollect,MT_COIN)
addHook("MobjDeath",PZ_CandyCollect,MT_FLINGRING)
addHook("MobjDeath",PZ_CandyCollect,MT_FLINGCOIN)

//SPIIIIIIIIIIIIIIIN
addHook("ThinkFrame", function()
     for player in players.iterate do
	  if player.pizzanoreal
	  and player.mo.state == S_PLAY_JUMPINITIAL
	  and player.machxdtimerr >= 10 then
	  player.mo.state = S_PLAY_PZNOMACH2JUMP
	  end
	  end
end)

//SPIIIIIIIN 2.0
addHook("ThinkFrame", function()
     for player in players.iterate do
	 if player.pizzanoreal
	  and player.mo.state == S_PLAY_PZNOMACH2JUMP
	  and player.machxdtimerr >= 160 then
	  player.mo.state = S_PLAY_PZNOMACH3JUMP
	  end
	 end
end)

 addHook("PlayerThink",function(player)
if player.pizzanoreal
and ((player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_SUPERJUMP_SIDE) 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.pizzanoreal
and ((player.mo.state == S_PLAY_FIRE) or (player.mo.state == S_PLAY_SUPERJUMP_SIDE) 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)

//dive
addHook("ThinkFrame", function()
     for player in players.iterate do
	 if player.pizzanoreal
	
      if player.c2timr == 1
		and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_PZNOMACH2JUMP 
		and player.machxdtimerr >= 10 then
					P_SetObjectMomZ(player.realmo, -17*FRACUNIT, false)
					player.mo.state = S_PLAY_PZNOMACH2JUMPDIVE
					player.charflags = $ & ~SF_RUNONWATER
					end
	 if player.c2timr == 1
		and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_PZNOMACH3JUMP
		and player.machxdtimerr >= 10 then
					P_SetObjectMomZ(player.realmo, -23*FRACUNIT, false)
					player.mo.state = S_PLAY_PZNOMACH3JUMPDIVE
					player.charflags = $ & ~SF_RUNONWATER
					end
	 if not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_SLIDE
		and player.machxdtimerr >= 10 then
					P_SetObjectMomZ(player.realmo, -20*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					player.charflags = $ & ~SF_RUNONWATER
					S_StartSound(player.mo, sfx_dive)
					local cloud = P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_THOK)
			        cloud.state = S_CLOUDEFFECT
					end
	 if player.c2timr == 1
		and not P_IsObjectOnGround(player.mo)
		and ((player.mo.state == S_PLAY_RUN)
		or (player.mo.state == S_PLAY_PZNOLONGJUMP_FINAL))
		and player.machxdtimerr >= 10 then
					P_SetObjectMomZ(player.realmo, -20*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					player.charflags = $ & ~SF_RUNONWATER
					S_StartSound(player.mo, sfx_dive)
					local cloud = P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_THOK)
			        cloud.state = S_CLOUDEFFECT
					end
	 if player.c2timr == 1
		and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_DASH
		and player.machxdtimerr >= 10 then
					P_SetObjectMomZ(player.realmo, -24*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					player.charflags = $ & ~SF_RUNONWATER
					S_StartSound(player.mo, sfx_dive)
					local cloud = P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_THOK)
			        cloud.state = S_CLOUDEFFECT
					end
	 if player.c2timr == 1
	 	and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_MACH4PZNO
		and player.machxdtimerr >= 10 then
					P_SetObjectMomZ(player.realmo, -28*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					player.charflags = $ & ~SF_RUNONWATER
					S_StartSound(player.mo, sfx_dive)
					local cloud = P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_THOK)
			        cloud.state = S_CLOUDEFFECT
					end
	 if player.c2timr == 1
	 	and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_MACH5PZNO
		and player.machxdtimerr >= 10 then
					P_SetObjectMomZ(player.realmo, -32*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					player.charflags = $ & ~SF_RUNONWATER
					S_StartSound(player.mo, sfx_dive)
					local cloud = P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_THOK)
			        cloud.state = S_CLOUDEFFECT
					end
	if player.c2timr == 1
	 	and not P_IsObjectOnGround(player.mo)
		and player.mo.state == S_PLAY_MACHC1
		and player.machxdtimerr >= 10 then
					P_SetObjectMomZ(player.realmo, -18*FRACUNIT, false)
					player.mo.state = S_PLAY_DIVE
					player.charflags = $ & ~SF_RUNONWATER
					S_StartSound(player.mo, sfx_dive)
					local cloud = P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_THOK)
			        cloud.state = S_CLOUDEFFECT
					end
				end
			end
end)

// Pizzano falling during a dive drop while diving. -Wiki
addHook("PlayerThink",function(player)
if player.pizzanoreal
and (player.mo.state == S_PLAY_DIVE)
and not (player.mo.eflags & MFE_UNDERWATER)
and player.jmptimr == 1 then
	player.pstomp = true
	P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
	player.mo.state = S_PLAY_BODYSLAM_INITIAL
end
end) 

//mach1
addHook("ThinkFrame", function()
     for player in players.iterate do
	 if player.pizzanoreal
and player.mo.state == S_PLAY_RUN
and player.machxdtimerr <= 60 then
 
 player.mo.state = S_PLAY_MACHC1
end
end
end)

//chainsaw
addHook("ThinkFrame", do
    for player in players.iterate
        if player.pizzanoreal
                if ((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)) then
					
					player.chainsawwtimer = $+1
					else
					player.chainsawwtimer = 0
				end
					if player.mo.state == S_PLAY_CHAINSAW then
					if player.machxdtimerr <= 290
					player.machxdtimerr = 290
					end
					player.chainsawwtimer = 0
				end
                    if player.c1timr == 1
					and player.chainsawwtimer >= 7 then
					P_InstaThrust(player.mo, player.cmd.angleturn << 16 + R_PointToAngle2(0, 0, player.cmd.forwardmove*FRACUNIT, -player.cmd.sidemove*FRACUNIT), 68*FRACUNIT)
					player.mo.state = S_PLAY_CHAINSAW
				end
			end
       end 
 end)

//ghost afterimage 
local function Ghostpzno(p)
	local afti = P_SpawnGhostMobj(p.mo)
	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

addHook("PlayerThink", function(player)
	if player.playerstate == PST_DEAD return end
	
	if player.pizzanoreal
	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
	     Ghostpzno(player)
end
end)

//ded
addHook("ThinkFrame", function()
     for player in players.iterate do
	 if player.pizzanoreal
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)
end
end
end)
 
addHook("ThinkFrame", function()
     for player in players.iterate do
	  if not player.pizzanoreal
        return
    end

    if not (player.cmd.buttons & BT_CUSTOM2) 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
end)

//pizzano doesnt uppercut, hes super jump
//SUPER JUMP: this is perfect -Pizzano
 addHook("PlayerThink",function(player)
if player.pizzanoreal
and player.c3timr == 1  
and P_IsObjectOnGround(player.mo)
and player.DoingKungfu == false
and not ((player.mo.state == S_PLAY_FALL) or (player.mo.state == S_PLAY_BODYSLAM_INITIAL) 
 or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL) or (player.mo.state == S_PLAY_PZNO_REDIRECT) or (player.mo.state == S_PLAY_BODYSLAM_FINAL) 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))
and player.machxdtimerr >= 160

or player.pizzanoreal
and (player.cmd.buttons & BT_CUSTOM3) 
and player.c1timr == 1 
and player.DoingKungfu == false
and not P_IsObjectOnGround(player.mo)
and not ((player.mo.state == S_PLAY_SUPERJUMP_SIDE)or (player.mo.state == S_PLAY_CHAINSAW)or (player.mo.state == S_PLAY_KUNGFU6)or (player.mo.state == S_PLAY_KUNGFU5)or (player.mo.state == S_PLAY_KUNGFU4)or (player.mo.state == S_PLAY_KUNGFU3)  or (player.mo.state == S_PLAY_KUNGFU2) or (player.mo.state == S_PLAY_KUNGFU1) or (player.mo.state == S_PLAY_BODYSLAM_INITIAL) 
or (player.mo.state == S_PLAY_SUPERJUMP_RELEASE) or (player.mo.state == S_PLAY_BODYSLAM_FINAL) or (player.mo.state == S_PLAY_FIRE_FINISH)  or (player.mo.state == S_PLAY_ROLL) or (player.mo.state == S_PLAY_FIRE))
   player.mo.state = S_PLAY_SUPERJUMP_PREPARE
   P_InstaThrust(player.mo, player.drawangle, 0*FRACUNIT)
   P_Thrust(player.mo, player.drawangle, 0*FRACUNIT)
   P_SetObjectMomZ(player.realmo, 0*FRACUNIT, false)
   player.machxdtimerr = 160
end
end)


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

 addHook("PlayerThink",function(player)
if player.pizzanoreal
and player.mo.state == S_PLAY_SUPERJUMP_RELEASE then
   P_SetObjectMomZ(player.realmo, 45*FRACUNIT, false)
   P_InstaThrust(player.mo, player.drawangle, 0*FRACUNIT)
  player.machxdtimerr = 160
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.pizzanoreal
	and p.mo.state == S_PLAY_SUPERJUMP_RELEASE
	and CheckCel(p, FRACUNIT)
		p.celhit = true
		p.mo.state = S_PLAY_SUPERJUMP_PLAND
		p.machxdtimerr = 0
	end
	if p.mo.state == S_PLAY_SUPERJUMP_PLAND
	P_SetObjectMomZ(p.realmo, 0*FRACUNIT, false)
    P_InstaThrust(p.mo, p.drawangle, 0*FRACUNIT)
	end
end) 

//redirect
addHook("ThinkFrame", function()
     for player in players.iterate do
	  if player.pizzanoreal
	  and player.machxdtimerr >= 160
	  and player.DoingKungfu == false
	  and ((player.mo.state == S_PLAY_SKID)
	  or (player.mo.state == S_PLAY_PZNO_REDIRECT)) then
	  player.mo.state = S_PLAY_PZNO_REDIRECT
	  player.machxdtimerr = 160
	  player.redirecttimerr = $+1
	  else
	  player.redirecttimerr = 0
				end
	 if player.pizzanoreal
	 and player.redirecttimerr >= 27
	 and P_IsObjectOnGround(player.mo)
	 
	 or player.pizzanoreal
	 and player.redirecttimerr >= 27
	 and (player.mo.state == S_PLAY_PZNO_REDIRECT)
	 and P_IsObjectOnGround(player.mo)then 
	 player.mo.state = S_PLAY_DASH
	 player.redirecttimerr = 0
	 P_InstaThrust(player.mo, player.mo.angle, 55*FRACUNIT)
	 end
	 
	if player.pizzanoreal
	 and (player.mo.state == S_PLAY_PZNO_REDIRECT)
	  and not P_IsObjectOnGround(player.mo)then 
	 player.RedirectPad = true
	 end
	 if player.pizzanoreal
	 and (player.mo.state == S_PLAY_PZNO_REDIRECT) then 
	 P_InstaThrust(player.mo, player.redirectangle, player.redirectpeed)
	              if player.redirectpeed >= 0
				  player.redirectpeed = $-2*FU
				  end
	 else
	 player.redirectpeed = player.speed
	 player.redirectangle = player.drawangle
	 end
end
end)

//random stuff for dash 
addHook("ThinkFrame", function()
     for player in players.iterate do
	 if player.pizzanoreal
	  and player.machxdtimerr >= 160
	  and player.speed <= 45*FRACUNIT
	  and not ((player.cmd.forwardmove*FRACUNIT)
	  or (player.cmd.sidemove*FRACUNIT))
	  and ((player.mo.state == S_PLAY_DASH)
	  or (player.mo.state == S_PLAY_PZNOMACH3JUMP)
	  or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE))
	  and player.wallclingtimr <= 1
	  
	  or player.pizzanoreal
	  and player.machxdtimerr >= 160
	  and player.speed <= 45*FRACUNIT
	  and ((player.mo.state == S_PLAY_DASH)
	  or (player.mo.state == S_PLAY_PZNOMACH3JUMP)
	  or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE))
	  and player.wallclingtimr <= 1 then
	  P_InstaThrust(player.mo, player.drawangle, 45*FRACUNIT)
	 end
	 if player.pizzanoreal
	  and player.machxdtimerr >= 160
	  and not ((player.cmd.forwardmove*FRACUNIT)
	  or (player.cmd.sidemove*FRACUNIT))
	  and ((player.mo.state == S_PLAY_DASH)
	  or (player.mo.state == S_PLAY_PZNOMACH3JUMP)
	  or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE))
	  and player.wallclingtimr <= 1 then
	  P_InstaThrust(player.mo, player.drawangle, 50*FRACUNIT)
	  player.machxdtimerr = 240
	 end
	 if player.pizzanoreal
	  and player.machxdtimerr >= 350
	  and not ((player.cmd.forwardmove*FRACUNIT)
	  or (player.cmd.sidemove*FRACUNIT))
	  and ((player.mo.state == S_PLAY_MACH4PZNO))
	  and player.speed <= 60*FRACUNIT then
	  player.machxdtimerr = 240
	  player.mo.state = S_PLAY_DASH
	 end
	 if player.pizzanoreal
	  and player.machxdtimerr <= 159
	  and ((player.mo.state == S_PLAY_RUN)
	  or (player.mo.state == S_PLAY_PZNOMACH2JUMP)
	  or (player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE))
	  P_InstaThrust(player.mo, player.drawangle, 39*FRACUNIT)
	 end
	 if player.pizzanoreal
	  and player.machxdtimerr <= 60
	  and ((player.mo.state == S_PLAY_MACHC1)
	  or (player.mo.state == S_PLAY_PZNOMACH2JUMP)
	  or (player.mo.state == S_PLAY_PZNOMACH2JUMPDIVE))then
	  P_InstaThrust(player.mo, player.drawangle, 32*FRACUNIT)
	 end
	 if player.pizzanoreal
	  and player.machxdtimerr >= 350
	  and (player.mo.state == S_PLAY_MACH4PZNO)
	  and ((player.cmd.forwardmove*FRACUNIT)
	  or (player.cmd.sidemove*FRACUNIT))
	  and (player.cmd.buttons & BT_SPIN)
	  and player.speed <= 65*FRACUNIT then
	  P_InstaThrust(player.mo, player.drawangle, 75*FRACUNIT)
end
end
end)

//WALLCLIMB
addHook("ThinkFrame", do
	for player in players.iterate
		if player.pizzanoreal
			
				player.atwall = 0
				local wall = R_PointInSubsector(player.mo.x+FixedMul(26*FRACUNIT, cos(player.mo.angle)), player.mo.y+FixedMul(26*FRACUNIT, sin(player.mo.angle))).sector
				local fheight = wall.floorheight
				local cheight = wall.ceilingheight
				
				if (fheight > player.mo.z) or ((cheight <= player.mo.height+player.mo.z) and not (fheight == cheight)/* and (wall.ceilingpic == "F_SKY1")*/) //This last bit seems to be broken...
					player.atwall = 1
				end
				for wall in wall.ffloors()
					if (player.mo.z <= wall.topheight) and (player.mo.height+player.mo.z > wall.bottomheight)
						and(wall.flags & FF_BLOCKPLAYER)
						player.atwall = $1 + 1	
				end
			end
		end
	end
end)

addHook("MobjMoveBlocked", function(mo)
	if mo.player and mo.player.valid
	and mo.player.pizzanoreal
	and mo.player.atwall > 0
	and not P_IsObjectOnGround(mo)
	and mo.player.wallclingtimr <= 2
	and mo.player.machxdtimerr >= 10
	    P_InstaThrust(mo.player.mo, mo.player.diveangle, mo.player.divespeed)
	    mo.player.ptwallrun = true
		else
		mo.player.divespeed = mo.player.speed
        mo.player.diveangle = mo.player.drawangle
	end
end, MT_PLAYER)

addHook("PlayerThink", function(p)
	 if p.pizzanoreal
	 and p.mo.state == S_PLAY_WALLCLIMBB
			P_SetObjectMomZ(p.realmo, 26*FRACUNIT, false)
			P_InstaThrust(p.mo, p.drawangle, 0*FRACUNIT)
	end
	 if p.pizzanoreal
	 and p.ptwallrun
	    p.mo.state = S_PLAY_WALLCLIMBB
	end
	if p.atwall == 0
	and p.ptwallrun
		p.ptwallrun = false
		p.pflags = $ & ~PF_STASIS 
		p.mo.state = S_PLAY_WALLCLIMBSPIN
		P_SetOrigin(p.mo, p.mo.x,p.mo.y,p.mo.z-p.mo.momz)
		p.wallclimspin = true
	end
	if p.ptwallrun
	and not (p.cmd.buttons & BT_USE)
	and p.wallclingtimr <= 2
	and p.mo.state == S_PLAY_WALLCLIMBB
		p.ptwallrun = false
		p.mo.state = S_PLAY_FALL
		P_InstaThrust(p.mo,p.mo.angle,-7*FRACUNIT)
		P_SetObjectMomZ(p.mo, 3*FRACUNIT)
		p.machxdtimerr = 0
	end
	if p.ptwallrun
	and CheckCel(p, FRACUNIT)
		p.celhit = true
		p.ptwallrun = false
		p.mo.state = S_PLAY_FALL
		p.machxdtimerr = 0
	end
	if p.ptwallrun
	and p.jmptimr == 1
	and p.wallclingtimr <= 2
		p.ptwallrun = false
		p.mo.state = S_PLAY_JUMP
		P_InstaThrust(p.mo,p.drawangle,-(p.normalspeed))
		p.mo.angle = R_PointToAngle2(0,0,p.mo.momx,p.mo.momy)
		P_SetObjectMomZ(p.mo, 8*FRACUNIT)
		S_StartSound(p.mo, sfx_jump)
	end
	//WALLCLIMB SPIN YEAH BOIIII
	if p.wallclimspin == true
	and not P_IsObjectOnGround(p.mo)
		p.mo.state = S_PLAY_WALLCLIMBSPIN
	end
	if P_IsObjectOnGround(p.mo)
	and p.wallclimspin == true
		p.paddashidk = true
		p.wallclimspin = false
	end
	if p.wallclimspin == true
	and p.c2timr == 1
		P_SetObjectMomZ(p.mo, -22*FRACUNIT)
	end
	if p.wallclimspin == true
	and p.c1timr == 1
		p.wallclimspin = false
		p.mo.state = S_PLAY_WALLCLIMBSPIN_CANCEL
		P_CreateRing(p)
		S_StartSound(p.mo, sfx_sjcan)
		P_SetObjectMomZ(p.mo, 5*FRACUNIT)
		P_InstaThrust(p.mo,p.drawangle, 55*FRACUNIT)
		p.machxdtimerr = 160
		
	end
end)

//skid
addHook("PlayerThink", function(player)
if player.pizzanoreal
and not (player.cmd.buttons & BT_SPIN)
and P_IsObjectOnGround(player.mo)
and ((player.mo.state == S_PLAY_MACH4PZNO)
or (player.mo.state == S_PLAY_RUN)
or (player.mo.state == S_PLAY_MACH5PZNO)
or (player.mo.state == S_PLAY_DASH)) 
or player.pizzanoreal
and not (player.cmd.buttons & BT_SPIN) 
and (player.mo.state == S_PLAY_PZNO_REDIRECT)
and P_IsObjectOnGround(player.mo)
and player.redirecttimerr >= 26 then 
player.mo.state = S_PLAY_SKID_STOP
player.machxtimerr = 0
player.redirecttimerr = 0
player.skidingidk = true
end
if player.pizzanoreal
and player.skidingidk
 player.mo.state = S_PLAY_SKID_STOP
 player.machxtimerr = 0
 P_InstaThrust(player.mo, player.skiddangle, player.skiddspeed)
    if player.skiddspeed > 0
		player.skiddspeed = $-2*FU
		else
		player.skiddspeed = $-2*FU
				end
	if (player.mo.state == S_PLAY_SKID_STOP)
	and player.skiddspeed <= 3*FRACUNIT
	player.mo.state = S_PLAY_STND
	player.skidingidk = false
end
else
player.skiddspeed = player.speed
player.skiddangle = player.drawangle
end
    if player.pizzanoreal
	and (player.mo.state == S_PLAY_MACHC1)
	and not (player.cmd.buttons & BT_SPIN)
	player.mo.state = S_PLAY_WALK
end
end)

//slide
addHook("ThinkFrame", function()
     for player in players.iterate do
	  if not player.pizzanoreal
        return
    end

    if (player.cmd.buttons & BT_CUSTOM2) and P_IsObjectOnGround(player.mo) and player.machxdtimerr >= 10
	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_MACH5PZNO)
	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.sliding = true
		else
		player.sliding = false
	end
	    if player.sliding
		player.mo.state = S_PLAY_SLIDE 
		P_InstaThrust(player.mo, player.sliddeangle, player.sliddespeed)
		player.pflags = $|PF_JUMPSTASIS
		player.charflags = $ & ~SF_RUNONWATER
    else
		player.sliddespeed = player.speed
        player.sliddeangle = player.drawangle
    end
	   if ((player.mo.state == S_PLAY_DIVE))
		P_InstaThrust(player.mo, player.diveangle, player.divespeed)
		player.charflags = $ & ~SF_RUNONWATER
    else
		player.divespeed = player.speed
        player.diveangle = player.drawangle
 
	end
	end
end)

//new crouch
addHook("ThinkFrame", function()
     for player in players.iterate do
if player.pizzanoreal
    if (player.cmd.buttons & BT_CUSTOM2) and P_IsObjectOnGround(player.mo) and player.speed <= 20*FRACUNIT
		player.pznocrounch = true
		end
	 if not (player.cmd.buttons & BT_CUSTOM2) and P_IsObjectOnGround(player.mo)
	 or not (player.cmd.buttons & BT_CUSTOM2) and P_IsObjectOnGround(player.mo) and player.pznocrounch == true
		player.pznocrounch = false
		end
	if player.pznocrounch == true
	or player.sliding == true
		player.height = 30*FRACUNIT
		player.normalspeed = 10*FRACUNIT
    else
        player.height = 58*FRACUNIT
    end
	if player.pznocrounch == true and P_IsObjectOnGround(player.mo) and player.speed <= 1*FRACUNIT and ((player.mo.state == S_PLAY_CROUNCH_MOVE) or (player.mo.state == S_PLAY_STND))
	or player.pznocrounch == true and P_IsObjectOnGround(player.mo) and player.speed <= 20*FRACUNIT and player.mo.state == S_PLAY_WALK
	player.mo.state = S_PLAY_CROUNCH
	end
	if not player.mo.state == S_PLAY_CROUNCH_MOVE
	player.mo.state = S_PLAY_CROUNCH
	end
	end
	if player.pznocrounch == true and not P_IsObjectOnGround(player.mo)
	or player.pznocrounch == true and not P_IsObjectOnGround(player.mo) and player.mo.state == S_PLAY_CROUNCH_MOVE
	player.mo.state = S_PLAY_CROUNCH_AIR
	end
	if not (player.cmd.buttons & BT_CUSTOM2) and player.mo.state == S_PLAY_CROUNCH_MOVE
	player.mo.state = S_PLAY_CROUNCH
	end
	if player.pznocrounch == true and P_IsObjectOnGround(player.mo) and player.mo.state == S_PLAY_CROUNCH
	and ((player.cmd.forwardmove) or (player.cmd.sidemove)) and player.speed >= 1*FRACUNIT
	player.mo.state = S_PLAY_CROUNCH_MOVE
	end
	end
end)

//crashing badies while mach3-ing
addHook("MobjDamage", function(target, inflictor, source, damage)
	if inflictor and inflictor.valid
	and inflictor.player and inflictor.player.valid
	and inflictor.player.pizzanoreal
	and target and target.valid
	and (target.flags & (MF_ENEMY|MF_BOSS))
	and (inflictor.state == S_PLAY_DASH)
		inflictor.state = S_PLAY_MACH3_PAD
	end
end)

//wallstun
addHook("MobjMoveBlocked", function(mo)
	if mo and mo.valid
	and mo.player and mo.player.valid
and (mo.skin == "pizzano")
and ((mo.state == S_PLAY_SLIDE)
or (mo.state == S_PLAY_SKID_STOP)
or(mo.state == S_PLAY_DIVE))

or ((mo.state == S_PLAY_RUN)
or (mo.state == S_PLAY_MACHC1))
and P_IsObjectOnGround(mo)
		P_InstaThrust(mo, mo.player.drawangle, -12*FRACUNIT) 
		P_SetObjectMomZ(mo, 5*FRACUNIT, false)
		S_StartSound(mo, sfx_bump, 255)
		mo.state = S_PLAY_STUNTT
		mo.player.machxdtimerr = 0
		mo.player.skidingidk = false
		mo.player.stuningg = true
	end
end,MT_PLAYER)