freeslot(
"SPR_PLSS",
"SPR2_TSSN",
"SPR2_TSS1",
"SPR2_TSS2",
"SPR2_TSDJ",
"SPR2_TSDD",
"SPR2_TSW1",
"SPR2_TSW2",
"SPR2_TSW3",
"SPR2_TSW4",
"SPR2_TSW5",
"SPR2_TSW6",
"SPR2_TST1",
"SPR2_TST2",
"SPR2_TST3",
"SPR2_TST4",
"SPR2_TST5",
"SPR2_TST6",
"SPR2_TST7",
"SPR2_TST8",
"SPR_SPGB",
"SPR2_SPLA",
"MT_SPICERLAUGH",
"S_PLAY_SPICERSPIN1",
"S_PLAY_SPICERSPIN2",
"S_PLAY_SPICERSPIN3",
"S_PLAY_SPICERSPIN4",
"S_PLAY_SPICERSPIN5",
"S_PLAY_SPICERSPIN6",
"S_PLAY_SPICERSPIN7",
"S_PLAY_SPICERSPIN8",
"S_PLAY_SPICERSPIN9",
"S_PLAY_SPICERSPIN10",
"S_PLAY_SPICERSPIN11",
"S_PLAY_SPICERSPIN12",
"S_PLAY_SPICERDOUBLEJUMP",
"S_PLAY_SPICERDEAD",
"S_CLIMBWALL_HOLD",
"S_CLIMBWALL_SPIN",
"S_PLAY_SPICERWADDLE1",
"S_PLAY_SPICERWADDLE2",
"S_PLAY_SPICERWADDLE3",
"S_PLAY_SPICERWADDLE4",
"S_PLAY_SPICERWADDLE5",
"S_PLAY_SPICERWADDLE6",
"S_PLAY_SPICERTAUNT1",
"S_PLAY_SPICERTAUNT2",
"S_PLAY_SPICERTAUNT3",
"S_PLAY_SPICERTAUNT4",
"S_PLAY_SPICERTAUNT5",
"S_PLAY_SPICERTAUNT6",
"S_PLAY_SPICERTAUNT7",
"S_PLAY_SPICERTAUNT8",
"S_SPICERLAUGH",
"S_PLAY_SPICERLAUGHATTACK1",
"S_PLAY_SPICERLAUGHATTACK2",
"S_PLAY_SPICERLAUGHATTACK3",
"S_PLAY_SPICERLAUGHATTACK4",
"S_PLAY_SPICERLAUGHATTACK5",
"S_PLAY_SPICERLAUGHATTACK6",
"S_PLAY_SPICERLAUGHATTACK7",
"S_PLAY_SPICERLAUGHATTACK8",
"S_PLAY_SPICERLAUGHATTACK9",
"S_PLAY_SPICERLAUGHATTACK10",
"sfx_splg"
)
sfxinfo[sfx_splg] = {caption = "HAHAHAHA!!"}
states[S_PLAY_SPICERSPIN1] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSSN,
        tics = -1,
}
states[S_PLAY_SPICERSPIN2] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSS1,
        tics = -1,
}
states[S_PLAY_SPICERSPIN3] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSS2,
        tics = -1,
}
states[S_PLAY_SPICERSPIN4] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSSN,
        tics = -1,
}
states[S_PLAY_SPICERSPIN5] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSS1,
        tics = -1,
}
states[S_PLAY_SPICERSPIN6] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSS2,
        tics = -1,
}
states[S_PLAY_SPICERSPIN7] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSSN,
        tics = -1,
}
states[S_PLAY_SPICERSPIN8] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSS1,
        tics = -1,
}
states[S_PLAY_SPICERSPIN9] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSS2,
        tics = -1,
}
states[S_PLAY_SPICERSPIN10] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSSN,
        tics = -1,
}
states[S_PLAY_SPICERSPIN11] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSS1,
        tics = -1,
}
states[S_PLAY_SPICERSPIN12] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSS2,
        tics = -1,
}
states[S_PLAY_SPICERDOUBLEJUMP] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSDJ,
        tics = -1,
}
states[S_PLAY_SPICERDEAD] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSDD,
        tics = -1,
}
states[S_CLIMBWALL_HOLD] = {SPR_WLHL,FF_ANIMATE|FF_PAPERSPRITE,18,nil,G,2,S_NULL}
states[S_CLIMBWALL_SPIN] = {SPR_WLSP,FF_ANIMATE|FF_PAPERSPRITE,10,nil,E,2,S_NULL}
states[S_PLAY_SPICERWADDLE1] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSW1,
        tics = -1,
}
states[S_PLAY_SPICERWADDLE2] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSW2,
        tics = -1,
}
states[S_PLAY_SPICERWADDLE3] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSW3,
        tics = -1,
}
states[S_PLAY_SPICERWADDLE4] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSW4,
        tics = -1,
}
states[S_PLAY_SPICERWADDLE5] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSW5,
        tics = -1,
}
states[S_PLAY_SPICERWADDLE6] = {
        sprite = SPR_PLAY,
        frame = SPR2_TSW6,
        tics = -1,
}
states[S_PLAY_SPICERTAUNT1] = {
        sprite = SPR_PLAY,
        frame = SPR2_TST1,
        tics = -1,
}
states[S_PLAY_SPICERTAUNT2] = {
        sprite = SPR_PLAY,
        frame = SPR2_TST2,
        tics = -1,
}
states[S_PLAY_SPICERTAUNT3] = {
        sprite = SPR_PLAY,
        frame = SPR2_TST3,
        tics = -1,
}
states[S_PLAY_SPICERTAUNT4] = {
        sprite = SPR_PLAY,
        frame = SPR2_TST4,
        tics = -1,
}
states[S_PLAY_SPICERTAUNT5] = {
        sprite = SPR_PLAY,
        frame = SPR2_TST5,
        tics = -1,
}
states[S_PLAY_SPICERTAUNT6] = {
        sprite = SPR_PLAY,
        frame = SPR2_TST6,
        tics = -1,
}
states[S_PLAY_SPICERTAUNT7] = {
        sprite = SPR_PLAY,
        frame = SPR2_TST7,
        tics = -1,
}
states[S_PLAY_SPICERTAUNT8] = {
        sprite = SPR_PLAY,
        frame = SPR2_TST8,
        tics = -1,
}
states[S_SPICERLAUGH] = {SPR_SPGB, A, 1, nil, 0, 0, S_SPICERLAUGH}
states[S_PLAY_SPICERLAUGHATTACK1] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK2] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK3] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK4] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK5] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK6] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK7] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK8] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK9] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
states[S_PLAY_SPICERLAUGHATTACK10] = {
        sprite = SPR_PLAY,
        frame = SPR2_SPLA,
        tics = -1,
}
mobjinfo[MT_SPICERLAUGH] = {
	doomednum = -1,
	spawnstate = S_SPICERLAUGH,
	spawnhealth = 1000,
	reactiontime = 8,
	deathstate = S_NULL,
	xdeathstate = S_NULL,
	speed = 15*FRACUNIT,
	radius = 31*FRACUNIT,
	height = 10*FRACUNIT,
	mass = 0,
	damage = 1,
	flags = MF_NOBLOCKMAP|MF_NOGRAVITY|MF_MISSILE
}
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.mo.state == S_PLAY_SPICERSPIN1
		player.mo.state = S_PLAY_SPICERSPIN2
		elseif player.mo.state == S_PLAY_SPICERSPIN2
		player.mo.state = S_PLAY_SPICERSPIN3
		elseif player.mo.state == S_PLAY_SPICERSPIN3
		player.mo.state = S_PLAY_SPICERSPIN4
		elseif player.mo.state == S_PLAY_SPICERSPIN4
		player.mo.state = S_PLAY_SPICERSPIN5
		elseif player.mo.state == S_PLAY_SPICERSPIN5
		player.mo.state = S_PLAY_SPICERSPIN6
		elseif player.mo.state == S_PLAY_SPICERSPIN6
		player.mo.state = S_PLAY_SPICERSPIN7
		elseif player.mo.state == S_PLAY_SPICERSPIN7
		player.mo.state = S_PLAY_SPICERSPIN8
		elseif player.mo.state == S_PLAY_SPICERSPIN8
		player.mo.state = S_PLAY_SPICERSPIN9
		elseif player.mo.state == S_PLAY_SPICERSPIN9
		player.mo.state = S_PLAY_SPICERSPIN10
		elseif player.mo.state == S_PLAY_SPICERSPIN10
		player.mo.state = S_PLAY_SPICERSPIN11
		elseif player.mo.state == S_PLAY_SPICERSPIN11
		player.mo.state = S_PLAY_SPICERSPIN12
		elseif player.mo.state == S_PLAY_SPICERSPIN12
		player.mo.state = S_PLAY_STND
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.mo.state == S_PLAY_SPICERWADDLE1
		player.mo.state = S_PLAY_SPICERWADDLE2
		elseif player.mo.state == S_PLAY_SPICERWADDLE2
		player.mo.state = S_PLAY_SPICERWADDLE3
		elseif player.mo.state == S_PLAY_SPICERWADDLE3
		player.mo.state = S_PLAY_SPICERWADDLE4
		elseif player.mo.state == S_PLAY_SPICERWADDLE4
		player.mo.state = S_PLAY_SPICERWADDLE5
		elseif player.mo.state == S_PLAY_SPICERWADDLE5
		player.mo.state = S_PLAY_SPICERWADDLE6
		elseif player.mo.state == S_PLAY_SPICERWADDLE6
		player.mo.state = S_PLAY_SPICERWADDLE1
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.mo.state == S_PLAY_SPICERTAUNT1
		player.mo.state = S_PLAY_SPICERTAUNT2
		elseif player.mo.state == S_PLAY_SPICERTAUNT2
		player.mo.state = S_PLAY_SPICERTAUNT3
		elseif player.mo.state == S_PLAY_SPICERTAUNT3
		player.mo.state = S_PLAY_SPICERTAUNT4
		elseif player.mo.state == S_PLAY_SPICERTAUNT4
		player.mo.state = S_PLAY_SPICERTAUNT5
		elseif player.mo.state == S_PLAY_SPICERTAUNT5
		player.mo.state = S_PLAY_SPICERTAUNT6
		elseif player.mo.state == S_PLAY_SPICERTAUNT6
		player.mo.state = S_PLAY_SPICERTAUNT7
		elseif player.mo.state == S_PLAY_SPICERTAUNT7
		player.mo.state = S_PLAY_SPICERTAUNT8
		elseif player.mo.state == S_PLAY_SPICERTAUNT8
		player.mo.state = S_PLAY_SPICERTAUNT1
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.spicerspin == 1
		player.powers[pw_nocontrol] = 32768
		P_InstaThrust(player.mo, player.mo.angle, 20*FRACUNIT)
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if (player.mo.state == S_PLAY_SPICERLAUGHATTACK1 or
		    player.mo.state == S_PLAY_SPICERLAUGHATTACK2 or
			player.mo.state == S_PLAY_SPICERLAUGHATTACK3 or
			player.mo.state == S_PLAY_SPICERLAUGHATTACK4 or
			player.mo.state == S_PLAY_SPICERLAUGHATTACK5 or
		    player.mo.state == S_PLAY_SPICERLAUGHATTACK6 or
			player.mo.state == S_PLAY_SPICERLAUGHATTACK7 or
			player.mo.state == S_PLAY_SPICERLAUGHATTACK8 or
			player.mo.state == S_PLAY_SPICERLAUGHATTACK9 or
		    player.mo.state == S_PLAY_SPICERLAUGHATTACK10)
		player.powers[pw_nocontrol] = 1
		player.spicerlaugh = 1
		else
		player.spicerlaugh = 0
//		player.mo.momx = 0
//		player.mo.momy = 0
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.spicerwaddle == 1
		player.powers[pw_nocontrol] = 32768
		P_InstaThrust(player.mo, player.mo.angle, 5*FRACUNIT)
	end
	end
	end
end)

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.skin ~= "thespicer" then
			continue
		end
		if player.spicerspin == nil then
			player.spicerspin = 0
end
end
end)

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.skin ~= "thespicer" then
			continue
		end
		if player.spicerwaddle == nil then
			player.spicerwaddle = 0
end
end
end)

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.skin ~= "thespicer" then
			continue
		end
		if player.spicerdead == nil then
			player.spicerdead = 0
end
end
end)

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.skin ~= "thespicer" then
			continue
		end
		if player.spicerlaugh == nil then
			player.spicerlaugh = 0
end
end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.mo.state == S_PLAY_SPICERLAUGHATTACK1
		player.mo.state = S_PLAY_SPICERLAUGHATTACK2
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK2
		player.mo.state = S_PLAY_SPICERLAUGHATTACK3
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK3
		player.mo.state = S_PLAY_SPICERLAUGHATTACK4
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK4
		player.mo.state = S_PLAY_SPICERLAUGHATTACK5
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK5
		player.mo.state = S_PLAY_SPICERLAUGHATTACK6
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK6
		player.mo.state = S_PLAY_SPICERLAUGHATTACK7
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK7
		player.mo.state = S_PLAY_SPICERLAUGHATTACK8
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK8
		player.mo.state = S_PLAY_SPICERLAUGHATTACK9
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK9
		player.mo.state = S_PLAY_SPICERLAUGHATTACK10
		elseif player.mo.state == S_PLAY_SPICERLAUGHATTACK10
		player.mo.state = S_PLAY_STND
	end
	end
	end
end)

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.skin ~= "thespicer" then
			continue
		end
		if player.spicertaunt == nil then
			player.spicertaunt = 0
end
end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.mo.state == S_PLAY_SPICERDOUBLEJUMP and P_IsObjectOnGround(player.mo)
		player.mo.state = S_PLAY_STND
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.exiting and player.spicertaunt == 0 and not (player.powers[pw_carry] == CR_NIGHTSMODE)
		player.mo.state = S_PLAY_SPICERTAUNT1
		S_StartSound(mo,sfx_splg)
	end
	end
	end
end)

addHook("PlayerCanDamage", function(player, mobj)
	if player.mo and player.mo.skin == "thespicer" and player.spicerspin == 1
	and (mobj.flags&MF_ENEMY or mobj.flags&MF_BOSS) and player.mo.skin == "thespicer" return true end
end, MT_PLAYER)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer" and
	   (player.mo.state == S_PLAY_SPICERSPIN1 or
		player.mo.state == S_PLAY_SPICERSPIN2 or
		player.mo.state == S_PLAY_SPICERSPIN3 or
		player.mo.state == S_PLAY_SPICERSPIN4 or
		player.mo.state == S_PLAY_SPICERSPIN5 or
		player.mo.state == S_PLAY_SPICERSPIN6 or
		player.mo.state == S_PLAY_SPICERSPIN7 or
		player.mo.state == S_PLAY_SPICERSPIN8 or
		player.mo.state == S_PLAY_SPICERSPIN9 or
		player.mo.state == S_PLAY_SPICERSPIN10 or
		player.mo.state == S_PLAY_SPICERSPIN11 or
		player.mo.state == S_PLAY_SPICERSPIN12)
		player.spicerspin = 1
		else
		player.spicerspin = 0
		end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer" and
	   (player.mo.state == S_PLAY_SPICERTAUNT1 or
		player.mo.state == S_PLAY_SPICERTAUNT2 or
		player.mo.state == S_PLAY_SPICERTAUNT3 or
		player.mo.state == S_PLAY_SPICERTAUNT4 or
		player.mo.state == S_PLAY_SPICERTAUNT5 or
		player.mo.state == S_PLAY_SPICERTAUNT6 or
		player.mo.state == S_PLAY_SPICERTAUNT7 or
		player.mo.state == S_PLAY_SPICERTAUNT8)
		player.spicertaunt = 1
		else
		player.spicertaunt = 0
		end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer" and
	   (player.mo.state == S_PLAY_SPICERWADDLE1 or
		player.mo.state == S_PLAY_SPICERWADDLE2 or
		player.mo.state == S_PLAY_SPICERWADDLE3 or
		player.mo.state == S_PLAY_SPICERWADDLE4 or
		player.mo.state == S_PLAY_SPICERWADDLE5 or
		player.mo.state == S_PLAY_SPICERWADDLE6)
		player.spicerwaddle = 1
		else
		player.spicerwaddle = 0
		end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer" and
	   (player.mo.state == S_PLAY_WAIT)
		player.mo.state = S_PLAY_SPICERWADDLE1
		end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.mo.state == S_PLAY_SPICERDOUBLEJUMP
		player.mo.state = S_PLAY_SPICERDOUBLEJUMP
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.mo.state == S_PLAY_SPICERDEAD
		player.powers[pw_nocontrol] = 1
		player.mo.momx = 0
		player.mo.momy = 0
		player.mo.momz = 0
		if not P_IsObjectOnGround(player.mo)
		P_SetObjectMomZ(player.mo, -999*FRACUNIT, false)
	end
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.spicertaunt == 1
		player.powers[pw_nocontrol] = 1
		player.mo.momx = 0
		player.mo.momy = 0
		player.mo.momz = 0
		if not P_IsObjectOnGround(player.mo)
		P_SetObjectMomZ(player.mo, -999*FRACUNIT, false)
	end
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.spicerdead == 1 and (player.playerstate == PST_LIVE)
		player.mo.state = S_PLAY_SPICERDEAD
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.mo.state == S_PLAY_CLING and P_IsObjectOnGround(player.mo)
		player.climbspin.astate = 2
		player.climbspin.atime = 0
		player.climbspin = 0
		P_DoJump(player)
		P_SetObjectMomZ(player.mo, 0*FRACUNIT, false)
		player.mo.state = S_PLAY_JUMP
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
	    if not (player.mo and player.mo.skin == "thespicer") then continue end
		player.charflags = $ & ~SF_CANBUSTWALLS
		 
		 if player.spicerspin == 1
		     player.charflags = $ |SF_CANBUSTWALLS
		 else
		     player.charflags = $ & ~SF_CANBUSTWALLS
		end
    end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.spicerdead == 0 and (player.playerstate == PST_DEAD)
		if (gametype != GT_TEAMMATCH) and (gametype != GT_CTF) and (gametype != GT_MATCH) and not (CBW_Battle and CBW_Battle.SkinVars)
			player.spicerdead = 1
	end
	end
	end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "thespicer"
		if player.spicerdead == 0 and player.powers[pw_super] and not (player.mo.state == S_PLAY_SUPER_TRANS1 or
		player.mo.state == S_PLAY_SUPER_TRANS2 and not
		player.mo.state == S_PLAY_SUPER_TRANS3 and not
		player.mo.state == S_PLAY_SUPER_TRANS4 and not
		player.mo.state == S_PLAY_SUPER_TRANS5 and not
		player.mo.state == S_PLAY_SUPER_TRANS6) and not (player.powers[pw_carry] == CR_NIGHTSMODE)
			player.spicerdead = 1
	end
	end
	end
end)

//hud.add(function(v)
//	for player in players.iterate do
//		if player.mo.skin ~= "thespicer" then
//			continue
//		end
//		v.drawNum(160, 5, player.spicerspin, V_ORANGEMAP|V_30TRANS)
//	end
//end)

addHook("PlayerThink",function(player)
	if player.mo.skin == "thespicer"
		if player.cmd.buttons & BT_SPIN and (gametype != GT_TEAMMATCH) and (gametype != GT_CTF) and (gametype != GT_MATCH) and P_IsObjectOnGround(player.mo) and player.spicerdead == 0 and player.spicerwaddle == 0 and player.spicertaunt == 0 and player.spicerspin == 0 and not (player.weapondelay) and not (player.playerstate == PST_DEAD) and not (player.pflags & PF_STASIS) and not (player.pflags & PF_FULLSTASIS) and not (player.powers[pw_carry] == CR_NIGHTSMODE) and not (player.powers[pw_carry]) and not (player.pflags & PF_STASIS) and not (CBW_Battle and CBW_Battle.SkinVars)
			player.mo.state = S_PLAY_SPICERSPIN1
			S_StartSound(player.mo, sfx_spin, p)
			player.weapondelay = TICRATE*2
		end
	end
end)

addHook("PlayerThink", function(player)
	if not (player and player.valid
	and player.mo and player.mo.valid)
		return
	end
    if player.mo.skin == "thespicer" then
        if not player.lastbuttons then player.lastbuttons = 0 end
        if ((player.cmd.buttons & BT_SPIN) and ((gametype == GT_TEAMMATCH) or (gametype == GT_CTF) or (gametype == GT_MATCH) or (CBW_Battle and CBW_Battle.SkinVars)) and P_IsObjectOnGround(player.mo) and player.spicerdead == 0 and player.spicerwaddle == 0 and player.spicertaunt == 0 and player.spicerspin == 0 and not (player.weapondelay) and not (player.lastbuttons & BT_SPIN) and not (player.weapondelay) and not (player.pflags & PF_STASIS) and not (player.pflags & PF_FULLSTASIS) and not (player.powers[pw_carry] == CR_NIGHTSMODE)  and not (player.powers[pw_carry])  and not (player.pflags & PF_STASIS)  and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) and P_PlayerInPain(player) != true) then
			local ring = P_SpawnPlayerMissile(player.mo, MT_SPICERLAUGH)
			player.weapondelay = 1*TICRATE
			player.mo.state = S_PLAY_SPICERLAUGHATTACK1
			S_StartSound(mo,sfx_splg)
        end
        player.lastbuttons = player.cmd.buttons
    end
end)

addHook("PlayerThink", function(player)
    if player.mo.skin == "thespicer" and player.spicerdead == 1 then
        player.pflags = player.pflags | PF_GODMODE
	else
		player.pflags = player.pflags & ~PF_GODMODE
    end
end)

addHook ("MobjMoveCollide", function (player, spicerdoesafunnyspin)
	if player.player ~= nil and player.skin == "thespicer"
	 if player.player.spicerspin == 1
		if (spicerdoesafunnyspin.type == MT_SALOONDOOR or spicerdoesafunnyspin.type == MT_SALOONDOORCENTER or spicerdoesafunnyspin.type == MT_WALLSPIKE or spicerdoesafunnyspin.type == MT_SPIKE)
			if (player.z + player.height < spicerdoesafunnyspin.z) 
			or (player.z > spicerdoesafunnyspin.z + spicerdoesafunnyspin.height)
				return false
			else
				P_KillMobj(spicerdoesafunnyspin,player,player)
			end
			end
		end
	end
end)

addHook("AbilitySpecial", function(player)
	if player.mo.skin != "thespicer"
		return 
	end
	if player.mo.state == S_PLAY_SPICERDOUBLEJUMP or player.pflags&PF_THOKKED or player.spicerspin == 1
		return true
	end
	player.mo.state = S_PLAY_SPICERDOUBLEJUMP
	if player.mo.eflags & MFE_UNDERWATER
		P_SetObjectMomZ(player.mo, 5*FRACUNIT, false)
		player.pflags = $|PF_THOKKED 
	else
		P_SetObjectMomZ(player.mo, 10*FRACUNIT, false)
		player.pflags = $|PF_THOKKED 
	return true
end
end)

local function CheckAndCrumble2(mo, sec)
  for fof in sec.ffloors()
    if not (fof.flags & FF_EXISTS) continue end -- Does it exist?
    if not (fof.flags & FF_BUSTUP) continue end -- Is it bustable?
    
    if mo.z + mo.momz + mo.height < fof.bottomheight continue end -- Are we too low?
    if mo.z + mo.momz > fof.topheight continue end -- Are we too high?

    EV_CrumbleChain(fof) -- Crumble
  end
end

addHook("PlayerThink", function(p)
  if not p.mo return end
  if p.mo.skin != "thespicer" return end
  if p.spicerspin == 0 return end
	CheckAndCrumble2(p.mo, p.mo.subsector.sector)
end)

-- Wall Check code by Buggie

rawset(_G, "P_IsClimbingValid",function(player, angle,sec)

	local platx, platy
	local glidesector
	local floorz, ceilingz
	local mo = player.mo
	local rover

	platx = P_ReturnThrustX(mo, angle, mo.radius + FixedMul(8*FRACUNIT, mo.scale))
	platy = P_ReturnThrustY(mo, angle, mo.radius + FixedMul(8*FRACUNIT, mo.scale))

	glidesector = R_PointInSubsector(mo.x + platx, mo.y + platy).sector
	if sec then glidesector = sec end
	
	floorz = glidesector.floorheight
	ceilingz = glidesector.ceilingheight

	if (glidesector ~= mo.subsector.sector)
	
		local floorclimb = false
		local topheight, bottomheight

		for rover in glidesector.ffloors()
		
			if (not (rover.flags & FF_EXISTS) or not (rover.flags & FF_BLOCKPLAYER))
				continue
			end

			topheight = rover.topheight
			bottomheight = rover.bottomheight

			floorclimb = true

			if (mo.eflags & MFE_VERTICALFLIP)
			
				if ((topheight < mo.z + mo.height) and ((mo.z + mo.height + mo.momz) < topheight))
					floorclimb = true
				end
				if (topheight < mo.z)
					floorclimb = false
				end
				if (bottomheight > mo.z + mo.height - FixedMul(16*FRACUNIT,mo.scale))
					floorclimb = false
				end
			else
			
				if ((bottomheight > mo.z) and ((mo.z - mo.momz) > bottomheight))
					floorclimb = true
				end
				if (bottomheight > mo.z + mo.height)
					floorclimb = false
				end
				if (topheight < mo.z + FixedMul(16*FRACUNIT,mo.scale))
					floorclimb = false
				end
			end

			if (floorclimb)
				break
			end
		end

		if (mo.eflags & MFE_VERTICALFLIP)
		
			if ((floorz <= mo.z + mo.height)
				and ((mo.z + mo.height - mo.momz) <= floorz))
				floorclimb = true
			end

			if ((floorz > mo.z)
				and glidesector.floorpic == "F_SKY1")
				return false
			end

			if ((mo.z + mo.height - FixedMul(16*FRACUNIT,mo.scale) > ceilingz)
				or (mo.z + mo.height <= floorz))
				floorclimb = true
			end
		else
		
			if ((ceilingz >= mo.z)
				and ((mo.z - mo.momz) >= ceilingz))
				floorclimb = true
			end

			if ((ceilingz < mo.z+mo.height)
				and glidesector.ceilingpic == "F_SKY1")
				return false
			end

			if ((mo.z + FixedMul(16*FRACUNIT,mo.scale) < floorz)
				or (mo.z >= ceilingz))
				floorclimb = true
			end
		end

		if (not floorclimb)
			return false
		end

		return true
	end

	return true
end)

rawset(_G,"PTR_GlideClimbTraverse",function(slidemo,li)
	if not li then return end
	local checkline = li
	local rover
	local topheight, bottomheight
	local fofline = false
	local checksector = (li.backsector and not P_PointOnLineSide(slidemo.x, slidemo.y, li)) and li.backsector or li.frontsector

	if (checksector.ffloors)
		for rover in checksector.ffloors()
			if (not(rover.flags & FF_EXISTS) or not(rover.flags & FF_BLOCKPLAYER) or ((rover.flags & FF_BUSTUP) and (slidemo.player.charflags & SF_CANBUSTWALLS)))
				continue
			end

			topheight = rover.topheight
			bottomheight = rover.bottomheight

			if (topheight < slidemo.z)
				continue
			end

			if (bottomheight > slidemo.z + slidemo.height)
				continue
			end

			// Got this far, so I guess it's climbable. // TODO: Climbing check, also, better method to do this?
			if (rover.master.flags & ML_TFERLINE)
				local linenum = checksector.lines[0]
				checkline = rover.master.frontsector.lines[0] + linenum
				fofline = true
			end

			break
		end
	end

	// see about climbing on the wall
	if (not(checkline.flags & ML_NOCLIMB) and checkline.special ~= 41)
		local canclimb
		local climbangle, climbline
		local whichside = P_PointOnLineSide(slidemo.x, slidemo.y, li)

		climbangle = R_PointToAngle2(li.v1.x, li.v1.y, li.v2.x, li.v2.y)
		climbline = climbangle

		if (whichside) // on second side?
			climbline = $+ ANGLE_180
		end

		climbangle = $+ (ANGLE_90 * (whichside and -1 or 1))

		canclimb = (li.backsector and P_IsClimbingValid(slidemo.player,climbangle,checksector) or true)
		
		if (((not slidemo.player.climbing)
		or (slidemo.player.climbing == 1))
		and canclimb)
			return true,climbangle,checksector
		end
	end
	return false,0
end)

addHook("ShieldSpecial", function(player)
	if player.valid and player.mo and player.mo.valid
	and player.playerstate == PST_LIVE
		if player.climbspin and player.climbspin.holdwall
			return true
		end
	end
end)

addHook("PlayerThink", function(player)
	if player.valid and player.mo and player.mo.valid
	and player.playerstate == PST_LIVE
		local mo = player.mo
		if not player.climbspin
			player.climbspin = {}
		else
			local c = player.climbspin
			c.walltime = $ or 0
			c.wang = $ or 0
			c.holdwall = $ or 0
			
			if c.holdwall then c.holdwall = $-1 end
			
			c.walljump = $ or 0
			if c.walljump
				c.walljump = $-1
				
				if player.speed and (c.walljump%5) <= 0
					local momang = R_PointToAngle2(0,0,player.rmomx,player.rmomy)
					for i = 0,1
						local ax = P_ReturnThrustX(nil,momang+ANGLE_90+(ANGLE_180*i),mo.radius)
						local ay = P_ReturnThrustY(nil,momang+ANGLE_90+(ANGLE_180*i),mo.radius)
						
						local px = P_ReturnThrustX(nil,momang,mo.radius*3/2)
						local py = P_ReturnThrustY(nil,momang,mo.radius*3/2)
						
						local s = P_SpawnMobjFromMobj(mo,ax,ay,mo.height/2,MT_PARTICLE)
						s.state = S_CLIMBWALL_SPIN
						s.angle = R_PointToAngle2(s.x,s.y,mo.x+player.rmomx+px,mo.y+player.rmomy+py)
						s.color = (c.airjump and SKINCOLOR_RED) or SKINCOLOR_TEAL
						
						s.momx = mo.momx*2/3
						s.momy = mo.momy*2/3
						s.momz = mo.momz
					end
				end
				c.waswall = true
			elseif c.waswall
				c.waswall = false
				c.airjump = false
			end
			
			c.astate = $ or 0
			c.atime = $ or 0
			if c.astate
				c.atime = $+1
				
				local fy = 8
					local fx = 8
					
					local dy = (FRACUNIT-mo.spriteyscale)/fy
					local dx = (FRACUNIT-mo.spritexscale)/fx
					
					if dy then mo.spriteyscale = $+dy end
					if dx then mo.spritexscale = $+dx end
				if c.astate == 1
					player.drawangle = c.wang
					player.pflags = ($|PF_THOKKED|PF_JUMPED|PF_NOJUMPDAMAGE) &~(PF_STARTJUMP|PF_SPINNING)
					mo.state = S_PLAY_CLING
					P_InstaThrust(mo,player.drawangle,mo.scale)
					mo.momz = $/2
					
					if c.atime >= 12 and player.cmd.buttons & BT_JUMP
						c.astate = 2
						c.atime = 0
						
						P_SetObjectMomZ(mo,17*FRACUNIT)
						P_InstaThrust(mo,player.drawangle,-20*mo.scale)
						S_StartSound(mo,sfx_jump)
						
						mo.state = S_PLAY_JUMP
					end
				elseif c.astate == 2
					if c.holdwall
						player.drawangle = c.wang
						P_Thrust(mo,player.drawangle,6*mo.scale)
					
						c.walltime = $+1
						if (c.walltime%5) <= 0
							local ax = P_ReturnThrustX(nil,c.wang,mo.radius)
							local ay = P_ReturnThrustY(nil,c.wang,mo.radius)
							
							local hx = P_ReturnThrustX(nil,c.wang,mo.radius/2)
							local hy = P_ReturnThrustY(nil,c.wang,mo.radius/2)
							
							local rr = P_RandomRange(-FixedInt(mo.radius),FixedInt(mo.radius))*FRACUNIT
							local rx = P_ReturnThrustX(nil,c.wang+ANGLE_90,rr)
							local ry = P_ReturnThrustY(nil,c.wang+ANGLE_90,rr)
							
							local h = P_SpawnMobjFromMobj(mo,ax+rx,ay+ry,player.spinheight,MT_PARTICLE)
							h.state = S_CLIMBWALL_HOLD
							h.renderflags = $|RF_VERTICALFLIP
							
							local px = mo.x
							local py = mo.y
							h.angle = R_PointToAngle2(px+ax,py+ay,px+hx+rx,py+hy+ry)
							h.momz = player.mo.momz-((2*mo.scale)*P_MobjFlip(mo))
						end
					end
					
					P_SpawnThokMobj(player)
					player.pflags = ($|PF_THOKKED|PF_JUMPED) &~(PF_STARTJUMP|PF_NOJUMPDAMAGE|PF_SPINNING)
					if player.cmd.buttons & BT_JUMP	
						if c.holdwall
							P_InstaThrust(mo,player.drawangle,-20*mo.scale)
							player.drawangle = $+ANGLE_180
						else
							c.airjump = true
						end
						
						player.pflags = $&~PF_THOKKED
						c.walljump = 16
						
						c.astate = 0
						c.atime = 0
						
						mo.spritexscale = FRACUNIT
						mo.spriteyscale = FRACUNIT
					end
					
					if mo.momz*P_MobjFlip(mo) < 0
						c.astate = 0
						c.atime = 0
						
						mo.spritexscale = FRACUNIT
						mo.spriteyscale = FRACUNIT
					end
				end
			elseif c.atime
				c.atime = 0
			end
		end
	end
end)

local function CS_DoWallShit(player,ang,sec,line)
	local c = player.climbspin
	local mo = player.mo
	
	c.holdwall = 3
	if not P_IsObjectOnGround(mo)
	and not (player.pflags & PF_THOKKED)
		c.walltime = $+1
		if (c.walltime%5) <= 0
			local ax = P_ReturnThrustX(nil,ang,mo.radius)
			local ay = P_ReturnThrustY(nil,ang,mo.radius)
			
			local hx = P_ReturnThrustX(nil,ang,mo.radius/2)
			local hy = P_ReturnThrustY(nil,ang,mo.radius/2)
			
			local rr = P_RandomRange(-FixedInt(mo.radius),FixedInt(mo.radius))*FRACUNIT
			local rx = P_ReturnThrustX(nil,ang+ANGLE_90,rr)
			local ry = P_ReturnThrustY(nil,ang+ANGLE_90,rr)
			
			local h = P_SpawnMobjFromMobj(mo,ax+rx,ay+ry,0,MT_PARTICLE)
			h.state = S_CLIMBWALL_HOLD
			
			local px = mo.x
			local py = mo.y
			h.angle = R_PointToAngle2(px+ax,py+ay,px+hx+rx,py+hy+ry)
			h.momz = player.mo.momz+((2*mo.scale)*P_MobjFlip(mo))
		end
		if player.spicerspin == 0 and not (player.mo.eflags & MFE_UNDERWATER) and not P_IsObjectOnGround(player.mo) and player.cmd.buttons & BT_SPIN
			player.drawangle = ang
			mo.momz = $/2
			mo.state = S_PLAY_CLING
			
			c.astate = 1
			c.atime = 0
			S_StartSound(mo,sfx_s3k4a)
		end
	end
end

addHook("MobjMoveBlocked", function(mo,mobj,line) --Wall check
	if mo and mo.valid
	and not (mobj and mobj.valid and mobj.flags & (MF_MONITOR|MF_ENEMY|MF_BOSS))
	and mo.player and mo.player.valid
	and mo.skin == "thespicer" and mo.player.climbspin
	and not (mo.player.pflags & PF_STASIS)
	and mo.player.playerstate == PST_LIVE
		if not (mo.player and mo.player.valid) then return end
		if line and line.valid
			local player = mo.player
			local ang = (player.climbspin.climbing and player.climbspin.climbing.ang) or 0
			if PTR_GlideClimbTraverse(mo,line)
				local real,ang,sec = PTR_GlideClimbTraverse(mo,line)
				if (P_IsClimbingValid(mo.player,ang) or (mobj and mobj.valid))
					if mobj and mobj.valid then ang = R_PointToAngle2(mo.x,mo.y,mobj.x,mobj.y) or 0 end
					CS_DoWallShit(mo.player,ang,sec,line)
					mo.player.climbspin.wang = ang
				end
			end
		elseif mobj and mobj.valid
			local ang = R_PointToAngle2(mo.x,mo.y,mobj.x,mobj.y) or 0
			CS_DoWallShit(mo.player,ang)
			mo.player.climbspin.wang = ang
		end
	end
end,MT_PLAYER)