Skip to content

Instantly share code, notes, and snippets.

@cm8263
Created September 5, 2019 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cm8263/23e8cc81e3d3b953f00cd8af5f309173 to your computer and use it in GitHub Desktop.
Save cm8263/23e8cc81e3d3b953f00cd8af5f309173 to your computer and use it in GitHub Desktop.
Ped Flee Vehicle Script
-- Create new thread
Citizen.CreateThread(function()
-- Last Entity Ped aimed at
local LastEntity = nil
-- Last vehicle Ped aimed at
local LastVehicle = nil
-- Not used?
local Talking = false
-- Forever
while true do
-- Safe looping
Citizen.Wait(0)
-- Get the entity Ped is aiming at
local FoundEntity, AimedEntity = GetEntityPlayerIsFreeAimingAt(pid)
-- If the ped is aiming at the entity in the car, there is an entity in the car, and it's not an entity we are already dealing with, and they are in range(?)
if IsPlayerFreeAimingAtEntity(-1, AimedEntity) and FoundEntity and (LastEntity ~= AimedEntity or IsPedInAnyVehicle(AimedEntity, false)) and (Config.car_aim_flee_range == 0 or GetDistanceBetweenCoords(GetEntityCoords(aiment), GetEntityCoords(GetPlayerPed(-1)), false) <= Config.car_aim_flee_range) then
-- Set last entity so this only executes once per ped
LastEntity = AimedEntity
-- I guess these are commented out?
-- local x,y,z = table.unpack(GetEntityCoords(aiment))
-- DrawBox(x+1,y+1,z+1,x-1,y-1,z-1, 0, 255, 0, 200)
-- Get the vehicle the entity is driving
local EntityVehicle = GetVehiclePedIsIn(AimedEntity, false)
-- Save last vehicle entity is in
LastVehicle = EntityVehicle
-- If the vehicle exist, the vehicle is a vehicle, the entity exists, the entity is an entity, and the entity is not a real person.
if DoesEntityExist(EntityVehicle) and IsEntityAVehicle(EntityVehicle) and DoesEntityExist(FoundEntity) and IsEntityAPed(FoundEntity) and not IsPedAPlayer(AimedEntity) then
-- Get out slowly and don't close the door
TaskLeaveVehicle(AimedEntity, EntityVehicle, 256)
-- While they are still in the vehicle
while IsPedInAnyVehicle(AimedEntity, false) do
-- Wait until the ped is out of the vehicle
Citizen.Wait(0)
end
-- Once out, clear their tasks
ClearPedTasksImmediately(AimedEntity)
-- Set to 'AlwaysFight', is this what we want?
SetPedCombatAttributes(AimedEntity, 46, true)
-- Make sure they forget what is going on
SetBlockingOfNonTemporaryEvents(AimedEntity, true)
-- Animation
TaskPlayAnim(AimedEntity, "random@mugging3", "handsup_standing_base", 0, 0, -1, 49, 0, 0, 0, 0 )
-- Reset last vehicle
ResetPedLastVehicle(AimedEntity)
-- Wait for robbing(?)
Citizen.Wait(7500)
-- Stop animation
ClearPedTasksImmediately(AimedEntity)
-- Make them run away
TaskReactAndFleePed(AimedEntity, PlayerPedId())
end
end
end
end)
@cm8263
Copy link
Author

cm8263 commented Sep 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment