--[[
Sonic boom v1.0 by Levin Heselhaus 
levinheselhaus@googlemail.com
]]--



local sonicboom = {}


local mod = false
local mod_toggle = false


function sonicboom.unload()

end
function sonicboom.init()

end

function sonicboom.tick()

local player = PLAYER.PLAYER_PED_ID()
local playerped = PLAYER.GET_PLAYER_PED(player)
local parastate = PED.GET_PED_PARACHUTE_STATE(player)
local velocity = ENTITY.GET_ENTITY_VELOCITY(player)
local speed = ENTITY.GET_ENTITY_SPEED(player)
local jumping = PED.IS_PED_JUMPING(player)
local falling = PED.IS_PED_FALLING(player)
local position = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player, 0, 0, 1)
local rotation = ENTITY.GET_ENTITY_ROTATION(player, 0)
local vehicle = PED.GET_VEHICLE_PED_IS_IN(player,true)
	if(get_key_pressed(Keys.F11) or CONTROLS.IS_CONTROL_PRESSED(2,187) and CONTROLS.IS_CONTROL_PRESSED(2,184))then 
		mod_toggle = true
	elseif mod_toggle then
		mod_toggle=false
				if(mod)then
					mod=false
					print("mod = false")
				else
					mod=true
					WEAPON.GIVE_DELAYED_WEAPON_TO_PED(player, 0xFBAB5776, 10, false)
					print("mod = true")
				end
	end
	if(mod)then
		UI.SET_TEXT_FONT(0)
		UI.SET_TEXT_SCALE(0.1, 0.35)
		UI.SET_TEXT_COLOUR(255, 255, 255, 255)
		UI.SET_TEXT_CENTRE(true)
		UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0)
		UI.SET_TEXT_EDGE(0, 0, 0, 0, 0)
		UI._SET_TEXT_ENTRY("STRING")
		UI._ADD_TEXT_COMPONENT_STRING("Sonic boom")
		UI._DRAW_TEXT(0.05,0.02)
		UI.SET_TEXT_FONT(0)
		UI.SET_TEXT_SCALE(0.1, 0.35)
		UI.SET_TEXT_COLOUR(255, 255, 255, 255)
		UI.SET_TEXT_CENTRE(true)
		UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0)
		UI.SET_TEXT_EDGE(0, 0, 0, 0, 0)
		UI._SET_TEXT_ENTRY("STRING")
		UI._ADD_TEXT_COMPONENT_STRING(speed)
		UI._DRAW_TEXT(0.15,0.02)
		ENTITY.SET_ENTITY_MAX_SPEED(player,500)
		PLAYER.SET_PLAYER_INVINCIBLE(player, true)
		GAMEPLAY.SET_SUPER_JUMP_THIS_FRAME(playerped)
		ENTITY.SET_ENTITY_INVINCIBLE(player, true)
		
		if(not falling and jumping and velocity.z > 0.5)then
			if(get_key_pressed(Keys.Space) or CONTROLS.IS_CONTROL_PRESSED(2,193))then
				ENTITY.SET_ENTITY_VELOCITY(player, velocity.x, velocity.y, velocity.z+0.3)
			end
		end
		
		if(parastate == 0 and speed < 40)then
			ENTITY.SET_ENTITY_VELOCITY(player, velocity.x*1.05, velocity.y*1.05, velocity.z)
		end
		
		velocity = ENTITY.GET_ENTITY_VELOCITY(player)
		if(parastate == 0 and speed < 80)then
			if(get_key_pressed(Keys.LControlKey) or CONTROLS.IS_CONTROL_PRESSED(2,185))then
				ENTITY.SET_ENTITY_VELOCITY(player, velocity.x*1.05, velocity.y*1.05, velocity.z*1.05)
			end
		end
		
		if(parastate == 0 and speed < 60)then
			if(get_key_pressed(Keys.LShiftKey) or CONTROLS.IS_CONTROL_PRESSED(2,183))then
				ENTITY.SET_ENTITY_VELOCITY(player, velocity.x*1.05, velocity.y*1.05, velocity.z*1.05)
			end
		end
		
		if(parastate == 0 and speed < 100)then
			if(get_key_pressed(Keys.LControlKey) and get_key_pressed(Keys.LShiftKey))then
				ENTITY.SET_ENTITY_VELOCITY(player, velocity.x*1.05, velocity.y*1.075, velocity.z*1.05)
			end
			if(CONTROLS.IS_CONTROL_PRESSED(2,183) and CONTROLS.IS_CONTROL_PRESSED(2,185))then
				ENTITY.SET_ENTITY_VELOCITY(player, velocity.x*1.05, velocity.y*1.075, velocity.z*1.05)
			end
		end
		
		velocity = ENTITY.GET_ENTITY_VELOCITY(player)
		if(parastate == 0 and velocity.z < 40)then
			if(get_key_pressed(Keys.S)or CONTROLS.IS_CONTROL_PRESSED(2,196))then
				ENTITY.SET_ENTITY_VELOCITY(player, velocity.x, velocity.y, velocity.z+1.5)
			end
		end
		
		if(speed > 45)then
			local Table,Count = PED.GET_PED_NEARBY_VEHICLES(player, 1)
			for k,v in ipairs(Table) do
				if(ENTITY.GET_ENTITY_SPEED(v) < (speed + 5))then
					local vpos = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(v, 0, 0, 1)
					local ppos = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player, 0, 0, 1)
					local distance = GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS(ppos.x,ppos.y,ppos.z,vpos.x,vpos.y,vpos.z,true)
					
					if(v ~= vehicle)then
						ENTITY.APPLY_FORCE_TO_ENTITY(v, 1, velocity.x/((distance+0)*3.5),velocity.y/((distance+0)*3.5),velocity.z/((distance+5)*3.5), 0,0,0, 1, false, true, true, true, true)
					end
					if(vpos.z < ppos.z and speed > 80)then
						ENTITY.APPLY_FORCE_TO_ENTITY(v, 1, 0,0,5/distance, 0,0,0, 1, false, true, true, true, true)
					end
				end
			end
		end
	end
end

return sonicboom