forked from Simnation/Main
ed
This commit is contained in:
parent
88ffeb3375
commit
87623c8379
27 changed files with 2865 additions and 1705 deletions
74
resources/[carscripts]/AdvancedParking/server/sv_utils.lua
Normal file
74
resources/[carscripts]/AdvancedParking/server/sv_utils.lua
Normal file
|
@ -0,0 +1,74 @@
|
|||
|
||||
-- returns if any player is inside a given vehicle
|
||||
function IsAnyPlayerInsideVehicle(vehicle, playerPeds)
|
||||
for i = 1, #playerPeds do
|
||||
local veh = GetVehiclePedIsIn(playerPeds[i], false)
|
||||
|
||||
if (DoesEntityExist(veh) and veh == vehicle) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- return the id and distance of the closest player
|
||||
function GetClosestPlayer(position, maxRadius, players, playerPedsWithHandles, bucket)
|
||||
local closestDistance = maxRadius or 1000.0
|
||||
local closestPlayer = nil
|
||||
|
||||
for i = 1, #players do
|
||||
if (GetPlayerRoutingBucket(players[i]) == bucket) then
|
||||
local distance = #(position - GetEntityCoords(playerPedsWithHandles[ players[i] ]))
|
||||
if (distance < closestDistance) then
|
||||
closestDistance = distance
|
||||
closestPlayer = players[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return closestPlayer, closestDistance
|
||||
end
|
||||
|
||||
-- return all player peds associated to their player handles
|
||||
function GetAllPlayerPedsWithHandles(players)
|
||||
local peds = {}
|
||||
|
||||
for i = 1, #players do
|
||||
local ped = GetPlayerPed(players[i])
|
||||
peds[players[i]] = DoesEntityExist(ped) and ped or nil
|
||||
end
|
||||
|
||||
return peds
|
||||
end
|
||||
|
||||
-- returns all currently loaded player peds
|
||||
function GetAllPlayerPeds()
|
||||
local playerPeds = {}
|
||||
|
||||
local players = GetPlayers()
|
||||
for i = 1, #players do
|
||||
local ped = GetPlayerPed(players[i])
|
||||
if (DoesEntityExist(ped)) then
|
||||
playerPeds[#playerPeds + 1] = ped
|
||||
end
|
||||
end
|
||||
|
||||
return playerPeds
|
||||
end
|
||||
|
||||
-- returns a list of all vehicles that are loaded and are registered within AP already
|
||||
function GetLoadedVehiclesWithId(vehicles)
|
||||
local list = {}
|
||||
|
||||
for i = 1, #vehicles do
|
||||
if (DoesEntityExist(vehicles[i])) then
|
||||
local id = Entity(vehicles[i])?.state?.ap_id
|
||||
if (id) then
|
||||
list[id] = vehicles[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return list
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue