-
-
Save cm8263/23e8cc81e3d3b953f00cd8af5f309173 to your computer and use it in GitHub Desktop.
Ped Flee Vehicle Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://forum.fivem.net/t/help-ped-flee-vehicle-script/774661