mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-17 14:06:02 +01:00
I am still alive
This commit is contained in:
@@ -31,6 +31,60 @@ function makeVeh(model, coords)
|
||||
return veh
|
||||
end
|
||||
|
||||
local distanceVehicles = {}
|
||||
--- Creates a vehicle that spawns when the player enters a designated polyzone area.
|
||||
---
|
||||
--- This function sets up a circular polyzone; when the player enters the zone, the vehicle is spawned,
|
||||
--- and when the player exits, the vehicle is deleted.
|
||||
---
|
||||
---@param data table A table containing vehicle data.
|
||||
--- - **vehicle** `string`: The model name or hash of the vehicle to spawn.
|
||||
--- - **coords** `vector4`: The coordinates where the vehicle will be placed. Should include x, y, z, and w (heading).
|
||||
---@param freeze boolean (optional) Whether to freeze the vehicle in place. Defaults to `false`.
|
||||
---@param synced boolean (optional) Whether the vehicle should be synced across clients. Defaults to `false`.
|
||||
function makeDistVehicle(data, radius, onEnter, onExit)
|
||||
local vehicle = nil
|
||||
local zoneId = keyGen() .. keyGen()
|
||||
local zone = createCirclePoly({
|
||||
name = zoneId,
|
||||
coords = vec3(data.coords.x, data.coords.y, data.coords.z),
|
||||
radius = radius,
|
||||
onEnter = function()
|
||||
vehicle = makeVeh(data.model, data.coords)
|
||||
if onEnter then
|
||||
debugPrint("makeDistVehicle onEnter running")
|
||||
onEnter(vehicle)
|
||||
end
|
||||
end,
|
||||
onExit = function()
|
||||
deleteVehicle(vehicle)
|
||||
if onExit then
|
||||
debugPrint("makeDistVehicle onExit running")
|
||||
onExit(vehicle)
|
||||
end
|
||||
end,
|
||||
debug = debugMode,
|
||||
})
|
||||
distanceVehicles[zoneId] = { zone = zone, vehicle = vehicle }
|
||||
return zoneId
|
||||
end
|
||||
|
||||
--- Removes a specific distance-based vehicle spawning zone.
|
||||
---
|
||||
---@param zoneId string The unique identifier of the zone to remove.
|
||||
function removeDistVehicleZone(zoneId)
|
||||
if distanceVehicles[zoneId].zone then
|
||||
removePolyZone(distanceVehicles[zoneId].zone) -- Adjust this if your polyzone library uses a different removal method.
|
||||
if distanceVehicles[zoneId].vehicle then
|
||||
deleteVehicle(distanceVehicles[zoneId].vehicle)
|
||||
end
|
||||
distanceVehicles[zoneId] = nil
|
||||
print("Removed polyzone for zoneId: " .. zoneId)
|
||||
else
|
||||
print("No zone found with zoneId: " .. zoneId)
|
||||
end
|
||||
end
|
||||
|
||||
--- Attempts to gain network control of a vehicle and set it as a mission entity.
|
||||
---
|
||||
--- This function forces synchronization of a vehicle with other players by requesting network control and setting the vehicle as a mission entity.
|
||||
@@ -67,6 +121,20 @@ function pushVehicle(entity)
|
||||
end
|
||||
end
|
||||
|
||||
--- Deletes a spawned vehicle.
|
||||
---
|
||||
---@param vehicle number The handle of the vehicle entity to delete.
|
||||
function deleteVehicle(vehicle)
|
||||
if vehicle then
|
||||
debugPrint("^6Bridge^7: ^2Destroying Vehicle^7: '^6" .. vehicle .. "^7'")
|
||||
if IsEntityAttachedToEntity(vehicle, PlayerPedId()) then
|
||||
SetEntityAsMissionEntity(vehicle)
|
||||
DetachEntity(vehicle, true, true)
|
||||
end
|
||||
DeleteVehicle(vehicle)
|
||||
end
|
||||
end
|
||||
|
||||
--- Cleans up all created vehicles when the resource stops.
|
||||
onResourceStop(function(r)
|
||||
for i = 1, #Vehicles do DeleteVehicle(Vehicles[i]) end
|
||||
|
||||
Reference in New Issue
Block a user