
-- Smooth Trail script by ffoxD.
-- i crediting them because they are way past cool!
local function SmoothTrail(mo, trailmo, freq)
    -- Real Z momentum thingy plus leveltime checks.
    -- You can replace all this with mo.momz+mo.pmomz but that stays at 0 when on slopes and on ground.
    if not mo.prevz or not mo.prevleveltime or (mo.prevleveltime ~= leveltime - 1) then
       mo.prevz = mo.z
    end
    local rmomz = mo.z - mo.prevz
    mo.prevz = mo.z
    mo.prevleveltime = leveltime
    -- Handy local variables.
    local mospeed = R_PointToDist2(0, 0, R_PointToDist2(0, 0, mo.momx, mo.momy), rmomz)
    local dist = (mospeed/freq)
    -- The loop, repeats until it spawns all the thok objects.
    for i = dist, 1, -1 do
        local spawnedmo = P_SpawnMobjFromMobj(mo, (mo.momx/dist)*i, (mo.momy/dist)*i, (rmomz/dist)*i, trailmo)
        spawnedmo.color = mo.color
        spawnedmo.blendmode = AST_ADD -- blend
    end
end

//star dash
addHook("PlayerThink", function(player)
	if player.mo.valid and player.mo.skin == "m.jimmyharold" then
		if not (player.cmd.buttons & BT_CUSTOM1) then
			player.c1tapready = true
			player.c1tapping = false
		elseif player.c1tapready then
			player.c1tapping = true
			player.c1tapready = false
		else
			player.c1tapping = false
		end
	
		if not (player.cmd.buttons & BT_WEAPONNEXT) then
			player.rtapready = true
			player.rtapping = false
		elseif player.rtapready then
			player.rtapping = true
			player.rtapready = false
		else
			player.c1tapping = false
		end
		
		if not (player.cmd.buttons & BT_WEAPONPREV) then
			player.ltapready = true
			player.ltapping = false
		elseif player.ltapready then
			player.ltapping = true
			player.ltapready = false
		else
			player.ltapping = false
		end
		
		if player.c1tapping and not player.exiting then
			if player.sit and player.jimwallrun <= 52 then
				player.rundaon = true
				player.jimwallrun = $ + 52
			elseif not player.sit then
				if player.rundash >= 1 and not (player.cmd.buttons & BT_JUMP)
				and player.jimwallrun <= 78 then
					player.rundaon = false
					P_InstaThrust(player.mo ,player.mo.angle, (player.rundash*FRACUNIT))
					S_StartSound(player.mo, sfx_zoom)
					S_StartSound(player.mo, sfx_bsnipe)
					player.jimwallrun = $ + 25
					player.rundash = 0
					player.mo.colorized = false
					if not (player.powers[pw_super])
						player.mo.color = player.skincolor
					end
				elseif player.rundash >= 1 and (player.cmd.buttons & BT_JUMP) 
				and player.jimwallrun <= 78 then
					player.rundaon = false
					P_SetObjectMomZ(player.mo, (player.rundash*FRACUNIT/4), false)
					player.mo.state = S_PLAY_LAUNCHFIRE
					S_StartSound(player.mo, sfx_zoom)
					S_StartSound(player.mo, sfx_s3k46)
					player.jimwallrun = $ + 25
					player.rundash = 0
					player.mo.colorized = false
					if not (player.powers[pw_super])
						player.mo.color = player.skincolor
					end
				end
			elseif not player.sit then
				
			end
		elseif player.rundaon then
			if player.rundash <= 150 then
				player.rundash = $ + 1
				if (leveltime % 17 == 0)
					S_StartSound(player.mo, sfx_spndsh)
				end
			elseif player.rundash >= 140 then
				player.mo.colorized = false
				player.smakuse = true
				if (leveltime % 2 == 0) then
					player.mo.colorized = true
					player.mo.color = SKINCOLOR_KETCHUP
				elseif player.mo.state != S_PLAY_DEAD and player.mo.state != S_PLAY_RUN and player.mo.state != S_PLAY_SNEAKERWORRY then
					player.mo.state = S_PLAY_WALK
				end
			end
		else
			player.rundash = 0
		end
	end
end)



local JIMDRAW = function(v, player, cam)
	if player.mo and player.mo.valid and player.mo.skin == "m.jimmyharold" then
		if player.rundash != nil and player.rundash >= 140 then
			v.draw(16, 75, v.cachePatch("JIM"))
			v.drawString(27, 87, "READY!", V_YELLOWMAP)
		end
	end
end
	
hud.add(JIMDRAW, "game")

//laser!!!
//input thingy
addHook("PlayerThink", function(player)
	if player.mo.valid and player.mo.skin == "m.jimmyharold" and G_RingSlingerGametype() then
		if not (player.cmd.buttons & BT_ATTACK) then
			player.firetapready = true
			player.firetapping = false
		elseif player.firetapready then
			player.firetapping = true
			player.firetapready = false
		else
			player.firetapping = false
		end
	end
end)

local LaserAimObj = nil
local LaserBurstObj = nil
local AimerPos = nil

addHook("PlayerThink", function(player)
	if player.mo.valid and player.mo.skin == "m.jimmyharold" then
		if player.jimlasercyan or player.firetapping then
			player.jimlasercyan = true
			player.jimlasertimer = $ or 0
			player.jimlasertimer = $ + 1
			if player.jimlasertimer < 3 *TICRATE then
				player.mo.momx = 0
				player.mo.momy = 0
				player.mo.momz = 0
				player.mo.state = S_PLAY_ROLL
				if player.jimlasertimer == 2 then
					LaserAimObj = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z + (player.height/2), MT_CPCLJIMAIN)
				elseif LaserAimObj.valid and LaserAimObj then
					LaserAimObj.z = player.mo.z
					LaserAimObj.renderflags = $|RF_FLOORSPRITE
					LaserAimObj.angle = player.drawangle
				end
				S_ChangeMusic("laserj", true, player)
			elseif player.jimlasertimer > 3 *TICRATE 
			and player.jimlasertimer < 4 *TICRATE then
				player.mo.state = S_PLAY_COLOURPOWER
				player.mo.momz = 0
				P_InstaThrust(player.mo ,player.drawangle, (256*FRACUNIT))
				SmoothTrail(player.mo, MT_CPCLJIMSQUARE, 16*FRACUNIT)
			elseif player.jimlasertimer > 4 *TICRATE then
				LaserBurstObj = P_SpawnParaloop(player.mo.x, player.mo.y, player.mo.z + (player.height/2), 512*FRACUNIT, 16, MT_CPCLJIMSQUARE, 0, nil, true)
				LaserBurstObj = P_SpawnParaloop(player.mo.x, player.mo.y, player.mo.z + (player.height/2), 512*FRACUNIT, 16, MT_CPCLJIMSQUARE, 90*ANG1, nil, true)
				LaserBurstObj = P_SpawnParaloop(player.mo.x, player.mo.y, player.mo.z + (player.height/2), 512*FRACUNIT, 16, MT_CPCLJIMSQUARE, 45*ANG1, nil, true)
				LaserBurstObj = P_SpawnParaloop(player.mo.x, player.mo.y, player.mo.z + (player.height/2), 512*FRACUNIT, 16, MT_CPCLJIMSQUARE, 0 - 45*ANG1, nil, true)
				if LaserBurstObj and LaserBurstObj.valid then
					LaserBurstObj.scale = LaserBurstObj.scale
					P_InstaThrust(LaserBurstObj ,player.drawangle, (64*FRACUNIT))
				end
				player.mo.momx = 0
				player.mo.momy = 0
				player.mo.momz = 0
				player.jimlasertimer = 0
				player.jimlasercyan = false
				player.mo.state = S_PLAY_FALL
				P_RestoreMusic(player)
			end
		end
	end
end)

addHook("PlayerThink", function(player)
	if player.mo.valid and player.mo.skin == "m.jimmyharold" then
		if player.jimlasercyan then
			if player.jimlasertimer < 3 *TICRATE then
				if (player.cmd.buttons & BT_ATTACK) and player.jimlasertimer > 2 *TICRATE then
					player.jimlasertimer = 75
				end
			end
		end
	end
end)

addHook("MobjMoveBlocked", function(mo)
	if mo.valid and mo.player then
		if mo.player.skin == "m.jimmyharold" then
			if mo.player.jimlasercyan then
				mo.angle = $ + (180*ANG1)
				mo.player.drawangle = $ + (180*ANG1)
				mo.player.jimlasertimer = 106
			end
		end
	end
end)


//atk stuf
addHook("PlayerCanDamage", function(player, mobj)
	if player.mo and player.mo.valid and player.jimlasertimer != nil and player.jimlasertimer > 3 *TICRATE then
	return true end
end)

//switch
addHook("PlayerThink", function(player)
	if player.mo.valid and player.mo.skin == "m.jimmyharold" then
		if (player.powers[pw_carry] & CR_ROPEHANG) or player.speed > 30*FRACUNIT then
			if (player.cmd.buttons & BT_WEAPONNEXT) then
				P_Thrust(player.mo, player.drawangle - (90*ANG1), 30*FRACUNIT)
				player.powers[pw_carry] = CR_NONE
				player.mo.momz = 5*FRACUNIT
				player.mo.state = S_PLAY_JUMP
				player.powers[pw_ignorelatch] = 1
				player.mo.momz = 3*FRACUNIT
			elseif (player.cmd.buttons & BT_WEAPONPREV) then
				P_Thrust(player.mo, player.drawangle + (90*ANG1), 30*FRACUNIT)
				player.powers[pw_carry] = CR_NONE
				player.mo.momz = 5*FRACUNIT
				player.mo.state = S_PLAY_JUMP
				player.powers[pw_ignorelatch] = 1
				player.mo.momz = 3*FRACUNIT
			end
		end
	end
end)
			

		
		
		