-
Notifications
You must be signed in to change notification settings - Fork 199
Open
Description
-- client side (inspired by addonsv)
function Admin:getVehicleInDirection( coordFrom, coordTo )
local rayHandle = CastRayPointToPoint( coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, GetPlayerPed( -1 ), 0 )
local _, _, _, _, vehicle = GetRaycastResult( rayHandle )
return vehicle
end
function Admin:getNearestVehicle(radius)
local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1),true))
local ped = GetPlayerPed(-1)
if IsPedSittingInAnyVehicle(ped) then
return GetVehiclePedIsIn(ped, true)
else
-- flags used:
--- 8192: boat
--- 4096: helicos
--- 4,2,1: cars (with police)
local veh = GetClosestVehicle(x+0.0001,y+0.0001,z+0.0001, radius+5.0001, 0, 8192+4096+4+2+1) -- boats, helicos
if not IsEntityAVehicle(veh) then veh = GetClosestVehicle(x+0.0001,y+0.0001,z+0.0001, radius+5.0001, 0, 4+2+1) end -- cars
return veh
end
end
function Admin:deleteVehicleInFrontOrInside(offset)
local ped = GetPlayerPed(-1)
local entity = nil
local entityexisted = false
if IsPedSittingInAnyVehicle(ped) then
entity = GetVehiclePedIsIn(ped, false)
else
entity = self:getVehicleInDirection(
GetEntityCoords(ped, 1),
GetOffsetFromEntityInWorldCoords(ped, 0.0, offset, 0.0)
)
end
if not entity or entity == 0 then
return false, nil
end
NetworkRequestControlOfEntity(entity)
local timeout = 2000
while timeout > 0 and not NetworkHasControlOfEntity(entity) do
Wait(100)
timeout = timeout - 100
end
SetEntityAsMissionEntity(entity, true, true)
timeout = 2000
while timeout > 0 and not IsEntityAMissionEntity(entity) do
Wait(100)
timeout = timeout - 100
end
local data = {}
if DoesEntityExist(entity) then
entityexisted = true
local model = GetEntityModel(entity)
local displaytext = GetDisplayNameFromVehicleModel(model)
data.veh = string.lower(displaytext or "unknown")
data.owner = DecorGetInt(entity, "vRP.owner")
Citizen.InvokeNative(0xEA386986E786A54F, Citizen.PointerValueIntInitialized(entity))
end
Wait(50)
if not DoesEntityExist(entity) and entityexisted then
data.pos = GetEntityCoords(PlayerPedId())
return true, data
end
if DoesEntityExist(entity) then
DeleteEntity(entity)
if DoesEntityExist(entity) then
return false, nil
else
return false, nil
end
else
return false, nil
end
end
-- an example of a server side function
local function m_deleteveh(menu)
local user = menu.user
local success, data = vRP.EXT.Admin.remote.deleteVehicleInFrontOrInside(user.source, 5.0)
if success and data then
if data.owner and data.owner > 0 and data.veh then
local tuser = vRP.users_by_cid[data.owner]
if tuser then
vRP.EXT.Garage.remote._removeOutVehicles(tuser.source, {[data.veh] = true})
end
end
end
end
gstsbsgb
Metadata
Metadata
Assignees
Labels
No labels