Files
community_bridge/modules/target/_default/client.lua
T
MrNewb 48f8122197 Remove cache and batch event libraries, update locales
Deleted the cache and batch event libraries from the codebase, including all related client, server, and shared files. Removed server-side particle library and associated client event handlers. Updated utility and clothing modules to remove cache dependencies. Improved utility logging and deprecated point functions with notices. Updated all locales to use a consistent 'PurchasedItem' message format and added Bulgarian (bg) translation. Bumped version to 0.13.1 in fxmanifest.
2025-12-23 19:27:27 -05:00

186 lines
5.3 KiB
Lua

---@diagnostic disable: duplicate-set-field
Target = Target or {}
Ids = Ids or Require("lib/utility/shared/ids.lua")
local InteractIds = {}
local function warnUser()
print("Currently Only Targeting Is Supported By Community Bridge, You Are Using A Resource That Requires The Target Module To Be Used.")
end
function Target.GetResourceName()
return "default"
end
function Target.GetCanInteract(id)
return InteractIds[id]
end
function Target.CreateCanInteract(cb)
if not cb then return end
local id = Ids.CreateUniqueId(InteractIds)
InteractIds[id] = {
id = id,
ableToInteract = -1,
onInteract = cb
}
return id
end
function Target.CanInteract(id, ...)
local interactData = InteractIds[id]
if not interactData then return true end
if interactData.ableToInteract == -1 then
local cb = interactData.onInteract
local canInteractStatus = cb(...)
interactData.ableToInteract = canInteractStatus and 1 or 0
SetTimeout(1000, function()
interactData.ableToInteract = -1
end)
end
return interactData.ableToInteract > 0
end
function Target.FixOptions(options)
for k, v in pairs(options) do
local action = v.onSelect or v.action
local select = function(entityOrData)
if type(entityOrData) == 'table' then
return action(entityOrData.entity)
end
return action(entityOrData)
end
options[k].onSelect = select
local optionsCanInteract = v.canInteract
if optionsCanInteract then
local id = Target.CreateCanInteract(optionsCanInteract)
v.canInteract = function(...)
return Target.CanInteract(id, ...)
end
end
end
return options
end
function Target.AddGlobalPlayer(options)
warnUser()
end
function Target.AddGlobalVehicle(options)
warnUser()
end
function Target.RemoveGlobalVehicle(options)
warnUser()
end
function Target.AddLocalEntity(entities, _options)
local fixedOptions = Target.FixOptions(_options)
if type(entities) == "string" or type(entities) == "number" then
entities = { entities }
end
for _, entity in pairs(entities) do
local id = Ids.RandomString()
local title = Language.Locale("target.title")
local menuData = { id = id, title = title, options = {} }
for k, v in pairs(fixedOptions) do
table.insert(menuData.options, {
title = title .. " " .. k,
description = Language.Locale("target.description"),
onSelect = function(selected, secondary, args)
if v.onSelect then
v.onSelect(selected, secondary, args)
end
end
})
end
Point.Register(id, entity, 5, nil, function()
local coords = GetEntityCoords(entity)
local sleep = 3000
local test = Language.Locale("target.interact")
CreateThread(function()
while DoesEntityExist(entity) do
Wait(sleep)
local distance = #(coords - GetEntityCoords(PlayerPedId()))
if distance < 2 then
sleep = 0
Utility.Draw3DHelpText(coords, test, 0.35)
if IsControlJustPressed(0, 38) then
Menu.Open(menuData, false)
end
else
sleep = 1000
end
end
end)
end,
function()
Point.Remove(id)
end, function()
--No need for this in this one
end)
end
end
function Target.AddModel(models, options)
warnUser()
end
function Target.AddBoxZone(name, coords, size, heading, options)
local fixedOptions = Target.FixOptions(options)
local id = Ids.RandomString()
local title = Bridge.Language.Locale("target.title")
local menuData = { id = id, title = title, options = {} }
for k, v in pairs(fixedOptions) do
table.insert(menuData.options, {
title = title .. " " .. k,
description = Bridge.Language.Locale("target.description"),
onSelect = function(selected, secondary, args)
if v.onSelect then
v.onSelect(selected, secondary, args)
end
end
})
end
local inZone = false
Point.Register(id, coords, 5, nil,
function()
local sleep = 3000
while inZone do
Wait(sleep)
local distance = #(coords - GetEntityCoords(PlayerPedId()))
if distance < 10 then
sleep = 0
Utility.Draw3DHelpText(coords, Bridge.Language.Locale("target.interact"), 0.35)
if IsControlJustPressed(0, 38) then
Menu.Open(menuData, false)
end
end
end
end,
function()
inZone = false
Point.Remove(id)
end,
function()
--No need for this in this one
end)
end
function Target.RemoveGlobalPlayer()
warnUser()
end
function Target.RemoveLocalEntity(entity)
warnUser()
end
function Target.RemoveModel(model)
warnUser()
end
function Target.RemoveZone(name)
warnUser()
end
return Target