From 98bcffd8e35bf7d6b4174be13d0274072fcf85b3 Mon Sep 17 00:00:00 2001 From: Mart556 Date: Wed, 31 Dec 2025 13:13:44 +0200 Subject: [PATCH 1/2] feat: hide the player locally when focus on dialog entity --- client/main.lua | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/client/main.lua b/client/main.lua index 90e8fe7..4a7a08c 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,22 +1,23 @@ if not LoadResourceFile(GetCurrentResourceName(), 'web/build/index.html') then print('^1[SD-DIALOG] ERROR: web/build folder not found!^0') print('^1[SD-DIALOG] You likely downloaded the source code instead of the release.^0') - print('^1[SD-DIALOG] Please download the latest release from: https://github.com/Samuels-Development/sd-dialog/releases/latest^0') + print( + '^1[SD-DIALOG] Please download the latest release from: https://github.com/Samuels-Development/sd-dialog/releases/latest^0') return end local Config = require 'config' -local isDialogOpen = false --- Whether dialog is currently open -local currentDialog = nil --- Current dialog data -local originalOptions = nil --- Original options with functions intact -local dialogCamera = nil --- Camera handle +local isDialogOpen = false --- Whether dialog is currently open +local currentDialog = nil --- Current dialog data +local originalOptions = nil --- Original options with functions intact +local dialogCamera = nil --- Camera handle local originalCamCoords = nil --- Original camera position for restoration -local originalCamRot = nil --- Original camera position for restoration -local currentCallback = nil --- Current callback for option selection -local focusedEntity = nil --- Entity being focused on -local entityDialogs = {} --- Store dialog data for entities and models -local modelDialogs = {} --- Store dialog data for entities and models +local originalCamRot = nil --- Original camera position for restoration +local currentCallback = nil --- Current callback for option selection +local focusedEntity = nil --- Entity being focused on +local entityDialogs = {} --- Store dialog data for entities and models +local modelDialogs = {} --- Store dialog data for entities and models --- Creates and activates the dialog camera focused on the NPC --- @param entity number Entity to focus on @@ -35,7 +36,8 @@ local function CreateDialogCamera(entity, transitionTime) local rx = GetEntityRotation(entity, 2) local camRotation = rx + vector3(0.0, 0.0, 181.0) - dialogCamera = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", x, y, z, camRotation.x, camRotation.y, camRotation.z, 65.0) + dialogCamera = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", x, y, z, camRotation.x, camRotation.y, camRotation.z, + 65.0) SetCamActive(dialogCamera, true) RenderScriptCams(true, true, transitionTime, true, true) @@ -82,6 +84,15 @@ local function OpenDialog(data, callback, rawOptions) if data.entity and DoesEntityExist(data.entity) then CreateDialogCamera(data.entity, data.transitionTime) + + CreateThread(function() + local SetPlayerInvisibleLocally = SetPlayerInvisibleLocally; + + while isDialogOpen do + SetPlayerInvisibleLocally(cache.playerId, true); + Wait(0) + end + end) end SetNuiFocus(true, true) @@ -162,25 +173,22 @@ RegisterNUICallback('selectOption', function(data, cb) if option then if option.action and type(option.action) == 'function' then option.action(option.params, option, currentDialog) - elseif option.clientEvent then if type(option.clientEvent) == 'table' then local eventName = option.clientEvent[1] - local args = {table.unpack(option.clientEvent, 2)} + local args = { table.unpack(option.clientEvent, 2) } TriggerEvent(eventName, table.unpack(args)) else TriggerEvent(option.clientEvent) end - elseif option.serverEvent then if type(option.serverEvent) == 'table' then local eventName = option.serverEvent[1] - local args = {table.unpack(option.serverEvent, 2)} + local args = { table.unpack(option.serverEvent, 2) } TriggerServerEvent(eventName, table.unpack(args)) else TriggerServerEvent(option.serverEvent) end - elseif option.onSelect then option.onSelect(option, currentDialog) end @@ -323,7 +331,7 @@ end ---@param data table Dialog data configuration ---@return boolean Success local function AddModelDialog(models, data) - local modelList = type(models) == 'table' and models or {models} + local modelList = type(models) == 'table' and models or { models } local targetName = 'sd_dialog_model_' .. tostring(modelList[1]) for _, model in ipairs(modelList) do @@ -368,7 +376,7 @@ end ---@param models table|string Model or array of models ---@return boolean Success local function RemoveModelDialog(models) - local modelList = type(models) == 'table' and models or {models} + local modelList = type(models) == 'table' and models or { models } local targetName = 'sd_dialog_model_' .. tostring(modelList[1]) for _, model in ipairs(modelList) do @@ -397,8 +405,8 @@ local function SpawnConfigEntity(entityConfig, index) entityConfig.coords.z, entityConfig.coords.w, false, true) if not lib.waitFor(function() - if DoesEntityExist(ped) then return true end - end, 'Failed to create config ped', 5000) then + if DoesEntityExist(ped) then return true end + end, 'Failed to create config ped', 5000) then SetModelAsNoLongerNeeded(entityConfig.model) return end From 7398d310578cdebe30f2c60e8b13631297acb4f9 Mon Sep 17 00:00:00 2001 From: Mart556 Date: Wed, 31 Dec 2025 13:14:58 +0200 Subject: [PATCH 2/2] feat: when option has `close = true;` close the dialog after select --- client/main.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/main.lua b/client/main.lua index 4a7a08c..a8c4272 100644 --- a/client/main.lua +++ b/client/main.lua @@ -192,6 +192,10 @@ RegisterNUICallback('selectOption', function(data, cb) elseif option.onSelect then option.onSelect(option, currentDialog) end + + if option.close then + CloseDialog() + end end end