Invoking can return nil

Added fallback for current resource, future proofing against require and fixing entities target property
This commit is contained in:
Mr.Crowley committed 2026-08-14 17:38:09 -05:00
1 parent a34c7ba245
commit ad8788bbfd
4 files changed
+11 -11

No files matched your search

+2 -2
View File
@@ -74,11 +74,11 @@ local logHandlers = {
end, end,
qb = function(message) qb = function(message)
TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetInvokingResource(), 'green', message, false) TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetInvokingResource() or GetCurrentResourceName(), 'green', message, false)
end, end,
ox_lib = function(message) ox_lib = function(message)
lib.logger(GetInvokingResource(), GetCurrentResourceName(), message) lib.logger(GetInvokingResource() or GetCurrentResourceName(), GetCurrentResourceName(), message)
end, end,
['built-in'] = function(message) ['built-in'] = function(message)
+5 -5
View File
@@ -104,7 +104,7 @@ end
function Target.AddLocalEntity(entities, options) function Target.AddLocalEntity(entities, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
ox_target:addLocalEntity(entities, options) ox_target:addLocalEntity(entities, options)
local resource = GetInvokingResource() local resource = GetInvokingResource() or GetCurrentResourceName()
resourceTargets.entities[resource] = resourceTargets.entities[resource] or {} resourceTargets.entities[resource] = resourceTargets.entities[resource] or {}
table.insert(resourceTargets.entities[resource], { entities = entities}) table.insert(resourceTargets.entities[resource], { entities = entities})
end end
@@ -122,7 +122,7 @@ end
function Target.AddNetworkedEntity(netids, options) function Target.AddNetworkedEntity(netids, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
ox_target:addEntity(netids, options) ox_target:addEntity(netids, options)
local resource = GetInvokingResource() local resource = GetInvokingResource() or GetCurrentResourceName()
resourceTargets.networkedEntities[resource] = resourceTargets.networkedEntities[resource] or {} resourceTargets.networkedEntities[resource] = resourceTargets.networkedEntities[resource] or {}
table.insert(resourceTargets.networkedEntities[resource], { netids = netids}) table.insert(resourceTargets.networkedEntities[resource], { netids = netids})
end end
@@ -140,7 +140,7 @@ end
function Target.AddModel(models, options) function Target.AddModel(models, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
ox_target:addModel(models, options) ox_target:addModel(models, options)
local resource = GetInvokingResource() local resource = GetInvokingResource() or GetCurrentResourceName()
resourceTargets.models[resource] = resourceTargets.models[resource] or {} resourceTargets.models[resource] = resourceTargets.models[resource] or {}
table.insert(resourceTargets.models[resource], { models = models}) table.insert(resourceTargets.models[resource], { models = models})
end end
@@ -167,7 +167,7 @@ function Target.AddBoxZone(name, coords, size, heading, options, debug)
debug = debug or targetDebug, debug = debug or targetDebug,
options = options, options = options,
}) })
table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() }) table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() or GetCurrentResourceName() })
return target return target
end end
@@ -185,7 +185,7 @@ function Target.AddSphereZone(name, coords, radius, options, debug)
debug = targetDebug or debug, debug = targetDebug or debug,
options = options options = options
}) })
table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() }) table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() or GetCurrentResourceName() })
return target return target
end end
+2 -2
View File
@@ -182,7 +182,7 @@ function Target.AddBoxZone(name, coords, size, heading, options, debug)
options = options, options = options,
distance = getLargestDistance(options), distance = getLargestDistance(options),
}) })
table.insert(targetZones, { name = name, creator = GetInvokingResource() }) table.insert(targetZones, { name = name, creator = GetInvokingResource() or GetCurrentResourceName() })
return name return name
end end
@@ -200,7 +200,7 @@ function Target.AddSphereZone(name, coords, radius, options, debug)
options = options, options = options,
distance = getLargestDistance(options), distance = getLargestDistance(options),
}) })
table.insert(targetZones, { name = name, creator = GetInvokingResource() }) table.insert(targetZones, { name = name, creator = GetInvokingResource() or GetCurrentResourceName() })
return name return name
end end
+2 -2
View File
@@ -142,7 +142,7 @@ function Target.AddBoxZone(name, coords, size, heading, options)
coords = coords, coords = coords,
options = options, options = options,
}) })
table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() }) table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() or GetCurrentResourceName() })
return target return target
end end
@@ -160,7 +160,7 @@ function Target.AddSphereZone(name, coords, radius, options, debug)
debug = targetDebug or debug, debug = targetDebug or debug,
options = options options = options
}) })
table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() }) table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() or GetCurrentResourceName() })
return target return target
end end