-- Init player infos
local ply = GetPlayerPed(-1)
local pCoords = GetEntityCoords(ply, true)
local px, py, pz = table.unpack(GetEntityCoords(ply, true))
isInside = false
-- Retrieve the local ID of the targeted vehicle
if(IsPedInAnyVehicle(ply, true))then
-- by sitting inside him
localVehId = GetVehiclePedIsIn(GetPlayerPed(-1), false)
isInside = true
else
-- by targeting the vehicle
localVehId = GetTargetedVehicle(pCoords, ply)
end
-- Get targeted vehicle infos
if(localVehId and localVehId ~= 0)then
local localVehPlate = string.lower(GetVehicleNumberPlateText(localVehId))
local localVehLockStatus = GetVehicleDoorLockStatus(localVehId)
local hasKey = false
-- If the vehicle appear in the table (if this is the player's vehicle or a locked vehicle)
for plate, vehicle in pairs(vehicles) do
if(string.lower(plate) == localVehPlate)then
-- If the vehicle is not locked (this is the player's vehicle)
if(vehicle ~= "locked")then
hasKey = true
if(time > timer)then
-- update the vehicle infos (Useful for hydrating instances created by the /givekey command)
vehicle.update(localVehId, localVehLockStatus)
-- Lock or unlock the vehicle
vehicle.lock()
time = 0
else
TriggerEvent("ls:notify", "You have to wait " .. (timer / 1000) .." seconds")
end
else
TriggerEvent("ls:notify", "The keys aren't inside")
end
end
end
-- If the player doesn't have the keys
if(not hasKey)then
-- If the player is inside the vehicle
if(isInside)then
-- If the player find the keys
if(canSteal())then
-- Check if the vehicle is already owned.
-- And send the parameters to create the vehicle object if this is not the case.
TriggerServerEvent('ls:checkOwner', localVehId, localVehPlate, localVehLockStatus)
else
-- If the player doesn't find the keys
-- Lock the vehicle (players can't try to find the keys again)
vehicles[localVehPlate] = "locked"
TriggerServerEvent("ls:lockTheVehicle", localVehPlate)
TriggerEvent("ls:notify", "The keys aren't inside")
end
end
end
end