This commit is contained in:
Nordi98 2025-07-20 19:03:04 +02:00
parent 4f7a53e4a7
commit 10de5a6c76
33 changed files with 2124 additions and 0 deletions

View file

@ -0,0 +1,125 @@
Open = false
cam = nil
Peds = {}
local Actions = {}
if Config.FrameworkLoadinEvent ~= '' then
RegisterNetEvent(Config.FrameworkLoadinEvent, function()
SpawnPeds()
end)
end
AddEventHandler('onResourceStart', function(resourceName)
if (GetCurrentResourceName() == resourceName) then
if #Config.peds ~= 0 then SpawnPeds() end
end
end)
---@param ped number # The id of the ped
---@param data table # The data for the interaction
---@param zoom number # Camera zoom level (optional, default: 40.0)
---@param x number # Camera X position (optional, default: 0)
---@param y number # Camera Y position (optional, default: 1.5)
---@param z number # Camera Z position (optional, default: 0.3)
---@param rotX number # Camera X rotation (optional, default: 0.0)
---@param rotY number # Camera Y rotation (optional, default: 0.0)
---@param rotZ number # Camera Z rotation (optional, default: GetEntityHeading(ped) + 180)
OpenDialog = function(ped, data, zoom, x, y, z, rotX, rotY, rotZ)
-- Setting defaults
local newX, newY, newZ = x or 0, y or 1.5, z or 0.3
local newRotX, newRotY, newRotZ = rotX or 0.0, rotY or 0.0, rotZ or GetEntityHeading(ped) + 180
local fov = zoom or 40.0
local coords = GetOffsetFromEntityInWorldCoords(ped, newX, newY, newZ)
-- camera setup
cam = CreateCam('DEFAULT_SCRIPTED_CAMERA', true)
SetEntityLocallyInvisible(PlayerPedId())
SetCamActive(cam, true)
RenderScriptCams(true, true, 500, true, true)
SetCamCoord(cam, coords.x, coords.y, coords.z + 0.2)
SetCamRot(cam, newRotX, newRotY, newRotZ, 5)
SetCamFov(cam, fov)
local Dialog = data
local function extractEvents(tbl)
for k, v in pairs(tbl) do
if type(v) == "table" then
extractEvents(v)
elseif k == "event" and type(v) == "string" then
Actions[v] = v
end
end
end
extractEvents(Dialog)
SetNuiFocus(true, true)
SendNUIMessage({
type = 'New',
data = data
})
Open = true
SetInvisible()
end
SetDialog = function(data)
SendNUIMessage({
type = 'Set',
data = data
})
end
CloseDialog = function()
Open = false
SendNUIMessage({
type = 'Close',
})
end
SpawnPedByID = function(id, data)
Peds[id] = data
SpawnPed(id, data)
end
DeletePedByID = function(id)
if Peds[id].ped then
exports['qb-target']:RemoveTargetEntity(Peds[id].ped)
DeleteEntity(Peds[id].ped)
Peds[id] = nil
end
end
RegisterNuiCallback("click", function(data, cb)
if data.data then
SendNUIMessage({
type = 'Continue',
data = data.data
})
cb(false)
return
end
if data.close then
SetNuiFocus(false, false)
if cam and DoesCamExist(cam) then
RenderScriptCams(false, true, 500, true, true)
DestroyCam(cam, true)
end
CloseDialog()
end
if Actions[data.event] then
if data.server then
TriggerServerEvent(Actions[data.event], data)
else
TriggerEvent(Actions[data.event], data)
end
end
end)
exports('OpenDialog', OpenDialog)
exports('SetDialog', SetDialog)
exports('CloseDialog', CloseDialog)
exports('SpawnPed', SpawnPedByID)

View file

@ -0,0 +1,87 @@
RegisterCommand('deleteped', function()
DeletePedByID('test')
end, false)
RegisterCommand('spawnped', function()
SpawnPedByID('test', {
label = 'Talk to stranger',
icon = 'fa-solid fa-comment',
model = "csb_avon",
coords = vector3(165.48, 6612.81, 31.9),
heading = 170,
data = {
firstname = 'John',
lastname = 'Doe',
text = 'Hey bud, how ya doin.',
buttons = {
{
text = 'Im ok, how are you?',
data = {
text = 'Im cool rn, see you around!',
buttons = {
{
text = 'Se ya',
close = true
},
}
}
},
{
text = 'No sorry, im gonna leave',
close = true
},
}
}
})
end, false)
RegisterNetEvent('con:mechanic', function(ped)
rep = 1
data = {
firstname = 'John',
lastname = 'Doe',
text = 'Hey bud, what can i do for you',
type = 'Mechanic',
rep = rep,
buttons = {
{ text = "I wanna clock in", data = {
text = 'Alright',
buttons = {
{ text = 'Clock in/out', event = 'con:clockin', close = true },
{ text = 'Whatever, changed my mind', event = 'con:back' },
}
}},
{ text = "I'm gonna leave", close = true },
}
}
OpenDialog(ped, data)
end)
RegisterNetEvent('con:back', function()
data = {
firstname = 'John',
lastname = 'Doe',
text = 'Hey bud, what can i do for you',
type = 'Mechanic',
rep = '2',
buttons = {
{ text = "I wanna clock in", data = {
text = 'Alright',
buttons = {
{ text = 'Clock in/out', event = 'con:clockin', close = true },
{ text = 'Whatever changed my mind', event = 'con:back' },
}
}
},
{ text = "I'm gonna leave", close = true },
}
}
SetDialog(data)
end)
RegisterNetEvent('con:clockin', function()
print('123')
TriggerEvent('QBCore:Notify', "clocked in", 'success')
end)

View file

@ -0,0 +1,148 @@
local loadModel = function(modelHash)
if not IsModelValid(modelHash) then
print(modelHash..' Is not a valid model')
return
end
RequestModel(modelHash)
RequestCollisionForModel(modelHash)
while not HasModelLoaded(modelHash) or not HasCollisionForModelLoaded(modelHash) do
Wait(10)
end
end
local getClosestPed = function(coords, max)
local all = GetGamePool('CPed')
local closest, closestCoords
max = max or 2.0
for i = 1, #all do
local ped = all[i]
if IsPedAPlayer(ped) then
return
end
local pedCoords = GetEntityCoords(ped)
local distance = #(coords - pedCoords)
if distance < max then
max = distance
closest = ped
closestCoords = pedCoords
end
end
return closest, closestCoords
end
local loadanimDict = function(animDict)
if not DoesAnimDictExist(animDict) then
print(animDict..' Is not a valid animation dict')
return
end
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Wait(10)
end
end
local playAnimation = function(animData)
if not IsEntityPlayingAnim(animData.ped, animData.dict, animData.lib, 3) then
if not animData.flag then animData.flag = 49 end
loadanimDict(animData.dict)
TaskPlayAnim(animData.ped, animData.dict, animData.lib, 2.0, -1.0, -1, animData.flag, 0, 0, 0, 0)
end
end
SpawnPeds = function()
for v, k in pairs(Config.peds) do
Peds[v] = k
SpawnPed(v, k)
end
end
SpawnPed = function(id, data)
local ped, pedDist = getClosestPed(data.coords)
if data.dict then
dict = data.dict
else
dict = "missbigscore2aig_6"
end
if data.lib then
lib = data.lib
else
lib = "wait_loop"
end
if DoesEntityExist(ped) and pedDist <= 1.2 then
DeletePed(ped)
end
loadModel(data.model)
Peds[id].ped = CreatePed(5, GetHashKey(data.model), data.coords.x, data.coords.y, data.coords.z - 1.0, data.heading, false, false)
SetEntityHeading(Peds[id].ped, data.heading)
SetPedCombatAttributes(Peds[id].ped, 46, true)
SetPedFleeAttributes(Peds[id].ped, 0, 0)
SetBlockingOfNonTemporaryEvents(Peds[id].ped, true)
SetEntityAsMissionEntity(Peds[id].ped, true, true)
FreezeEntityPosition(Peds[id].ped, true)
SetEntityInvincible(Peds[id].ped, true)
SetPedDiesWhenInjured(Peds[id].ped, false)
SetPedHearingRange(Peds[id].ped, 1.0)
SetPedAlertness(Peds[id].ped, 0)
if data.type ~= 'scenario' then
playAnimation({
ped = Peds[id].ped,
dict = dict,
lib = lib,
flag = 1
})
else
TaskStartScenarioInPlace(Peds[id].ped, data.anim, 0, false)
end
opts = {
label = data.label,
icon = data.icon,
action = function()
if data.data then
OpenDialog(Peds[id].ped, data.data)
else
if data.server then
TriggerServerEvent(data.event, Peds[id].ped)
else
TriggerEvent(data.event, Peds[id].ped)
end
end
end
}
if Config.Target == 'qb' then
exports['qb-target']:AddTargetEntity(Peds[id].ped, {
options = { opts },
distance = 2.0
})
elseif Config.Target == 'ox' then
exports.ox_target:addLocalEntity(Peds[id].ped, {opts}) -- Use opts directly
else
print("^1[ERROR] Invalid Target Config! Check your Config.Target setting.^0")
end
end
SetInvisible = function()
while Open do
SetEntityLocallyInvisible(PlayerPedId())
Wait(5)
end
end