Hey, everybody I’ve been working on a script recently for our server so that players can steal cars from peds with a weapon. The script is suppose to work so when you aim your gun at the localped in vehicle, they step out, and put their hands up. you would then be able to rob them for their keys which would take about 5 seconds. the other idea is if you dont have a gun, you could try at opening a car door with a localped in it. there would be a 1/3 chance of opening the car (the localped left it “unlocked”). once the door opens, you rip them out normally and enter the car to “look for the keys” (another 1/3 success rate) for 5 seconds. the police would either be notified when you start looking for the keys, or when you start “robbing” the localped for their keys. we currently cant figure out the “give keys” function between players, so including that would be of great help with making this work im sure!
At the moment, in the current development stage for this script, i’ve manged to get it so when player is aiming gun at ped, they stop vehicle and leave there vehicle and put there hands up (Sort of).
I was stuck on the script at a certain point as ussually the NPC’s would jus hop out and flee instantly without displaying an animation, so I found a work around so when NPC exits car it performs TaskPedWander (Or some syntax like) so now the ped will stand there for 8 seconds then flee after timer, but adding that task now causes another problem of where the ped instantly TP’s out of the vehicle and the animation of hands up, only shows for a blink second at the begin and end of the Citizen.Wait()
Was just wondering if anybody more experienced than I am could help me out of this script, not too experienced my self, just starting learning Lua so some help would be very much appreciated.
Video of code in action: https://streamable.com/jf1b6
Current Stage Of Code:
Citizen.CreateThread(function()
local lastent = nil
local lastveh = nil
local talking = false
while true do
Citizen.Wait(0)
local pid = PlayerId()
local foundaiment, aiment = GetEntityPlayerIsFreeAimingAt(pid)
if IsPlayerFreeAiming(pid) and foundaiment and (lastent~=aiment or IsPedInAnyVehicle(aiment, false)) and (Config.car_aim_flee_range==0 or GetDistanceBetweenCoords(GetEntityCoords(aiment), GetEntityCoords(GetPlayerPed(-1)), false)<=Config.car_aim_flee_range) then
lastent=aiment
– 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)
local vehicle = GetVehiclePedIsIn(aiment, false)
lastveh = vehicle
if DoesEntityExist(vehicle) and IsEntityAVehicle(vehicle) and DoesEntityExist(aiment) and IsEntityAPed(aiment) and not IsPedAPlayer(aiment) then
TaskLeaveVehicle(aiment, vehicle, 46)
while IsPedInAnyVehicle(aiment,false) do Citizen.Wait(250); TaskLeaveVehicle(aiment, vehicle, 46)
ClearPedTasksImmediately(aiment)
Citizen.Wait(1)
SetPedCombatAttributes(aiment, 46, true)
SetPedFleeAttributes(aiment, 0, 0)
SetBlockingOfNonTemporaryEvents(aiment, true)
TaskPlayAnim(aiment,“random@mugging3”, “handsup_standing_base”, 0, 0, -1, 49, 0, 0, 0, 0 )
TaskWanderInArea(aiment, 0, 0, 0, 20, 100, 100)
ResetPedLastVehicle(aiment)
Citizen.Wait(7500)
ClearPedTasksImmediately(aiment)
TaskReactAndFleePed(aiment, PlayerPedId())
end
end
end
end
end)