local songtable = {
  [01] = "_jimd1",
  [02] = "_jimd2",
}

local randomnum = P_RandomRange(1 , 5)



addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.skin ~= "jimmyharold" then
			continue
		end
		
		if not (player.cmd.buttons & BT_CUSTOM2) then
			player.emotapready = true
			player.emotapping = false
		elseif player.emotapready then
			player.emotapping = true
			player.emotapready = false
		else
			player.emotapping = false
		end
		local randomnum = P_RandomRange(1 , 2)
		if player.emotapping and not player.dothing and not player.exiting then
			player.dothing = true
			S_ChangeMusic(songtable[randomnum])
		elseif player.emotapping and player.dothing then
			player.dothing = false
			P_RestoreMusic(player)
			player.mo.state = S_PLAY_STND
		elseif player.dothing then
			player.pflags = $ |PF_FULLSTASIS
			if player.mo.state != S_PLAY_RSTRSONT then
				player.mo.state = S_PLAY_RSTRSONT
			end
		end
	end
end)

addHook("BotTiccmd", function(bot)
	local player = players[0]
	local mo = players[0].mo
	if player.exiting then 
		return
	end
	if bot.mo and player.mo.skin == "jimmyharold" and player and mo
		if player.dothing then
			if bot.mo.state != S_PLAY_RSTRSONT then
				bot.mo.state = S_PLAY_RSTRSONT
			elseif bot.mo.state == S_PLAY_RSTRSONT then
				bot.pflags = $ |PF_FULLSTASIS
			end
		elseif bot.mo.state == S_PLAY_RSTRSONT then
			bot.mo.state = S_PLAY_WALK
		end
	end
end)
