Fixed up dialogue default
dialogue now works properly. Still needs some builders. Maybe optionally pass a model and auto create ped, add menu offsets (pos rot) maybe some other stuff. Added into bridge export table
This commit is contained in:
1 parent
f8d46b9f7b
commit
bde07a4dd8
2 files changed
+86
-14
No files matched your search
@@ -101,10 +101,10 @@ Bridge.RegisterModule("Progressbar", Progressbar)
|
||||
|
||||
Bridge.RegisterModule("Target", Target)
|
||||
Bridge.RegisterModule("Menu", Menu)
|
||||
Bridge.RegisterModule("Utility", cLib.Utility)
|
||||
Bridge.RegisterModule("Dialogue", Dialogue)
|
||||
|
||||
Bridge.RegisterModule("Placeable", cLib.Placeable)
|
||||
--new
|
||||
Bridge.RegisterModule("Utility", cLib.Utility)
|
||||
Bridge.RegisterModule("Placeable", cLib.Placeable)--new
|
||||
Bridge.RegisterModule("Gizmo", cLib.Gizmo)
|
||||
Bridge.RegisterModule("Scaleform", cLib.Scaleform)
|
||||
Bridge.RegisterModule("Raycast", cLib.Raycast)
|
||||
|
||||
@@ -1,11 +1,34 @@
|
||||
|
||||
local promises = {}
|
||||
local activeDialogue = nil
|
||||
local pendingCameraDestroy = false
|
||||
Dialogue = {}
|
||||
|
||||
function CloseDialogue(name)
|
||||
local cam = nil
|
||||
local npc = nil
|
||||
|
||||
function Dialogue.CloseDialogue(name)
|
||||
-- Instead of destroying immediately, wait to see if new dialogue opens
|
||||
pendingCameraDestroy = true
|
||||
activeDialogue = nil
|
||||
|
||||
SetNuiFocus(false, false)
|
||||
SendNUIMessage({
|
||||
type = "close",
|
||||
name = name
|
||||
})
|
||||
|
||||
-- Wait brief moment to see if new dialogue opens
|
||||
CreateThread(function()
|
||||
Wait(50) -- Small delay to allow new dialogue to open
|
||||
if pendingCameraDestroy and not activeDialogue then
|
||||
-- No new dialogue opened, safe to destroy camera
|
||||
RenderScriptCams(false, 1, 1000, 1, 0)
|
||||
SetCamActive(cam, false)
|
||||
DestroyCam(cam, false)
|
||||
cam = nil
|
||||
end
|
||||
end)
|
||||
|
||||
promises[name] = nil
|
||||
end
|
||||
|
||||
@@ -13,7 +36,36 @@ end
|
||||
--- @param name string
|
||||
--- @param dialogue string
|
||||
--- @param options table example = {{ id = string, label = string}}
|
||||
function OpenDialogue(name, dialogue, options, onSelected, onCancelled)
|
||||
function Dialogue.OpenDialogue(entity, name, dialogue, options, onSelected, onCancelled)
|
||||
-- Cancel any pending camera destroy
|
||||
pendingCameraDestroy = false
|
||||
activeDialogue = name
|
||||
|
||||
-- camera magic!
|
||||
if entity then
|
||||
local pedHeading = GetEntityHeading(entity)
|
||||
-- Convert heading to radians and calculate offset
|
||||
local angleRad = math.rad(pedHeading)
|
||||
local offsetX = math.sin(angleRad) * 1.5
|
||||
local offsetY = math.cos(angleRad) * 1.5
|
||||
|
||||
-- Get position in front of ped based on their heading
|
||||
local endLocation = GetEntityCoords(entity) + vector3(offsetX, offsetY, 1.0)
|
||||
|
||||
if not cam then cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", 1) end
|
||||
local camPos = GetCamCoord(cam)
|
||||
local dist = #(endLocation - camPos)
|
||||
local abs = cam and math.abs(dist)
|
||||
if not abs or abs > 0.5 then
|
||||
print(abs)
|
||||
endLocation = GetEntityCoords(entity) + vector3(offsetX, offsetY, 1.0)
|
||||
local camAngle = (pedHeading + 180.0) % 360.0
|
||||
SetCamRot(cam, 0.0, 0.0, camAngle, 2)
|
||||
SetCamCoord(cam, endLocation.x, endLocation.y, endLocation.z)
|
||||
RenderScriptCams(true, 1, 1000, 1, 0)
|
||||
SetCamActive(cam, true)
|
||||
end
|
||||
end
|
||||
SendNUIMessage({
|
||||
type = "open",
|
||||
text = dialogue,
|
||||
@@ -21,16 +73,32 @@ function OpenDialogue(name, dialogue, options, onSelected, onCancelled)
|
||||
options = options
|
||||
})
|
||||
SetNuiFocus(true, true)
|
||||
local wrappedFunction = function(selected)
|
||||
|
||||
local wrappedFunction = function(selected)
|
||||
SetNuiFocus(false, false)
|
||||
CloseDialogue(name)
|
||||
Dialogue.CloseDialogue(name)
|
||||
onSelected(selected)
|
||||
end
|
||||
promises[name] = wrappedFunction
|
||||
end
|
||||
|
||||
RegisterCommand("dialogue", function()
|
||||
OpenDialogue( "Akmed" , "Hello how are you doing my friend?", {
|
||||
local pos = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0, 2.0, 0)
|
||||
local timeout = 500
|
||||
local model = `a_f_y_hipster_01`
|
||||
RequestModel(model)
|
||||
while not HasModelLoaded(model) do
|
||||
Wait(0)
|
||||
timeout = timeout - 1
|
||||
if timeout == 0 then
|
||||
print("Failed to load model")
|
||||
return
|
||||
end
|
||||
end
|
||||
local prop = CreatePed(0, model, pos.x, pos.y, pos.z, 0.0, false, false)
|
||||
|
||||
Wait(750)
|
||||
Dialogue.OpenDialogue( prop, "Akmed" , "Hello how are you doing my friend?", {
|
||||
{
|
||||
label = "Trade with me",
|
||||
id = 'something',
|
||||
@@ -42,10 +110,10 @@ RegisterCommand("dialogue", function()
|
||||
},
|
||||
function(selectedId)
|
||||
if selectedId == 'something' then
|
||||
OpenDialogue( "Akmed" , "Thank you for wanting to purchase me lucky charms", {
|
||||
Dialogue.OpenDialogue( prop, "Akmed" , "Thank you for wanting to purchase me lucky charms", {
|
||||
{
|
||||
label = "fuck russia",
|
||||
id = 'something',
|
||||
label = "Fuck off",
|
||||
id = 'something',
|
||||
},
|
||||
{
|
||||
label = "Goodbye",
|
||||
@@ -53,7 +121,12 @@ RegisterCommand("dialogue", function()
|
||||
},
|
||||
},
|
||||
function(selectedId)
|
||||
print("fuck russia:", selectedId)
|
||||
DeleteEntity(prop)
|
||||
if selectedId == "something" then
|
||||
print("You hate lucky charms")
|
||||
else
|
||||
print("Thanks for keeping it civil")
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
@@ -62,7 +135,6 @@ RegisterCommand("dialogue", function()
|
||||
end)
|
||||
|
||||
RegisterNuiCallback("dialogue:SelectOption", function(data)
|
||||
print("Selected option: " .. data.name)
|
||||
local promis = promises[data.name]
|
||||
if not promis then return end
|
||||
promis(data.id)
|
||||
|
||||
Reference in new issue
Block a user