//command for fix the hud idk
rawset(_G, "CV_hud", {}) -- for console vars
CV_hud.x = CV_RegisterVar({
	name = "PZNO_hud_x",
	defaultvalue = "260",
	flags = CV_NETVAR|CV_FLOAT,
	PossibleValue = {MIN = -1000, MAX = 1000*FRACUNIT}, 
})

CV_hud.y = CV_RegisterVar({
	name = "PZNO_hud_y",
	defaultvalue = "70",
	flags = CV_NETVAR|CV_FLOAT,
	PossibleValue = {MIN = -1000, MAX = 1000*FRACUNIT}, 
})

//command for enable hud, by xd
COM_AddCommand("PZNO_hud", function(player, arg1)
    if arg1 == nil
        CONS_Printf(player, 'you can enable and disable telereacciones xd.')
        return
    end

    if arg1 == "1" or arg1 == "yes" then
	    CONS_Printf(player, "i want see your beautiful face pizzano.")
        player.hudd = 1
    elseif arg1 == "0" or arg1 == "no" then
	    CONS_Printf(player, "i dont want see you pizzano.")
        player.hudd = 0
    end
end)

//hud (By properpeppinomod, credits to his dev)

local function face(v, player)
	if player.mo and player.mo.valid
	and player.hudd == 1
	or player.mo and player.mo.valid
	and player.hudd == nil
		if (maptol & TOL_NIGHTS) then
			return
		end
		
		if not player.mo and player.mo.valid
			return
		end
		
		local idleanim = ((leveltime/2) % 57) + 1
		local mach3anim = ((leveltime/1) % 6) + 1
		local mach4anim = ((leveltime/1) % 6) + 1
		local panicanim = ((leveltime/2) % 3) + 1
		local owchieanim = ((leveltime/2) % 3) + 1
		local overtimeanim = ((leveltime/2) % 3) + 1
		local mach2anim = ((leveltime/2) % 6) + 1
		local idle = v.cachePatch( 'PNO_IE' .. idleanim )
		local mach3 = v.cachePatch( 'PNO_H' .. mach3anim )
		local mach4 = v.cachePatch( 'PNO_C' .. mach4anim )
		local panic = v.cachePatch( 'PNO_P' .. panicanim )
		local owchie = v.cachePatch( 'PNO_L' .. owchieanim )
		local overtime = v.cachePatch( 'PNO_O' .. overtimeanim )
		local mach2 = v.cachePatch( 'PNO_M' .. mach2anim )
		local playercolor = v.getColormap(player.skin, player.mo.color)
		
		 if player.pizzanoreal
		and ((PTSR and PTSR.pizzatime and not PTSR.timeover)
		or ((PTV3 and PTV3.pizzatime and player.ptv3 and not player.ptv3.extreme)
		and not (gametype == GT_PTV3DM)
		and not (PTV3.overtime)))
		and not ((player.mo.state == S_PLAY_PAIN)
		or (player.mo.state == S_PLAY_DEDXD)
		or (player.mo.state == S_PLAY_DEAD)
		or (player.mo.state == S_PLAY_RUN)
		or (player.mo.state == S_PLAY_DASH)
		or (player.mo.state == S_PLAY_FIRE)
		 or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL) or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL_FINISH)
		or (player.mo.state == S_PLAY_MACH3_PAD)
		or (player.mo.state == S_PLAY_MACH4PZNO) or (player.mo.state == S_PLAY_MACH5PZNO)
		or (player.mo.state == S_PLAY_PZNO_REDIRECT)
		or (player.mo.state == S_PLAY_SUPERJUMP_PREPARESIDE)
		or (player.mo.state == S_PLAY_FIRE_FINISH)
		or (player.mo.state == S_PLAY_SUPERJUMP_SIDE)
		or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE)
		or (player.mo.state == S_PLAY_PZNOMACH3JUMP)
		or (player.mo.state == S_PLAY_MACHC1))
			v.drawScaled(CV_hud.x.value, CV_hud.y.value, FRACUNIT/2, panic, V_SNAPTOTOP|V_SNAPTORIGHT, playercolor)
		
		elseif player.pizzanoreal
		and ((PTSR and PTSR.pizzatime and PTSR.timeover)
		or (player.ptv3 and player.ptv3.extreme))
		and not ((player.mo.state == S_PLAY_PAIN)
		or (player.mo.state == S_PLAY_DEDXD)
		or (player.mo.state == S_PLAY_DEAD))
			v.drawScaled(CV_hud.x.value, CV_hud.y.value, FRACUNIT/2, overtime, V_SNAPTOTOP|V_SNAPTORIGHT, playercolor)
		
		elseif player.pizzanoreal
		and ((player.mo.state == S_PLAY_DASH)
		or (player.mo.state == S_PLAY_FIRE)
		or (player.mo.state == S_PLAY_MACH3_PAD)
		or (player.mo.state == S_PLAY_PZNO_REDIRECT)
		 or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL) or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL_FINISH)
		or (player.mo.state == S_PLAY_SUPERJUMP_PREPARESIDE)
		or (player.mo.state == S_PLAY_FIRE_FINISH)
		or (player.mo.state == S_PLAY_SUPERJUMP_SIDE))
		or  player.pizzanoreal
		and ((player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE)
		or (player.mo.state == S_PLAY_PZNOMACH3JUMP))
		and player.machxdtimerr <= 350
			v.drawScaled(CV_hud.x.value, CV_hud.y.value, FRACUNIT/2, mach3, V_SNAPTOTOP|V_SNAPTORIGHT, playercolor)
		
		elseif player.pizzanoreal
		and ((player.mo.state == S_PLAY_MACH4PZNO) or (player.mo.state == S_PLAY_MACH5PZNO)) 
		or player.pizzanoreal
		and player.machxdtimerr >= 350
		and ((player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE)
		or (player.mo.state == S_PLAY_PZNOMACH3JUMP))
			v.drawScaled(CV_hud.x.value, CV_hud.y.value, FRACUNIT/2, mach4, V_SNAPTOTOP|V_SNAPTORIGHT, playercolor)
		
		elseif player.pizzanoreal
		and ((player.mo.state == S_PLAY_RUN)
		or (player.mo.state == S_PLAY_MACHC1))
			v.drawScaled(CV_hud.x.value, CV_hud.y.value, FRACUNIT/2, mach2, V_SNAPTOTOP|V_SNAPTORIGHT, playercolor)
		
		elseif player.pizzanoreal
		and ((player.mo.state == S_PLAY_PAIN) or (player.mo.state == S_PLAY_DEDXD) or (player.mo.state == S_PLAY_DEAD))
			v.drawScaled(CV_hud.x.value, CV_hud.y.value, FRACUNIT/2, owchie, V_SNAPTOTOP|V_SNAPTORIGHT, playercolor)
		
		elseif player.pizzanoreal
		and not ((PTSR and PTSR.pizzatime and not PTSR.timeover)
		or ((PTV3 and PTV3.pizzatime and player.ptv3 and not player.ptv3.extreme)
		and not (gametype == GT_PTV3DM)
		and not (PTV3.overtime)))
		and not ((player.mo.state == S_PLAY_PAIN)
		or (player.mo.state == S_PLAY_DEDXD)
		or (player.mo.state == S_PLAY_DEAD)
		or (player.mo.state == S_PLAY_RUN)
		or (player.mo.state == S_PLAY_DASH)
		or (player.mo.state == S_PLAY_FIRE)
		 or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL) or (player.mo.state == S_PLAY_WALLCLIMBSPIN_CANCEL_FINISH)
		or (player.mo.state == S_PLAY_MACH3_PAD)
		or (player.mo.state == S_PLAY_MACH4PZNO) or (player.mo.state == S_PLAY_MACH5PZNO)
		or (player.mo.state == S_PLAY_PZNO_REDIRECT)
		or (player.mo.state == S_PLAY_SUPERJUMP_PREPARESIDE)
		or (player.mo.state == S_PLAY_FIRE_FINISH)
		or (player.mo.state == S_PLAY_SUPERJUMP_SIDE)
		or (player.mo.state == S_PLAY_PZNOMACH3JUMPDIVE)
		or (player.mo.state == S_PLAY_PZNOMACH3JUMP)
		or (player.mo.state == S_PLAY_MACHC1))
			v.drawScaled(CV_hud.x.value, CV_hud.y.value, FRACUNIT/2, idle, V_SNAPTOTOP|V_SNAPTORIGHT, playercolor)

		end
	end
end
hud.add(face, "game")

//
//BEST PIZZATIME ANIMATION EVER/idk
//
addHook("ThinkFrame", function(player)
     for player in players.iterate do
	  if player.pizzanoreal
    and ((PTSR and PTSR.pizzatime and not PTSR.timeover)
	or (PTV3 and PTV3.pizzatime))
		and not ((player.ptv3 and player.ptv3.extreme))
	player.pizzatimestimerxd = $+1
	else
	player.pizzatimestimerxd = 0
	end
	if player.pizzanoreal
	and player.pizzatimestimerxd == 535 then
	P_FlashPal(player, 1, 14)
    end
	end
end)

local function itssugarrush(v, player)
	if player.mo and player.mo.valid
		if (maptol & TOL_NIGHTS) then
			return
		end
		
		if not player.mo and player.mo.valid
			return
		end
		
		local sugarrushanim = ((leveltime/2) % 2) + 1
		local sugarrushh = v.cachePatch( 'SRM_A' .. sugarrushanim )
		local playercolor = v.getColormap(player.skin, player.mo.color)
		
		 if player.pizzanoreal
		and ((PTSR and PTSR.pizzatime and not PTSR.timeover)
		or (PTV3 and PTV3.pizzatime))
		and not ((player.ptv3 and player.ptv3.extreme))
		
		and player.pizzatimestimerxd <= 535
			v.drawScaled(160*FRACUNIT, 80*FRACUNIT, FRACUNIT/2, sugarrushh, V_PERPLAYER, playercolor)
		end
	end
end
hud.add(itssugarrush, "game")

//tutorial hehe
COM_AddCommand("PZNO_tutorial", function(player, arg1)
    if arg1 == nil
        CONS_Printf(player, 'you can learn about pizzanos moveset with a tutorial(show and hide).')
        return
    end

    if arg1 == "1" or arg1 == "show" or arg1 == "yes" then
        player.pznotutorial = 1
    elseif arg1 == "0" or arg1 == "hide" or arg1 == "no" then
        player.pznotutorial = 0
    end
end)

addHook("PlayerThink", function(player)
	if player.pizzanoreal == true
	and not ((player.pznotutorialpag3 == true)
	or (player.pznotutorialpag2 == true))
	player.pznotutorialpag1 = true
	end
	
	if player.pizzanoreal
	and ((player.pznotutorialpag1 == true)
	or (player.pznotutorialpag3 == true))
	and player.c2timr == 1
	player.pznotutorialpag2 = true
	player.pznotutorialpag1 = false
	player.pznotutorialpag3 = false
	end
	
	if player.pizzanoreal
	and ((player.pznotutorialpag2 == true)
	or (player.pznotutorialpag3 == true))
	and player.c1timr == 1
	player.pznotutorialpag2 = false
	player.pznotutorialpag1 = true
	player.pznotutorialpag3 = false
	end
	
	if player.pizzanoreal
	and ((player.pznotutorialpag1 == true)
	or (player.pznotutorialpag2 == true))
	and player.c3timr == 1
	player.pznotutorialpag2 = false
	player.pznotutorialpag1 = false
	player.pznotutorialpag3 = true
	end
end)

local function showtutorial(v, player)
	if player.mo and player.mo.valid
	and player.pizzanoreal
	and player.pznotutorial == 1
		if (maptol & TOL_NIGHTS) then
			return
		end
		
		if not player.mo and player.mo.valid
			return
		end
		
		local pnotutorialpagg1 = ((leveltime/2) % 1) + 1
		local pnotutorialpagg2 = ((leveltime/2) % 1) + 1
		local pnotutorialpagg3 = ((leveltime/2) % 1) + 1
		local pnotutorialpag1 = v.cachePatch( 'TUTORIALPAG1' .. pnotutorialpagg1 )
		local pnotutorialpag2 = v.cachePatch( 'TUTORIALPAG2' .. pnotutorialpagg2 )
		local pnotutorialpag3 = v.cachePatch( 'TUTORIALPAG3' .. pnotutorialpagg3 )
		local playercolor = v.getColormap(player.skin, player.mo.color)
		
		 if player.pizzanoreal
		 and player.pznotutorialpag1 == true
			v.drawScaled(60*FRACUNIT, 60*FRACUNIT, FRACUNIT/2, pnotutorialpag1, V_PERPLAYER, playercolor)
         
		 elseif player.pizzanoreal
		 and player.pznotutorialpag2 == true
		 v.drawScaled(60*FRACUNIT, 60*FRACUNIT, FRACUNIT/2, pnotutorialpag2, V_PERPLAYER, playercolor)
		 
		 elseif player.pizzanoreal
		 and player.pznotutorialpag3 == true
		 v.drawScaled(60*FRACUNIT, 60*FRACUNIT, FRACUNIT/2, pnotutorialpag3, V_PERPLAYER, playercolor)
		end
	end
end
hud.add(showtutorial, "game")