From 9ad8c6188c97033dbfb00dcc8c3225e918671f12 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:33:05 -0400 Subject: [PATCH] Drawtext for non target partial support --- lib/utility/client/utility.lua | 20 ++++++ modules/target/_defualt/client.lua | 97 +++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 2 deletions(-) diff --git a/lib/utility/client/utility.lua b/lib/utility/client/utility.lua index dcca2e6..2b7f62f 100644 --- a/lib/utility/client/utility.lua +++ b/lib/utility/client/utility.lua @@ -239,6 +239,26 @@ Utility.HelpText = function(text, duration) EndTextCommandDisplayHelp(0, false, true, duration or 5000) end +---This will display 3D help text at the specified coordinates. +---@param coords table +---@param text string +---@param scale number +Utility.Draw3DHelpText = function(coords, text, scale) + local onScreen, x, y = GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z) + if onScreen then + SetTextScale(scale or 0.35, scale or 0.35) + SetTextFont(4) + SetTextProportional(1) + SetTextColour(255, 255, 255, 215) + SetTextEntry("STRING") + SetTextCentre(1) + AddTextComponentString(text) + DrawText(x, y) + local factor = (string.len(text)) / 370 + DrawRect(x, y + 0.0125, 0.015 + factor, 0.03, 41, 11, 41, 100) + end +end + ---This will display a native help text on the screen. It will add a text entry and display it for the specified duration. ---@param text string Utility.NotifyText = function(text) diff --git a/modules/target/_defualt/client.lua b/modules/target/_defualt/client.lua index bc9b892..710c524 100644 --- a/modules/target/_defualt/client.lua +++ b/modules/target/_defualt/client.lua @@ -4,6 +4,20 @@ 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 +Target.FixOptions = function(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 + end + return options +end + Target.AddGlobalPlayer = function(options) warnUser() end @@ -17,15 +31,94 @@ Target.RemoveGlobalVehicle = function(options) end Target.AddLocalEntity = function(entities, _options) - warnUser() + 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 menuData = { id = id, title = "Options", options = {} } + for k, v in pairs(fixedOptions) do + table.insert(menuData.options, { + title = ("Option " .. k), + description = "No Description", + icon = v.icon or "fas fa-code-pull-request", + args = {}, + onSelect = function(selected, secondary, args) + if v.onSelect then + v.onSelect(selected, secondary, args) + end + end + }) + end + Point.Register(id, entity, 5, args, + function() + local coords = GetEntityCoords(entity) + local sleep = 3000 + while DoesEntityExist(entity) do + Wait(sleep) + local distance = #(coords - GetEntityCoords(PlayerPedId())) + if distance < 10 then + sleep = 0 + Utility.Draw3DHelpText(coords, "Press [E] To Interact", 0.35) + if IsControlJustPressed(0, 38) then + Menu.Open(menuData, false) + end + else + sleep = 3000 + end + end + end, + function() + Point.Remove(id) + end, function() + --No need for this in this one + end) + end end + Target.AddModel = function(models, options) warnUser() end Target.AddBoxZone = function(name, coords, size, heading, options) - warnUser() + local fixedOptions = Target.FixOptions(_options) + local id = Ids.RandomString() + local menuData = { id = id, title = "Options", options = {} } + for k, v in pairs(fixedOptions) do + table.insert(menuData.options, { + title = ("Option " .. k), + description = "No Description", + onSelect = function(selected, secondary, args) + if v.onSelect then + v.onSelect(selected, secondary, args) + end + end + }) + end + Point.Register(id, coords, 5, args, + function() + local sleep = 3000 + while true do + Wait(sleep) + local distance = #(coords - GetEntityCoords(PlayerPedId())) + if distance < 10 then + sleep = 0 + Utility.Draw3DHelpText(coords, "Press [E] To Interact", 0.35) + if IsControlJustPressed(0, 38) then + Menu.Open(menuData, false) + end + else + sleep = 3000 + end + end + end, + function() + Point.Remove(id) + end, function() + --No need for this in this one + end) end Target.RemoveGlobalPlayer = function()