From 45c5af8e817b6146c9d99496d5f1d10915a2e069 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Tue, 22 Apr 2025 19:16:31 +0100 Subject: [PATCH] Fix duplicate functions and typos --- shared/callback.lua | 18 ++- shared/crafting.lua | 44 +++--- shared/isAnimal.lua | 4 - shared/make/makeVeh.lua | 36 ----- shared/playerfunctions.lua | 2 +- shared/scaleforms/instructionalButtons.lua | 43 +++++- shared/scaleforms/scaleform_basic.lua | 168 --------------------- shared/stashcontrol.lua | 4 +- shared/targets.lua | 3 +- shared/vehicles.lua | 2 +- 10 files changed, 85 insertions(+), 239 deletions(-) diff --git a/shared/callback.lua b/shared/callback.lua index f0cbf46..f60f106 100644 --- a/shared/callback.lua +++ b/shared/callback.lua @@ -8,8 +8,18 @@ --- ---@usage --- ```lua +--- local table = { ["info"] = "HI" } --- createCallback('myCallback', function(source, ...) ---- -- Your callback code here +--- return table +--- end) +--- +--- createCallback("callback:checkVehicleOwned", function(source, plate) +--- local result = isVehicleOwned(plate) +--- if result then +--- return true +--- else +--- return false +--- end --- end) --- ``` function createCallback(callbackName, funct) @@ -46,7 +56,11 @@ end --- ---@usage --- ```lua ---- local result = triggerCallback('myCallback', arg1, arg2) +--- local result = triggerCallback('myCallback') +--- jsonPrint(result) +--- +--- local result = triggerCallback("callback:checkVehicleOwned", plate) +--- print(result) --- ``` function triggerCallback(callbackName, ...) local result = nil diff --git a/shared/crafting.lua b/shared/crafting.lua index 6ff6c10..334667d 100644 --- a/shared/crafting.lua +++ b/shared/crafting.lua @@ -36,26 +36,26 @@ local excludeKeys = { --- --- @usage --- ```lua ----craftingMenu({ ---- craftable = { ---- Header = "Weapon Crafting", ---- Recipes = { ---- [1] = { ---- ["weapon_pistol"] = { ["steel"] = 5, ["plastic"] = 2 }, ---- amount = 1, ---- }, ---- -- More recipes... ---- }, ---- Anims = { ---- animDict = "amb@prop_human_parking_meter@male@idle_a", ---- anim = "idle_a", ---- }, ---- }, ---- coords = vector3(100.0, 200.0, 300.0), ----stashTable = "crafting_stash", ---- job = "mechanic", ---- onBack = function() print("Returning to previous menu") end, ----}) +--- craftingMenu({ +--- craftable = { +--- Header = "Weapon Crafting", +--- Recipes = { +--- [1] = { +--- ["weapon_pistol"] = { ["steel"] = 5, ["plastic"] = 2 }, +--- amount = 1, +--- }, +--- -- More recipes... +--- }, +--- Anims = { +--- animDict = "amb@prop_human_parking_meter@male@idle_a", +--- anim = "idle_a", +--- }, +--- }, +--- coords = vector3(100.0, 200.0, 300.0), +--- stashTable = "crafting_stash", +--- job = "mechanic", +--- onBack = function() print("Returning to previous menu") end, +--- }) function craftingMenu(data) if CraftLock then return end @@ -118,7 +118,7 @@ function craftingMenu(data) end while not canCarryTable do Wait(0) end - disable = not checkHasItem(data.stashName, itemTable) + disable = not checkStashItem(data.stashName, itemTable) setheader = ((metadata and metadata.label) or (Items[tostring(k)] and Items[tostring(k)].label) or "error - "..tostring(k)) ..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "") @@ -217,7 +217,7 @@ function multiCraft(data) if data.stashName then debugPrint("") - local hasItems, stashname = checkHasItem(data.stashName, itemTable) + local hasItems, stashname = checkStashItem(data.stashName, itemTable) if hasItems == true then max += 1 stashName = stashname diff --git a/shared/isAnimal.lua b/shared/isAnimal.lua index 7c99525..1de037c 100644 --- a/shared/isAnimal.lua +++ b/shared/isAnimal.lua @@ -23,10 +23,6 @@ -- Retrieve a flat list of all animal model hashes: local allAnimalModels = getAnimalModels() - File Separation Suggestion: - For scalability, consider separating this module into two files: - • AnimalDetection.lua (for functions and callbacks) - • AnimalPedsData.lua (for the AnimalPeds table) ]] -- Global animal classification flags. diff --git a/shared/make/makeVeh.lua b/shared/make/makeVeh.lua index 6403c4d..77551a7 100644 --- a/shared/make/makeVeh.lua +++ b/shared/make/makeVeh.lua @@ -87,42 +87,6 @@ function removeDistVehicleZone(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. ---- ----@param entity number The handle of the vehicle entity to push. ---- ----@usage ---- ```lua ---- pushVehicle(vehicle) ---- ``` -function pushVehicle(entity) - SetVehicleModKit(entity, 0) - if entity ~= 0 and DoesEntityExist(entity) then - if not NetworkHasControlOfEntity(entity) then - debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Requesting network control of vehicle^7.") - NetworkRequestControlOfEntity(entity) - local timeout = 2000 - while timeout > 0 and not NetworkHasControlOfEntity(entity) do - Wait(100) - timeout -= 100 - end - if NetworkHasControlOfEntity(entity) then debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Network has control of entity^7.") end - end - if not IsEntityAMissionEntity(entity) then - debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Setting vehicle as a ^7'^2mission^7' ^2entity^7.") - SetEntityAsMissionEntity(entity, true, true) - local timeout = 2000 - while timeout > 0 and not IsEntityAMissionEntity(entity) do - Wait(100) - timeout -= 100 - end - if IsEntityAMissionEntity(entity) then debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Vehicle is a ^7'^2mission^7'^2 entity^7.") end - end - end -end - --- Deletes a spawned vehicle. --- ---@param vehicle number The handle of the vehicle entity to delete. diff --git a/shared/playerfunctions.lua b/shared/playerfunctions.lua index eebbcb6..46eed39 100644 --- a/shared/playerfunctions.lua +++ b/shared/playerfunctions.lua @@ -432,7 +432,7 @@ function hasJob(job, source, grade) return hasJobFlag, duty end ---- Retrieves basic player information (name, cash, bank, job, etc.) based on the active inventory system. +--- Retrieves basic player information (name, cash, bank, job, etc.) based on the active core/inventory system. --- --- Can be called server-side (passing a player source) or client-side (for current player). --- diff --git a/shared/scaleforms/instructionalButtons.lua b/shared/scaleforms/instructionalButtons.lua index 81819db..9fdfd71 100644 --- a/shared/scaleforms/instructionalButtons.lua +++ b/shared/scaleforms/instructionalButtons.lua @@ -66,4 +66,45 @@ function makeInstructionalButtons(info) -- Final full-screen draw with full opacity. DrawScaleformMovieFullscreen(build, 255, 255, 255, 255, 0) -end \ No newline at end of file +end + +-- EXPERIMENTAL -- +-- RedM Button Prompts -- +-- Creates the promot, then shows it, this needs to be run in a loop +local promptGroups = {} + +function makeRedInstructionalButtons(info, title) + if not promptGroups[title] then -- Create group if not exists + promptGroups[title] = { + title = CreateVarString(10, 'LITERAL_STRING', title), + id = GetRandomIntInRange(0, 0xffffff), + prompts = {}, + } + for i = 1, #info do + promptGroups[title].prompts[i] = { + keys = info[i].keys, + text = info[i].text, + } + local keyTitle = CreateVarString(10, 'LITERAL_STRING', info[i].text) + -- Create one prompt per entry + local promptSet = UiPromptRegisterBegin() + -- Register all keys for this prompt + for k = 1, #info[i].keys do + PromptSetControlAction(promptSet, info[i].keys[k]) + end + PromptSetText(promptSet, keyTitle) + PromptSetEnabled(promptSet, true) + PromptSetVisible(promptSet, true) + PromptSetGroup(promptSet, promptGroups[title].id) + PromptRegisterEnd(promptSet) + end + end + PromptSetActiveGroupThisFrame(promptGroups[title].id, promptGroups[title].title) +end + +onResourceStop(function() + for k, v in pairs(promptGroups) do + print("^5Bridge^7: ^2Removing Prompt Group^7: ^3" .. k .. "^7") + PromptDelete(promptGroups[k].id, 1) + end +end, true) \ No newline at end of file diff --git a/shared/scaleforms/scaleform_basic.lua b/shared/scaleforms/scaleform_basic.lua index 253f1d9..aa6b75c 100644 --- a/shared/scaleforms/scaleform_basic.lua +++ b/shared/scaleforms/scaleform_basic.lua @@ -1,171 +1,3 @@ ---[[ - Instructional Buttons & Debug Text Module - ------------------------------------------- - This module provides functions for: - • Displaying instructional buttons on-screen via a scaleform movie. - • Drawing debug text with a background rectangle when debugMode is enabled. - • Rendering 3D text in the world. - • Displaying help messages and spinners. -]] - -------------------------------------------------------------- --- Instructional Buttons Functionality -------------------------------------------------------------- - ---- Loads and draws instructional buttons on-screen using a scaleform movie. ---- ---- Requests the "instructional_buttons" scaleform, clears previous data, sets clear space, ---- creates data slots for each button option provided in `info`, and then draws the scaleform fullscreen. ---- ---- @param info table An array of tables, where each table represents a button option: ---- - keys (table): An array of key codes (e.g., {38, 29}) to display. ---- - text (string): The label for the button. ---- ---- @usage ---- ```lua ----CreateThread(function() ---- while true do ---- makeInstructionalButtons({ ---- { keys = {38, 29}, text = "Open Menu" }, ---- { keys = {45}, text = "Close Menu" } ---- }) ---- Wait(0) ---- end ----end) ---- ``` -function makeInstructionalButtons(info) - local build = RequestScaleformMovie("instructional_buttons") - while not HasScaleformMovieLoaded(build) do Wait(0) end - - -- Draw the scaleform fullscreen (initial draw). - DrawScaleformMovieFullscreen(build, 255, 255, 255, 0, 0) - - -- Clear previous instructions. - BeginScaleformMovieMethod(build, "CLEAR_ALL") - EndScaleformMovieMethod() - - -- Set clear spacing between buttons. - BeginScaleformMovieMethod(build, "SET_CLEAR_SPACE") - ScaleformMovieMethodAddParamInt(200) - EndScaleformMovieMethod() - - -- Add each button option to the scaleform. - for i = 1, #info do - BeginScaleformMovieMethod(build, "SET_DATA_SLOT") - ScaleformMovieMethodAddParamInt(i - 1) - for k = 1, #info[i].keys do - ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(2, info[i].keys[k], true)) - end - BeginTextCommandScaleformString("STRING") - AddTextComponentSubstringKeyboardDisplay(info[i].text) - EndTextCommandScaleformString() - EndScaleformMovieMethod() - end - - -- Draw the instructional buttons. - BeginScaleformMovieMethod(build, "DRAW_INSTRUCTIONAL_BUTTONS") - EndScaleformMovieMethod() - - -- Set a translucent black background. - BeginScaleformMovieMethod(build, "SET_BACKGROUND_COLOUR") - ScaleformMovieMethodAddParamInt(0) - ScaleformMovieMethodAddParamInt(0) - ScaleformMovieMethodAddParamInt(0) - ScaleformMovieMethodAddParamInt(80) - EndScaleformMovieMethod() - - -- Final full-screen draw with full opacity. - DrawScaleformMovieFullscreen(build, 255, 255, 255, 255, 0) -end - --- EXPERIMENTAL -- --- RedM Button Prompts -- --- Creates the promot, then shows it, this needs to be run in a loop -local promptGroups = {} - -function makeRedInstructionalButtons(info, title) - if not promptGroups[title] then -- Create group if not exists - promptGroups[title] = { - title = CreateVarString(10, 'LITERAL_STRING', title), - id = GetRandomIntInRange(0, 0xffffff), - prompts = {}, - } - for i = 1, #info do - promptGroups[title].prompts[i] = { - keys = info[i].keys, - text = info[i].text, - } - local keyTitle = CreateVarString(10, 'LITERAL_STRING', info[i].text) - -- Create one prompt per entry - local promptSet = UiPromptRegisterBegin() - -- Register all keys for this prompt - for k = 1, #info[i].keys do - PromptSetControlAction(promptSet, info[i].keys[k]) - end - PromptSetText(promptSet, keyTitle) - PromptSetEnabled(promptSet, true) - PromptSetVisible(promptSet, true) - PromptSetGroup(promptSet, promptGroups[title].id) - PromptRegisterEnd(promptSet) - end - end - PromptSetActiveGroupThisFrame(promptGroups[title].id, promptGroups[title].title) -end - -onResourceStop(function() - for k, v in pairs(promptGroups) do - print("^5GTAUI^7: ^2Removing Prompt Group^7: ^3" .. k .. "^7") - PromptDelete(promptGroups[k].id, 1) - end -end, true) - -------------------------------------------------------------- --- Debug Text Display Functionality -------------------------------------------------------------- - ---- Draws debug text on the screen if debugMode is enabled. ---- ---- Calculates a background rectangle based on the number of text lines and renders each line on-screen. ---- ---- @param textTable table An array of strings to display. ---- @param loc vector2 (Optional) Top-left coordinate for the text box (default: vec2(0.05, 0.65)). ---- ---- @usage ---- ```lua ----CreateThread(function() ---- while true do ---- debugScaleForm( ---- { ---- "Line 1: Debug info", ---- "Line 2: More info" ---- } ---- ) ---- Wait(0) ---- end ----end) ---- ``` -function debugScaleForm(textTable, loc) - if debugMode then - loc = loc or vec2(0.05, 0.65) - - local lineHeight = 0.025 -- Height per line. - local totalHeight = #textTable * lineHeight - local boxPadding = 0.01 -- Padding around the text. - local size = vec2(0.18, totalHeight + boxPadding * 2) - - -- Draw background rectangle. - DrawRect(loc.x + size.x / 2, loc.y + size.y / 2, size.x, size.y, 0, 0, 0, 255) - - -- Render each line of text. - for i = 1, #textTable do - SetTextScale(0.30, 0.30) - BeginTextCommandDisplayText("STRING") - AddTextComponentSubstringKeyboardDisplay(textTable[i]) - EndTextCommandDisplayText(loc.x + 0.005, loc.y + (i - 1) * lineHeight + 0.01) - end - end -end - ------------------------------------------------------------- -- 3D Text Rendering ------------------------------------------------------------- diff --git a/shared/stashcontrol.lua b/shared/stashcontrol.lua index f717839..f392554 100644 --- a/shared/stashcontrol.lua +++ b/shared/stashcontrol.lua @@ -82,9 +82,9 @@ end --- --- @usage --- ```lua ---- local found, stashName = checkHasItem({"playerStash", "storageStash"}, { iron = 2, wood = 5 }) +--- local found, stashName = checkStashItem({"playerStash", "storageStash"}, { iron = 2, wood = 5 }) --- ``` -function checkHasItem(stashes, itemTable) +function checkStashItem(stashes, itemTable) if not stashes then return hasItem(itemTable), nil end diff --git a/shared/targets.lua b/shared/targets.lua index 1701e02..05d0621 100644 --- a/shared/targets.lua +++ b/shared/targets.lua @@ -373,8 +373,7 @@ end --- --- @usage --- ```lua ----createModelTarget( ----{ model1, model2 }, +---createModelTarget({ model1, model2 }, ---{ --- { --- action = function() diff --git a/shared/vehicles.lua b/shared/vehicles.lua index 1476d1b..7430e01 100644 --- a/shared/vehicles.lua +++ b/shared/vehicles.lua @@ -262,7 +262,7 @@ end --- --- @usage --- ```lua ---- local closestVeh, distance = getClosestVehicle({ x = 100, y = 200, z = 30 }, true) +--- local closestVeh, distance = getClosestVehicle({ x = 100, y = 200, z = 30 }, src) --- ``` function getClosestVehicle(coords, src) local ped, vehicles, closestDistance, closestVehicle