Patch blip issue, add param to blip, guard in removeped,

Patch blip error on bridge restart, add param to blip, guard in removeped, redid lib point functions (now much much much easier to work with,
This commit is contained in:
MrNewb committed 2025-03-07 11:45:39 -05:00
1 parent f5913a0c45
commit 6c18fd7a6c
1 file changed
+47 -43
+47 -43
View File
@@ -4,7 +4,6 @@ local spawnedPeds = {}
local ActivePoints = {} local ActivePoints = {}
Utility.CreateProp = function(model, coords, heading, networked) Utility.CreateProp = function(model, coords, heading, networked)
if networked == nil then networked = true end
Utility.LoadModel(model) Utility.LoadModel(model)
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
local propEntity = CreateObject(model, coords.x, coords.y, coords.z, networked, false, false) local propEntity = CreateObject(model, coords.x, coords.y, coords.z, networked, false, false)
@@ -14,30 +13,20 @@ Utility.CreateProp = function(model, coords, heading, networked)
end end
Utility.CreateVehicle = function(model, coords, heading, networked) Utility.CreateVehicle = function(model, coords, heading, networked)
if networked == nil then networked = true end
Utility.LoadModel(model) Utility.LoadModel(model)
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, networked, false) local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, networked, false)
SetVehicleHasBeenOwnedByPlayer(vehicle, true) SetVehicleHasBeenOwnedByPlayer(vehicle, true)
SetVehicleNeedsToBeHotwired(vehicle, false) SetVehicleNeedsToBeHotwired(vehicle, false)
SetModelAsNoLongerNeeded(model)
SetVehRadioStation(vehicle, "OFF") SetVehRadioStation(vehicle, "OFF")
SetModelAsNoLongerNeeded(model)
return vehicle, { networkid = NetworkGetNetworkIdFromEntity(vehicle) or 0, coords = GetEntityCoords(vehicle), heading = GetEntityHeading(vehicle), } return vehicle, { networkid = NetworkGetNetworkIdFromEntity(vehicle) or 0, coords = GetEntityCoords(vehicle), heading = GetEntityHeading(vehicle), }
end end
Utility.CreatePed = function(model, coords, heading, networked, clothing) Utility.CreatePed = function(model, coords, heading, networked, settings)
if networked == nil then networked = true end
Utility.LoadModel(model) Utility.LoadModel(model)
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
local spawnedEntity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, networked, false) local spawnedEntity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, networked, false)
if clothing then
for componentID, v in pairs(clothing) do
SetPedComponentVariation(spawnedEntity, componentID, v[1], v[2], 0)
end
end
FreezeEntityPosition(spawnedEntity, true)
SetEntityInvincible(spawnedEntity, true)
SetBlockingOfNonTemporaryEvents(spawnedEntity, true)
SetModelAsNoLongerNeeded(model) SetModelAsNoLongerNeeded(model)
table.insert(spawnedPeds, spawnedEntity) table.insert(spawnedPeds, spawnedEntity)
return spawnedEntity return spawnedEntity
@@ -48,17 +37,23 @@ Utility.StartBusySpinner = function(text)
BeginTextCommandBusyString(text) BeginTextCommandBusyString(text)
AddTextComponentSubstringPlayerName(text) AddTextComponentSubstringPlayerName(text)
EndTextCommandBusyString(0) EndTextCommandBusyString(0)
return true
end end
Utility.StopBusySpinner = function() Utility.StopBusySpinner = function()
if BusyspinnerIsOn() then BusyspinnerOff() end if BusyspinnerIsOn() then
BusyspinnerOff()
return true
end
return false
end end
Utility.CreateBlip = function(coords, sprite, color, scale, label, shortRange) Utility.CreateBlip = function(coords, sprite, color, scale, label, shortRange, displayType)
local blip = AddBlipForCoord(coords.x, coords.y, coords.z) local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
SetBlipSprite(blip, sprite or 8) SetBlipSprite(blip, sprite or 8)
SetBlipColour(blip, color or 3) SetBlipColour(blip, color or 3)
SetBlipScale(blip, scale or 0.8) SetBlipScale(blip, scale or 0.8)
SetBlipDisplay(blip, displayType or 2)
SetBlipAsShortRange(blip, shortRange) SetBlipAsShortRange(blip, shortRange)
AddTextEntry(label, label) AddTextEntry(label, label)
BeginTextCommandSetBlipName(label) BeginTextCommandSetBlipName(label)
@@ -71,7 +66,7 @@ Utility.RemoveBlip = function(blip)
local success = false local success = false
for i, storedBlip in ipairs(blipIDs) do for i, storedBlip in ipairs(blipIDs) do
if storedBlip == blip then if storedBlip == blip then
RemoveBlip(blip) RemoveBlip(storedBlip)
table.remove(blipIDs, i) table.remove(blipIDs, i)
success = true success = true
break break
@@ -104,7 +99,9 @@ end
Utility.RemovePed = function(entity) Utility.RemovePed = function(entity)
local success = false local success = false
DeleteEntity(entity) if DoesEntityExist(entity) then
DeleteEntity(entity)
end
for i, storedEntity in ipairs(spawnedPeds) do for i, storedEntity in ipairs(spawnedPeds) do
if storedEntity == entity then if storedEntity == entity then
table.remove(spawnedPeds, i) table.remove(spawnedPeds, i)
@@ -230,51 +227,58 @@ Utility.GetClosestPlayer = function(coords, distanceScope, includeMe)
return closestPlayer, closestDistance, GetPlayerServerId(closestPlayer) return closestPlayer, closestDistance, GetPlayerServerId(closestPlayer)
end end
-- register points ---This function is used to register a point on the map, functions are fired when in the distance/exiting the area
Utility.RegisterPoint = function(pointCoords, pointDistance, pointOnEnter, pointOnExit) ---@param pointID string
local enterZone = lib.points.new({ ---@param pointCoords table
coords = pointCoords, ---@param pointDistance number
---@param _onEnter function
---@param _onExit function
---@param _nearby function
Utility.RegisterPoint = function(pointID, pointCoords, pointDistance, _onEnter, _onExit, _nearby)
ActivePoints[pointID] = lib.points.new({
coords = pointCoords,
distance = pointDistance, distance = pointDistance,
onEnter = function(self) onEnter = function(self)
pointOnEnter(self) _onEnter(self)
end, end,
onExit = function(self) onExit = function(self)
pointOnExit(self) _onExit(self)
end, end,
nearby = function(self)
_nearby(self)
end
}) })
local pointID = Bridge.Ids.RandomLower(nil, 8)
ActivePoints[pointID] = enterZone
return enterZone, pointID
end end
-- Function to retrieve the enterZone using pointID -- Function to retrieve the zone by the pointID
---@param pointID string
Utility.GetPointById = function(pointID) Utility.GetPointById = function(pointID)
return ActivePoints[pointID] return ActivePoints[pointID]
end end
---@return table | nil
Utility.GetActivePoints = function()
return ActivePoints
end
---Pass the point ID to remove the point from the map
---@param pointID string
---@return boolean
Utility.RemovePoint = function(pointID) Utility.RemovePoint = function(pointID)
local point = ActivePoints[pointID] if not ActivePoints[pointID] then return false end
if point then ActivePoints[pointID]:remove()
--print("Removing point with ID " .. pointID) ActivePoints[pointID] = nil
point:remove() -- Call the remove method on the point (ensure this method stops all event listeners) return true
ActivePoints[pointID] = nil -- Remove from ActivePoints table
--print("Point removed successfully.")
return true
else
--print("Point with ID " .. pointID .. " not found.")
return false
end
end end
AddEventHandler('onResourceStop', function(resource) AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then if resource == GetCurrentResourceName() then
for _, blip in pairs(blipIDs) do for _, blip in pairs(blipIDs) do
if DoesBlipExist(blip.id) then if blip and DoesBlipExist(blip) then
RemoveBlip(blip.id) RemoveBlip(blip)
end end
end end
for _, ped in pairs(spawnedPeds) do for _, ped in pairs(spawnedPeds) do
if DoesEntityExist(ped) then if ped and DoesEntityExist(ped) then
DeleteEntity(ped) DeleteEntity(ped)
end end
end end