freeslot("MT_TAUNT","S_TAUNT","SPR_TANT","sfx_taunt","S_PLAY_TAUNT1","S_PLAY_TAUNT2","S_PLAY_TAUNT3","S_PLAY_TAUNT4","S_PLAY_TAUNT5","S_PLAY_TAUNT6","S_PLAY_TAUNT7","S_PLAY_TAUNT8","S_PLAY_TAUNT9","S_PLAY_TAUNT10","S_PLAY_TAUNT11","S_PLAY_TAUNT12","S_PLAY_TAUNT13","S_PLAY_TAUNT14","SPR2_TAU1","SPR2_TAU2","SPR2_TAU3","SPR2_TAU4","SPR2_TAU5","SPR2_TAU6","SPR2_TAU7","SPR2_TAU8","SPR2_TAU9","SPR2_TA10","SPR2_TA11","SPR2_TA12","SPR2_TA13","SPR2_TA14")
sfxinfo[sfx_taunt].caption = "Taunt"

states[S_PLAY_TAUNT1] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU1,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT2] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU2,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT3] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU3,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT4] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU4,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT5] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU5,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT6] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU6,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT7] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU7,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT8] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU8,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT9] = {
	sprite = SPR_PLAY,
	frame = SPR2_TAU9,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT10] = {
	sprite = SPR_PLAY,
	frame = SPR2_TA10,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT11] = {
	sprite = SPR_PLAY,
	frame = SPR2_TA11,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT12] = {
	sprite = SPR_PLAY,
	frame = SPR2_TA12,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT13] = {
	sprite = SPR_PLAY,
	frame = SPR2_TA13,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

states[S_PLAY_TAUNT14] = {
	sprite = SPR_PLAY,
	frame = SPR2_TA14,
	tics = -1,
	nextstate = S_PLAY_TAUNT1
}

addHook("ThinkFrame", do
	for p in players.iterate
		if not (p.cmd.buttons & BT_TOSSFLAG)
		and not p.taunting
		and p.mo and p.mo.valid
		p.prevmomx = p.mo.momx
			p.prevmomy = p.mo.momy
			p.prevmomz = p.mo.momz
			p.prevstate = p.mo.state
			p.prevmachcounter = p.machcounter
		end
		if p.tftics == nil
			p.tftics = 0
		end
		if (p.cmd.buttons & BT_TOSSFLAG)
			p.tftics = $1+1
		else
			p.tftics = 0
		end
	end
end)

freeslot("sfx_promot")
sfxinfo[sfx_promot].caption = "Caption" 

local function removebubble(mo)
	if mo and mo.valid
		P_RemoveMobj(mo)
	end
end

addHook("ThinkFrame", do
	for p in players.iterate
		
		if p.tauntingtimer == nil
			p.tauntingtimer = 0
		end
		
		if p.tftics == 1
		and not p.taunting
		and p.mo.state ~= S_PLAY_SHOULDERBASHSTART
		and p.mo and p.mo.valid
		and not p.powers[pw_carry]
		and p.playerstate == PST_LIVE
		and not P_PlayerInPain(p)
		and not p.powers[pw_nocontrol]
		and not p.grabbing
		and not p.assonfire
		and not (p.pflags & PF_STASIS)
		and not p.bodyslam
		and not (p.pflags & PF_SPINNING)
		and not p.kungfu
		and not p.ptwallrun
		and not p.divecancel
		and p.mo.state ~= S_PLAY_CELHIT
		and not p.bodyslamstart
		and not (p.pflags & PF_SPINNING)
		and p.mo.state ~= S_PLAY_PP_SUPERJUMP
		and not p.superpp
		and p.mo.state ~= S_PLAY_REDIRECTFALL
		and not P_UpperCutAnimation(p)
		and p.mo.state ~= S_PLAY_REDIRECTSTART1
		and p.mo.state ~= S_PLAY_REDIRECTSTART2
		and p.mo.state ~= S_PLAY_REDIRECTSTART3
		and p.mo.state ~= S_PLAY_REDIRECTSTART4
		and p.mo.state ~= S_PLAY_PARRY1
		and p.mo.state ~= S_PLAY_PP_REDIRECT
		and (p.mo.state ~= S_PLAY_PARRY1 or p.mo.state ~= S_PLAY_PARRY2 or p.mo.state ~= S_PLAY_PARRY3)
		and p.mo.state ~= S_PLAY_BODYLAND
		and p.mo.state ~= S_PLAY_PP_WALLCLIMB
		and p.ppc
			S_StartSound(p.mo, sfx_taunt)
			p.taunting = true
		end
		if p.taunting == nil
			p.taunting = false
		end
		if p.taunting == true
			p.shouldmach3 = false
			p.mo.momx = 0
			p.mo.momy = 0
			p.mo.momz = 0
			p.grabbing = false
			p.grabtics = 0
			p.powers[pw_nocontrol] = 150000000000
			p.pflags = $|PF_JUMPSTASIS
			p.tauntingtimer = $1+1
			if not p.tauntbubble
				p.tauntbubble = P_SpawnMobj(p.mo.x,p.mo.y,p.mo.z,MT_TAUNT)
				p.tauntbubble.scale = p.mo.scale-FRACUNIT/5
				p.tauntbubble.target = p.mo
			end
			if p.tauntbubble and p.tauntbubble.valid
				p.tauntbubble.target = p.mo
				P_SetOrigin(p.tauntbubble,p.mo.x,p.mo.y,p.mo.z)
			end
			if (p.mo.eflags & MFE_VERTICALFLIP)
			and p.tauntbubble and p.tauntbubble.valid
				p.tauntbubble.eflags = $|MFE_VERTICALFLIP
				p.tauntbubble.flags2 = $|MF2_OBJECTFLIP
			end
			if p.tauntingtimer == 16
				removebubble(p.tauntbubble)
				p.tauntbubble = nil
				p.powers[pw_nocontrol] = 0
				p.taunting = false
				p.tauntingtimer = 0
				p.pflags = $ & ~PF_JUMPSTASIS
				p.mo.momz = p.prevmomz
				p.mo.state = p.prevstate
				p.mo.momx = p.prevmomx
				p.mo.momy = p.prevmomy
				p.machcounter = p.prevmachcounter
			end
		end
	end
end)

addHook("PlayerSpawn", function(p)
	p.taunting = false
	p.tauntingtimer = 0
end)

//made by clairbun
rawset(_G, "L_Choose", function(...)
	local args = {...}
	local choice = P_RandomRange(1,#args)
	return args[choice]
end)

addHook("PlayerThink", function(p)
	if p.cantdofunny == nil
		p.cantdofunny = false
	end
	if p.taunting
	and p.mo.state ~= S_PLAY_TAUNT1
	and p.mo and p.mo.valid
	and p.mo.state ~= S_PLAY_TAUNT2
	and p.mo.state ~= S_PLAY_TAUNT3
	and p.mo.state ~= S_PLAY_TAUNT4
	and p.mo.state ~= S_PLAY_TAUNT5
	and p.mo.state ~= S_PLAY_TAUNT6
	and p.mo.state ~= S_PLAY_TAUNT7
	and p.mo.state ~= S_PLAY_TAUNT8
	and p.mo.state ~= S_PLAY_TAUNT9
	and p.mo.state ~= S_PLAY_TAUNT10
	and p.mo.state ~= S_PLAY_TAUNT11
	and p.mo.state ~= S_PLAY_TAUNT12
	and p.mo.state ~= S_PLAY_TAUNT13
	and p.mo.state ~= S_PLAY_TAUNT14
		p.mo.state = L_Choose(S_PLAY_TAUNT1,S_PLAY_TAUNT2,S_PLAY_TAUNT3,S_PLAY_TAUNT4,S_PLAY_TAUNT5,S_PLAY_TAUNT6,S_PLAY_TAUNT7,S_PLAY_TAUNT8,S_PLAY_TAUNT9,S_PLAY_TAUNT10,S_PLAY_TAUNT11,S_PLAY_TAUNT12,S_PLAY_TAUNT13,S_PLAY_TAUNT14)
	end
	if p.mo.state == S_PLAY_TAUNT13
	and not p.cantdofunny
	and p.taunting
		S_StartSound(p.mo, sfx_promot)
		p.cantdofunny = true
	end
	if not p.taunting
		p.cantdofunny = false
	end
end)
	
addHook("PlayerSpawn", function(p)
	p.tauntbubble = nil
end)