addHook("PlayerThink",function(p)
	if not (p.mo and p.mo.valid and p.mo.skin=="uglyknux") return end
	local mo = p.mo
	if P_IsObjectOnGround(mo) and p.pflags & PF_GLIDING
		p.pflags = $ & ~(PF_GLIDING|PF_JUMPED|PF_NOJUMPDAMAGE)
		p.mo.state = S_PLAY_WALK
	end
	if p.mo.state == S_PLAY_GLIDE_LANDING
		p.mo.state = S_PLAY_STND
	end
	if p.mo.state != S_PLAY_GLIDE
		p.pflags = $ & ~PF_THOKKED
	end
end) 

addHook("PreThinkFrame", do
    for p in players.iterate
        if not (p.mo and p.mo.valid and p.mo.skin=="uglyknux") return end
        if p.climbing == 1 and not p.powers[pw_super] --Bruh how tf is he still slower than the other one (okay so I'm a literal dumbass for thinking that testing this with another Ugly present would be a good idea)
            p.cmd.forwardmove = $*3/4 
			p.cmd.sidemove = $*9/10
		elseif p.climbing == 1 and p.powers[pw_super] --Super buffs just because he needs them.
			p.cmd.forwardmove = $*2
			p.cmd.sidemove = $*2
		end
    end
end)

COM_AddCommand("UglyControlsOff", function(p)
	if not (p.mo and p.mo.valid and p.mo.skin=="uglyknux")
	    print("You can't use this right now.")
		S_StartSound(mo,sfx_lose)
    end
	if (p.mo and p.mo.skin=="uglyknux")
		R_SetPlayerSkin(p,"Knuckles")
		print("Why're you even playing Ugly in the first place?")
		S_StartSound(mo,sfx_bewar1)
	end
end)

COM_AddCommand("UglyControlsOn",function(p)
    if not (p and p.mo and p.mo.valid and p.mo.health and (p.mo.skin=="knuckles" or p.mo.skin=="uglyknux"))
        CONS_Printf(consoleplayer, "You can't use this right now.")
		S_StartSound(mo,sfx_lose)
        return
    end
    if p.mo.skin=="knuckles"
       print("No.")
	   S_StartSound(mo,sfx_lose)
    else
        CONS_Printf(p, "You're already using UglyKnux!")
		S_StartSound(mo,sfx_lose)
    end
end)
