created characterOptions
Created characterOptions in dialogue. Can be an int (entity) or a table containing { entity = int, offset = vector3, rotationOffset = vector3}
Will add group support in this system in the future
This commit is contained in:
1 parent
b125a1f937
commit
b75ab8479b
1 file changed
+51
-39
@@ -36,7 +36,16 @@ end
|
|||||||
--- @param name string
|
--- @param name string
|
||||||
--- @param dialogue string
|
--- @param dialogue string
|
||||||
--- @param options table example = {{ id = string, label = string}}
|
--- @param options table example = {{ id = string, label = string}}
|
||||||
function Dialogue.OpenDialogue(entity, name, dialogue, options, onSelected, onCancelled)
|
function Dialogue.OpenDialogue( name, dialogue, characterOptions, dialogueOptions, onSelected)
|
||||||
|
assert(name, "Name is required")
|
||||||
|
assert(dialogue, "Dialogue is required")
|
||||||
|
assert(dialogueOptions, "Dialogue options are required")
|
||||||
|
assert(characterOptions, "CharacterOptions must be a number or table containing an entity")
|
||||||
|
local isCharacterATable = type(characterOptions) == "table"
|
||||||
|
local entity = isCharacterATable and characterOptions.entity or tonumber(characterOptions)
|
||||||
|
local offset = isCharacterATable and characterOptions.offset or vector3(0, 0, 0)
|
||||||
|
local rotationOffset = isCharacterATable and characterOptions.rotationOffset or vector3(0, 0, 0)
|
||||||
|
|
||||||
-- Cancel any pending camera destroy
|
-- Cancel any pending camera destroy
|
||||||
pendingCameraDestroy = false
|
pendingCameraDestroy = false
|
||||||
activeDialogue = name
|
activeDialogue = name
|
||||||
@@ -50,19 +59,17 @@ function Dialogue.OpenDialogue(entity, name, dialogue, options, onSelected, onCa
|
|||||||
local offsetY = math.cos(angleRad) * 1.5
|
local offsetY = math.cos(angleRad) * 1.5
|
||||||
|
|
||||||
-- Get position in front of ped based on their heading
|
-- Get position in front of ped based on their heading
|
||||||
local endLocation = GetEntityCoords(entity) + vector3(offsetX, offsetY, 1.0)
|
local endLocation = GetEntityCoords(entity) + vector3(offsetX, offsetY, 0.5) + offset
|
||||||
|
|
||||||
if not cam then cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", 1) end
|
if not cam then cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", 1) end
|
||||||
local camPos = GetCamCoord(cam)
|
local camPos = GetCamCoord(cam)
|
||||||
local dist = #(endLocation - camPos)
|
local dist = #(endLocation - camPos)
|
||||||
local abs = cam and math.abs(dist)
|
local abs = cam and math.abs(dist)
|
||||||
if not abs or abs > 0.5 then
|
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
|
local camAngle = (pedHeading + 180.0) % 360.0
|
||||||
SetCamRot(cam, 0.0, 0.0, camAngle, 2)
|
SetCamRot(cam, rotationOffset.x, rotationOffset.y, camAngle + rotationOffset.z, 2)
|
||||||
SetCamCoord(cam, endLocation.x, endLocation.y, endLocation.z)
|
SetCamCoord(cam, endLocation.x, endLocation.y, endLocation.z)
|
||||||
RenderScriptCams(true, 1, 1000, 1, 0)
|
RenderScriptCams(true, true, 1000, true, false)
|
||||||
SetCamActive(cam, true)
|
SetCamActive(cam, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -70,7 +77,7 @@ function Dialogue.OpenDialogue(entity, name, dialogue, options, onSelected, onCa
|
|||||||
type = "open",
|
type = "open",
|
||||||
text = dialogue,
|
text = dialogue,
|
||||||
name = name,
|
name = name,
|
||||||
options = options
|
options = dialogueOptions
|
||||||
})
|
})
|
||||||
SetNuiFocus(true, true)
|
SetNuiFocus(true, true)
|
||||||
|
|
||||||
@@ -95,43 +102,48 @@ RegisterCommand("dialogue", function()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local prop = CreatePed(0, model, pos.x, pos.y, pos.z, 0.0, false, false)
|
local ped = CreatePed(0, model, pos.x, pos.y, pos.z, 0.0, false, false)
|
||||||
|
|
||||||
|
local characterData = {
|
||||||
|
entity = ped,
|
||||||
|
offset = vector3(0, 0, 0),
|
||||||
|
rotationOffset = vector3(0, 0, 0)
|
||||||
|
}
|
||||||
Wait(750)
|
Wait(750)
|
||||||
Dialogue.OpenDialogue( prop, "Akmed" , "Hello how are you doing my friend?", {
|
Dialogue.OpenDialogue("Akmed", "Hello how are you doing my friend?", characterData, {
|
||||||
{
|
{
|
||||||
label = "Trade with me",
|
label = "Trade with me",
|
||||||
id = 'something',
|
id = 'something',
|
||||||
},
|
|
||||||
{
|
|
||||||
label = "Goodbye",
|
|
||||||
id = 'someotherthing',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
function(selectedId)
|
{
|
||||||
if selectedId == 'something' then
|
label = "Goodbye",
|
||||||
Dialogue.OpenDialogue( prop, "Akmed" , "Thank you for wanting to purchase me lucky charms", {
|
id = 'someotherthing',
|
||||||
{
|
},
|
||||||
label = "Fuck off",
|
},
|
||||||
id = 'something',
|
function(selectedId)
|
||||||
},
|
if selectedId == 'something' then
|
||||||
{
|
Dialogue.OpenDialogue( "Akmed" , "Thank you for wanting to purchase me lucky charms", characterData, {
|
||||||
label = "Goodbye",
|
{
|
||||||
id = 'someotherthing',
|
label = "Fuck off",
|
||||||
},
|
id = 'something',
|
||||||
},
|
},
|
||||||
function(selectedId)
|
{
|
||||||
DeleteEntity(prop)
|
label = "Goodbye",
|
||||||
if selectedId == "something" then
|
id = 'someotherthing',
|
||||||
print("You hate lucky charms")
|
},
|
||||||
else
|
},
|
||||||
print("Thanks for keeping it civil")
|
function(selectedId)
|
||||||
end
|
DeleteEntity(ped)
|
||||||
|
if selectedId == "something" then
|
||||||
|
print("You hate lucky charms")
|
||||||
|
else
|
||||||
|
print("Thanks for keeping it civil")
|
||||||
end
|
end
|
||||||
)
|
end)
|
||||||
end
|
else
|
||||||
|
DeleteEntity(ped)
|
||||||
end
|
end
|
||||||
)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNuiCallback("dialogue:SelectOption", function(data)
|
RegisterNuiCallback("dialogue:SelectOption", function(data)
|
||||||
|
|||||||
Reference in new issue
Block a user