//hello

//sky chase level code
//i suer do lov ato scrawlwer levews is a fats gaem!
addHook("PlayerThink", function(player)
	if player.mo.valid and not player.exiting and player.playerstate == PST_LIVE then
		if gamemap == 628 or gamemap == 629 then
			player.scflyangle = $ or player.mo.angle
			player.mo.angle = player.scflyangle
			if player.mo.state == S_PLAY_PAIN or player.scflystunned then
				print("ohno!,hit!")
				player.scflystunned = true
				player.scflystun = $ + 1
				player.mo.state = S_PLAY_PLANERIDE
				if player.scflystun >= (1*TICRATE)/2 then
					player.scflystunned = false
					player.scflystun = 0
				end
			else
				P_InstaThrust(player.mo ,player.scflyangle ,player.scflysped)
				P_Thrust(player.mo ,(player.scflyangle - 90*ANG1), ((((player.cmd.sidemove/player.scflymoveaccel)*2)/(5/2))*FRACUNIT))
				player.mo.rollangle = 0 - (player.cmd.sidemove*ANG1)
				P_SetObjectMomZ(player.mo, ((((player.cmd.forwardmove/player.scflymoveaccel)*2)/(5/2))*FRACUNIT), false)
				player.mo.state = S_PLAY_PLANERIDE
			end
		end
	end
end)

//acceleration value thingies
addHook("PlayerThink", function(player)
	if player.mo.valid and not player.exiting and player.playerstate == PST_LIVE then
		if gamemap == 628 or gamemap == 629 then
			if player.cmd.sidemove or player.cmd.forwardmove then
				if player.scflymoveaccel >= 4 then
					player.scflymoveaccel = ($ /4)*3
					print(player.scflymoveaccel)
				else
					player.scflymoveaccel = 3
				end
			else
				player.scflymoveaccel = 50
			end
		end
	end
end)

//WALL COLLISION
addHook("MobjMoveBlocked", function(jo)
    if not jo.player then return end
	if jo.player.valid then
		local player = players[0]
		local mo = players[0].mo
		if gamemap == 628 or gamemap == 629 then
			P_DamageMobj(player.mo)
		end
	end
end)

addHook("PlayerSpawn", function(player)
	player.scflyangle = nil
	player.scflystunned = false
	player.scflystun = 0
	player.scflymoveaccel = 50
	player.scusecooldown = 0
	player.scfiring = false
	player.jimded = 0
	player.scflysped = 15*FRACUNIT
	player.scmachspeed = false
end)

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.valid and gamemap == 628 or gamemap == 629 then
			if not (player.cmd.buttons & BT_JUMP) then
				player.dodgetapready = true
				player.dodgetapping = false
			elseif player.dodgetapready then
				player.dodgetapping = true
				player.dodgetapready = false
			else
				player.dodgetapping = false
			end
			
			if not (player.cmd.buttons & BT_SPIN) then
				player.firetapready = true
				player.firetapping = false
			elseif player.firetapready then
				player.firetapping = true
				player.firetapready = false
			else
				player.firetapping = false
			end
		end
	end
end)

//scripted event: "Going Down!!!" (or rather fast)
addHook("PlayerThink", function(player)
	if player.mo.valid and not player.exiting and player.playerstate == PST_LIVE then
		if gamemap == 629 then
			if player.mo.subsector.sector.tag == 6 
			and not player.scmachspeed then
				player.scflysped = 30*FRACUNIT
				player.scflyangle = ANG1
				P_TeleportMove(player.mo, 768, player.mo.y, player.mo.z)
				player.rings = 0
				player.scmachspeed = true
			end
		end
	end
end)
			
addHook("SpinSpecial", function(player)
    if player.scflyangle != nil then 
		if (leveltime % 5 == 0) then
			local projectile = P_SpawnPlayerMissile(player.mo, 	MT_JETTBULLET)
			S_StartSound(player.mo, sfx_trfire)
			if projectile.valid then
				projectile.fuse = TICRATE
				P_InstaThrust(projectile ,player.scflyangle ,player.scflysped*4)
			end
		end
    end
end)
			