Merge pull request #88 from JericoFX/dev
A set of changes Dui + Cleaning
This commit is contained in:
7 files changed
+681
-260
No files matched your search
+226
-189
@@ -1,112 +1,158 @@
|
|||||||
|
-- Cutscene Manager for FiveM
|
||||||
|
-- Handles cutscene loading, playback, and character management
|
||||||
|
|
||||||
|
---@class Cutscene
|
||||||
Cutscenes = Cutscenes or {}
|
Cutscenes = Cutscenes or {}
|
||||||
Cutscene = Cutscene or {}
|
Cutscene = Cutscene or {}
|
||||||
Cutscene.done = true
|
Cutscene.done = true
|
||||||
|
|
||||||
local names = {
|
-- Constants
|
||||||
{male = 'MP_1'},
|
local LOAD_TIMEOUT <const> = 10000
|
||||||
{male = 'MP_2'},
|
local FADE_DURATION <const> = 1000
|
||||||
{male = 'MP_3'},
|
local CUTSCENE_WAIT <const> = 1000
|
||||||
{male = 'MP_4'},
|
|
||||||
{male = 'MP_Male_Character', female = 'MP_Female_Character'},
|
-- Character model definitions
|
||||||
{male = 'MP_Male_Character_1', female = 'MP_Female_Character_1'},
|
local characterTags <const> = {
|
||||||
{male = 'MP_Male_Character_2', female = 'MP_Female_Character_2'},
|
{ male = 'MP_1' },
|
||||||
{male = 'MP_Male_Character_3', female = 'MP_Female_Character_3'},
|
{ male = 'MP_2' },
|
||||||
{male = 'MP_Male_Character_4', female = 'MP_Female_Character_4'},
|
{ male = 'MP_3' },
|
||||||
{male = 'MP_Plane_Passenger_1'},
|
{ male = 'MP_4' },
|
||||||
{male = 'MP_Plane_Passenger_2'},
|
{ male = 'MP_Male_Character', female = 'MP_Female_Character' },
|
||||||
{male = 'MP_Plane_Passenger_3'},
|
{ male = 'MP_Male_Character_1', female = 'MP_Female_Character_1' },
|
||||||
{male = 'MP_Plane_Passenger_4'},
|
{ male = 'MP_Male_Character_2', female = 'MP_Female_Character_2' },
|
||||||
{male = 'MP_Plane_Passenger_5'},
|
{ male = 'MP_Male_Character_3', female = 'MP_Female_Character_3' },
|
||||||
{male = 'MP_Plane_Passenger_6'},
|
{ male = 'MP_Male_Character_4', female = 'MP_Female_Character_4' },
|
||||||
{male = 'MP_Plane_Passenger_7'},
|
{ male = 'MP_Plane_Passenger_1' },
|
||||||
{male = 'MP_Plane_Passenger_8'},
|
{ male = 'MP_Plane_Passenger_2' },
|
||||||
{male = 'MP_Plane_Passenger_9'},
|
{ male = 'MP_Plane_Passenger_3' },
|
||||||
|
{ male = 'MP_Plane_Passenger_4' },
|
||||||
|
{ male = 'MP_Plane_Passenger_5' },
|
||||||
|
{ male = 'MP_Plane_Passenger_6' },
|
||||||
|
{ male = 'MP_Plane_Passenger_7' },
|
||||||
|
{ male = 'MP_Plane_Passenger_8' },
|
||||||
|
{ male = 'MP_Plane_Passenger_9' },
|
||||||
}
|
}
|
||||||
|
|
||||||
function Cutscene.GetTags(cutscene)
|
-- Component definitions for character customization
|
||||||
if not Cutscene.Load(cutscene) then return end
|
local componentsToSave <const> = {
|
||||||
StartCutscene(0)
|
-- Components
|
||||||
Wait(1000)
|
{ name = "head", id = 0, type = "drawable" },
|
||||||
local tags = {}
|
{ name = "beard", id = 1, type = "drawable" },
|
||||||
for k, tag in pairs(names) do
|
{ name = "hair", id = 2, type = "drawable" },
|
||||||
if DoesCutsceneEntityExist(tag.male, 0) or DoesCutsceneEntityExist(tag.female, 0) then
|
{ name = "arms", id = 3, type = "drawable" },
|
||||||
table.insert(tags, tag)
|
{ name = "pants", id = 4, type = "drawable" },
|
||||||
end
|
{ name = "parachute", id = 5, type = "drawable" },
|
||||||
|
{ name = "feet", id = 6, type = "drawable" },
|
||||||
|
{ name = "accessories", id = 7, type = "drawable" },
|
||||||
|
{ name = "undershirt", id = 8, type = "drawable" },
|
||||||
|
{ name = "vest", id = 9, type = "drawable" },
|
||||||
|
{ name = "decals", id = 10, type = "drawable" },
|
||||||
|
{ name = "jacket", id = 11, type = "drawable" },
|
||||||
|
-- Props
|
||||||
|
{ name = "hat", id = 0, type = "prop" },
|
||||||
|
{ name = "glasses", id = 1, type = "prop" },
|
||||||
|
{ name = "ears", id = 2, type = "prop" },
|
||||||
|
{ name = "watch", id = 3, type = "prop" },
|
||||||
|
{ name = "bracelet", id = 4, type = "prop" },
|
||||||
|
{ name = "misc", id = 5, type = "prop" },
|
||||||
|
{ name = "left_wrist", id = 6, type = "prop" },
|
||||||
|
{ name = "right_wrist", id = 7, type = "prop" },
|
||||||
|
{ name = "prop8", id = 8, type = "prop" },
|
||||||
|
{ name = "prop9", id = 9, type = "prop" },
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Utility Functions
|
||||||
|
|
||||||
|
function table.shallow_copy(t)
|
||||||
|
local t2 = {}
|
||||||
|
for k, v in pairs(t) do
|
||||||
|
t2[k] = v
|
||||||
end
|
end
|
||||||
StopCutsceneImmediately()
|
return t2
|
||||||
Wait(2000)
|
|
||||||
return tags
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Cutscene.Load(cutscene)
|
local function WaitForModelLoad(modelHash)
|
||||||
assert(cutscene, "Cutscene.Load called without a cutscene name.")
|
local timeout = GetGameTimer() + LOAD_TIMEOUT
|
||||||
if IsPedMale(PlayerPedId()) then
|
while not HasModelLoaded(modelHash) and GetGameTimer() < timeout do
|
||||||
RequestCutsceneWithPlaybackList(cutscene, 31, 8)
|
|
||||||
else
|
|
||||||
RequestCutsceneWithPlaybackList(cutscene, 103, 8)
|
|
||||||
end
|
|
||||||
local timeout = GetGameTimer() + 10000
|
|
||||||
while not (HasCutsceneLoaded()) and GetGameTimer() < timeout do
|
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
|
return HasModelLoaded(modelHash)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function CreatePedFromModel(modelName, coords)
|
||||||
|
local model = GetHashKey(modelName)
|
||||||
|
RequestModel(model)
|
||||||
|
|
||||||
|
if not WaitForModelLoad(model) then
|
||||||
|
print("Failed to load model: " .. modelName)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local ped = CreatePed(0, model, coords.x, coords.y, coords.z, 0.0, true, false)
|
||||||
|
if not DoesEntityExist(ped) then
|
||||||
|
print("Failed to create ped from model: " .. modelName)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return ped
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Cutscene Core Functions
|
||||||
|
local function LoadCutscene(cutscene)
|
||||||
|
assert(cutscene, "Cutscene.Load called without a cutscene name.")
|
||||||
|
local playbackList = IsPedMale(PlayerPedId()) and 31 or 103
|
||||||
|
RequestCutsceneWithPlaybackList(cutscene, playbackList, 8)
|
||||||
|
|
||||||
|
local timeout = GetGameTimer() + LOAD_TIMEOUT
|
||||||
|
while not HasCutsceneLoaded() and GetGameTimer() < timeout do
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
|
||||||
if not HasCutsceneLoaded() then
|
if not HasCutsceneLoaded() then
|
||||||
print("Cutscene failed to load: ", cutscene)
|
print("Cutscene failed to load: ", cutscene)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Cutscene.SavePedOutfit(ped)
|
local function GetCutsceneTags(cutscene)
|
||||||
local outfitData = {}
|
if not LoadCutscene(cutscene) then return end
|
||||||
local componentsToSave = {
|
|
||||||
-- Components
|
|
||||||
{ name = "head", id = 0, type = "drawable" },
|
|
||||||
{ name = "beard", id = 1, type = "drawable" },
|
|
||||||
{ name = "hair", id = 2, type = "drawable" },
|
|
||||||
{ name = "arms", id = 3, type = "drawable" },
|
|
||||||
{ name = "pants", id = 4, type = "drawable" },
|
|
||||||
{ name = "parachute", id = 5, type = "drawable" },
|
|
||||||
{ name = "feet", id = 6, type = "drawable" },
|
|
||||||
{ name = "accessories", id = 7, type = "drawable" },
|
|
||||||
{ name = "undershirt", id = 8, type = "drawable" },
|
|
||||||
{ name = "vest", id = 9, type = "drawable" },
|
|
||||||
{ name = "decals", id = 10, type = "drawable" },
|
|
||||||
{ name = "jacket", id = 11, type = "drawable" },
|
|
||||||
|
|
||||||
-- Props
|
StartCutscene(0)
|
||||||
{ name = "hat", id = 0, type = "prop" },
|
Wait(CUTSCENE_WAIT)
|
||||||
{ name = "glasses", id = 1, type = "prop" },
|
|
||||||
{ name = "ears", id = 2, type = "prop" },
|
local tags = {}
|
||||||
{ name = "watch", id = 3, type = "prop" },
|
for _, tag in pairs(characterTags) do
|
||||||
{ name = "bracelet", id = 4, type = "prop" },
|
if DoesCutsceneEntityExist(tag.male, 0) or DoesCutsceneEntityExist(tag.female, 0) then
|
||||||
{ name = "misc", id = 5, type = "prop" },
|
table.insert(tags, tag)
|
||||||
{ name = "left_wrist", id = 6, type = "prop" },
|
end
|
||||||
{ name = "right_wrist", id = 7, type = "prop" },
|
end
|
||||||
{ name = "prop8", id = 8, type = "prop" },
|
|
||||||
{ name = "prop9", id = 9, type = "prop" },
|
StopCutsceneImmediately()
|
||||||
}
|
Wait(CUTSCENE_WAIT * 2)
|
||||||
|
return tags
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Character Outfit Management
|
||||||
|
local function SavePedOutfit(ped)
|
||||||
|
local outfitData = {}
|
||||||
|
|
||||||
for _, component in ipairs(componentsToSave) do
|
for _, component in ipairs(componentsToSave) do
|
||||||
if component.type == "drawable" then
|
if component.type == "drawable" then
|
||||||
local drawable = GetPedDrawableVariation(ped, component.id)
|
|
||||||
local texture = GetPedTextureVariation(ped, component.id)
|
|
||||||
local palette = GetPedPaletteVariation(ped, component.id)
|
|
||||||
outfitData[component.name] = {
|
outfitData[component.name] = {
|
||||||
id = component.id,
|
id = component.id,
|
||||||
type = component.type,
|
type = component.type,
|
||||||
drawable = drawable,
|
drawable = GetPedDrawableVariation(ped, component.id),
|
||||||
texture = texture,
|
texture = GetPedTextureVariation(ped, component.id),
|
||||||
palette = palette,
|
palette = GetPedPaletteVariation(ped, component.id),
|
||||||
}
|
}
|
||||||
elseif component.type == "prop" then
|
elseif component.type == "prop" then
|
||||||
local propIndex = GetPedPropIndex(ped, component.id)
|
|
||||||
local propTexture = GetPedPropTextureIndex(ped, component.id)
|
|
||||||
outfitData[component.name] = {
|
outfitData[component.name] = {
|
||||||
id = component.id,
|
id = component.id,
|
||||||
type = component.type,
|
type = component.type,
|
||||||
propIndex = propIndex,
|
propIndex = GetPedPropIndex(ped, component.id),
|
||||||
propTexture = propTexture,
|
propTexture = GetPedPropTextureIndex(ped, component.id),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -114,7 +160,7 @@ function Cutscene.SavePedOutfit(ped)
|
|||||||
return outfitData
|
return outfitData
|
||||||
end
|
end
|
||||||
|
|
||||||
function Cutscene.ApplyPedOutfit(ped, outfitData)
|
local function ApplyPedOutfit(ped, outfitData)
|
||||||
if not outfitData or type(outfitData) ~= "table" then
|
if not outfitData or type(outfitData) ~= "table" then
|
||||||
print("ApplyPedOutfit: Invalid outfitData provided.")
|
print("ApplyPedOutfit: Invalid outfitData provided.")
|
||||||
return
|
return
|
||||||
@@ -122,29 +168,40 @@ function Cutscene.ApplyPedOutfit(ped, outfitData)
|
|||||||
|
|
||||||
for componentName, data in pairs(outfitData) do
|
for componentName, data in pairs(outfitData) do
|
||||||
if data.type == "drawable" then
|
if data.type == "drawable" then
|
||||||
-- Ensure all values are present before applying
|
SetPedComponentVariation(ped, data.id, data.drawable or 0, data.texture or 0, data.palette or 0)
|
||||||
local drawable = data.drawable or 0
|
|
||||||
local texture = data.texture or 0
|
|
||||||
local palette = data.palette or 0
|
|
||||||
SetPedComponentVariation(ped, data.id, drawable, texture, palette)
|
|
||||||
elseif data.type == "prop" then
|
elseif data.type == "prop" then
|
||||||
-- Clear prop if it's marked as not present (-1 index)
|
|
||||||
if data.propIndex == -1 or data.propIndex == nil then
|
if data.propIndex == -1 or data.propIndex == nil then
|
||||||
ClearPedProp(ped, data.id)
|
ClearPedProp(ped, data.id)
|
||||||
else
|
else
|
||||||
local propTexture = data.propTexture or 0
|
SetPedPropIndex(ped, data.id, data.propIndex, data.propTexture or 0, true)
|
||||||
SetPedPropIndex(ped, data.id, data.propIndex, propTexture, true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Public Interface
|
||||||
|
function Cutscene.GetTags(cutscene)
|
||||||
|
return GetCutsceneTags(cutscene)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Cutscene.Load(cutscene)
|
||||||
|
return LoadCutscene(cutscene)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Cutscene.SavePedOutfit(ped)
|
||||||
|
return SavePedOutfit(ped)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Cutscene.ApplyPedOutfit(ped, outfitData)
|
||||||
|
return ApplyPedOutfit(ped, outfitData)
|
||||||
|
end
|
||||||
|
|
||||||
function Cutscene.Create(cutscene, coords, srcs)
|
function Cutscene.Create(cutscene, coords, srcs)
|
||||||
local lastCoords = coords or GetEntityCoords(PlayerPedId())
|
local lastCoords = coords or GetEntityCoords(PlayerPedId())
|
||||||
DoScreenFadeOut(0)
|
DoScreenFadeOut(0)
|
||||||
local tagsFromCutscene = Cutscene.GetTags(cutscene)
|
|
||||||
|
|
||||||
if not Cutscene.Load(cutscene) then
|
local tagsFromCutscene = GetCutsceneTags(cutscene)
|
||||||
|
if not LoadCutscene(cutscene) then
|
||||||
print("Cutscene.Create: Failed to load cutscene", cutscene)
|
print("Cutscene.Create: Failed to load cutscene", cutscene)
|
||||||
DoScreenFadeIn(0)
|
DoScreenFadeIn(0)
|
||||||
return false
|
return false
|
||||||
@@ -152,100 +209,85 @@ function Cutscene.Create(cutscene, coords, srcs)
|
|||||||
|
|
||||||
srcs = srcs or {}
|
srcs = srcs or {}
|
||||||
local clothes = {}
|
local clothes = {}
|
||||||
|
|
||||||
local localped = PlayerPedId()
|
local localped = PlayerPedId()
|
||||||
|
|
||||||
local playersToProcess = {}
|
-- Process players and create necessary peds
|
||||||
table.insert(playersToProcess, { ped = localped, identifier = "localplayer", coords = lastCoords})
|
local playersToProcess = { { ped = localped, identifier = "localplayer", coords = lastCoords } }
|
||||||
for i, src_raw in ipairs(srcs) do
|
|
||||||
if type(src_raw) == 'number' then
|
for _, src_raw in ipairs(srcs) do
|
||||||
if src_raw and not DoesEntityExist(src_raw) then
|
if type(src_raw) == 'number' then
|
||||||
local playerPed = GetPlayerPed(GetPlayerFromServerId(src_raw)) -- Assuming GetPlayerPed takes server ID
|
if src_raw and not DoesEntityExist(src_raw) then
|
||||||
|
local playerPed = GetPlayerPed(GetPlayerFromServerId(src_raw))
|
||||||
if DoesEntityExist(playerPed) then
|
if DoesEntityExist(playerPed) then
|
||||||
local ped = ClonePed(playerPed, false, false, true)
|
local ped = ClonePed(playerPed, false, false, true)
|
||||||
table.insert(playersToProcess, { ped = ped, identifier = "player" })
|
table.insert(playersToProcess, { ped = ped, identifier = "player" })
|
||||||
else
|
|
||||||
print("Cutscene.Create: Ped for src " .. src_raw .. " does not exist.")
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(playersToProcess, { ped = src_raw, identifier = "user"}) --developer passed a ped
|
table.insert(playersToProcess, { ped = src_raw, identifier = "user" })
|
||||||
end
|
end
|
||||||
elseif type(src_raw) == 'string' then
|
elseif type(src_raw) == 'string' then
|
||||||
-- impliment creating a ped by model name
|
local ped = CreatePedFromModel(src_raw, GetEntityCoords(localped))
|
||||||
local model = GetHashKey(src_raw)
|
if ped then
|
||||||
RequestModel(model)
|
|
||||||
local timeout = GetGameTimer() + 10000
|
|
||||||
while not HasModelLoaded(model) and GetGameTimer() < timeout do
|
|
||||||
Wait(0)
|
|
||||||
end
|
|
||||||
if not HasModelLoaded(model) then
|
|
||||||
print("Cutscene.Create: Failed to load model " .. src_raw)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
local pos = GetEntityCoords(localped)
|
|
||||||
local ped = CreatePed(0, model, pos.x, pos.y, pos.z, 0.0, true, false)
|
|
||||||
|
|
||||||
if ped and DoesEntityExist(ped) then
|
|
||||||
table.insert(playersToProcess, { ped = ped, identifier = 'script' })
|
table.insert(playersToProcess, { ped = ped, identifier = 'script' })
|
||||||
else
|
|
||||||
print("Cutscene.Create: Failed to create ped for src " .. src_raw)
|
|
||||||
end
|
end
|
||||||
elseif type(src_raw) == 'boolean' and src_raw then
|
|
||||||
print("Cutscene.Create: src_raw is a boolean, creating random ped currently not implimented.")
|
|
||||||
-- local pos = GetEntityCoords(localped)
|
|
||||||
-- local ped = CreateRandomPed(pos.x, pos.y, pos.z)
|
|
||||||
|
|
||||||
-- if ped and DoesEntityExist(ped)then
|
|
||||||
-- table.insert(playersToProcess, { ped = ped, identifier = 'script' })
|
|
||||||
-- else
|
|
||||||
-- print("Cutscene.Create: Failed to create random ped for src " )
|
|
||||||
-- end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local availableTags = {} -- Create a mutable copy of tags
|
-- Process available tags and assign to players
|
||||||
for _, tagName in ipairs(tagsFromCutscene or {}) do
|
local availableTags = table.shallow_copy(tagsFromCutscene or {})
|
||||||
table.insert(availableTags, tagName)
|
|
||||||
end
|
|
||||||
|
|
||||||
local usedTags = {}
|
local usedTags = {}
|
||||||
local cleanupTags = {}
|
local cleanupTags = {}
|
||||||
|
|
||||||
for _, playerData in ipairs(playersToProcess) do
|
for _, playerData in ipairs(playersToProcess) do
|
||||||
local currentPed = playerData.ped
|
local currentPed = playerData.ped
|
||||||
local isPedMale = IsPedMale(currentPed)
|
if not currentPed or not DoesEntityExist(currentPed) then goto continue end
|
||||||
local tagTable = availableTags[1]
|
|
||||||
|
local tagTable = table.remove(availableTags, 1)
|
||||||
if not tagTable then
|
if not tagTable then
|
||||||
print("Cutscene.Create: No available tags for player", playerData.identifier)
|
print("Cutscene.Create: No available tags for player", playerData.identifier)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
local tag = not isPedMale and tagTable.female or tagTable.male
|
local isPedMale = IsPedMale(currentPed)
|
||||||
local unusedTag = nil
|
local tag = isPedMale and tagTable.male or tagTable.female
|
||||||
if isPedMale and tagTable.female then
|
local unusedTag = isPedMale and tagTable.female or tagTable.male
|
||||||
unusedTag = isPedMale and tagTable.female or tagTable.male
|
|
||||||
end
|
|
||||||
SetCutsceneEntityStreamingFlags(tag, 0, 1)
|
SetCutsceneEntityStreamingFlags(tag, 0, 1)
|
||||||
RegisterEntityForCutscene(currentPed, tag, 0, GetEntityModel(currentPed), 64)
|
RegisterEntityForCutscene(currentPed, tag, 0, GetEntityModel(currentPed), 64)
|
||||||
SetCutscenePedComponentVariationFromPed(tag, currentPed, 0)
|
SetCutscenePedComponentVariationFromPed(tag, currentPed, 0)
|
||||||
clothes[tag] = { clothing = Cutscene.SavePedOutfit(currentPed), ped = currentPed }
|
|
||||||
table.insert(usedTags, tag) -- Track used tags
|
clothes[tag] = {
|
||||||
table.insert(cleanupTags, unusedTag) -- Track tags to be cleaned up later
|
clothing = SavePedOutfit(currentPed),
|
||||||
table.remove(availableTags, 1) -- Remove used tag
|
ped = currentPed
|
||||||
|
}
|
||||||
|
|
||||||
|
table.insert(usedTags, tag)
|
||||||
|
if unusedTag then table.insert(cleanupTags, unusedTag) end
|
||||||
|
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Clean up unused tags
|
||||||
for _, tag in ipairs(cleanupTags) do
|
for _, tag in ipairs(cleanupTags) do
|
||||||
local ped = RegisterEntityForCutscene(0, tag, 3, 0, 64)
|
local ped = RegisterEntityForCutscene(0, tag, 3, 0, 64)
|
||||||
NetworkSetEntityInvisibleToNetwork(ped, true)
|
if ped then
|
||||||
|
SetEntityVisible(ped, false, false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Handle remaining unused tags
|
||||||
for _, tag in ipairs(availableTags) do
|
for _, tag in ipairs(availableTags) do
|
||||||
local ped1 = RegisterEntityForCutscene(0, tag.male, 3, 0, 64)
|
for _, tagType in pairs({ tag.male, tag.female }) do
|
||||||
NetworkSetEntityInvisibleToNetwork(ped1, true)
|
if tagType then
|
||||||
local ped2 = RegisterEntityForCutscene(0, tag.female, 3, 0, 64)
|
local ped = RegisterEntityForCutscene(0, tagType, 3, 0, 64)
|
||||||
NetworkSetEntityInvisibleToNetwork(ped2, true)
|
if ped then
|
||||||
|
SetEntityVisible(ped, false, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local data = {
|
return {
|
||||||
cutscene = cutscene,
|
cutscene = cutscene,
|
||||||
coords = coords,
|
coords = coords,
|
||||||
tags = usedTags,
|
tags = usedTags,
|
||||||
@@ -253,44 +295,47 @@ function Cutscene.Create(cutscene, coords, srcs)
|
|||||||
peds = playersToProcess,
|
peds = playersToProcess,
|
||||||
clothes = clothes,
|
clothes = clothes,
|
||||||
}
|
}
|
||||||
Cutscene.done = false
|
|
||||||
return data
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Cutscene.Start(cutsceneData)
|
function Cutscene.Start(cutsceneData)
|
||||||
DoScreenFadeIn(1000)
|
|
||||||
Cutscene.done = false
|
|
||||||
if not cutsceneData then
|
if not cutsceneData then
|
||||||
print("Cutscene.Start: Cutscene data is nil.")
|
print("Cutscene.Start: Cutscene data is nil.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
DoScreenFadeIn(FADE_DURATION)
|
||||||
|
Cutscene.done = false
|
||||||
|
|
||||||
local clothes = cutsceneData.clothes
|
local clothes = cutsceneData.clothes
|
||||||
local coords = cutsceneData.coords
|
local coords = cutsceneData.coords
|
||||||
if coords then
|
|
||||||
|
-- Start cutscene
|
||||||
|
if coords then
|
||||||
if type(coords) == 'boolean' then
|
if type(coords) == 'boolean' then
|
||||||
coords = GetEntityCoords(PlayerPedId())
|
coords = GetEntityCoords(PlayerPedId())
|
||||||
end
|
end
|
||||||
StartCutsceneAtCoords(coords.x, coords.y, coords.z, 0 )
|
StartCutsceneAtCoords(coords.x, coords.y, coords.z, 0)
|
||||||
else
|
else
|
||||||
StartCutscene(0)
|
StartCutscene(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
Wait(100)
|
Wait(100)
|
||||||
|
|
||||||
|
-- Apply clothing to cutscene characters
|
||||||
for k, datam in pairs(clothes) do
|
for k, datam in pairs(clothes) do
|
||||||
local ped = datam.ped
|
local ped = datam.ped
|
||||||
if DoesEntityExist(ped) then
|
if DoesEntityExist(ped) then
|
||||||
SetCutscenePedComponentVariationFromPed(k, ped, 0)
|
SetCutscenePedComponentVariationFromPed(k, ped, 0)
|
||||||
Cutscene.ApplyPedOutfit(ped, datam.clothing)
|
ApplyPedOutfit(ped, datam.clothing)
|
||||||
else
|
|
||||||
print("Cutscene.Create: Ped " .. k .. " does not exist.")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local lastCoords = nil
|
-- Scene loading thread
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while not Cutscene.done do
|
local lastCoords
|
||||||
|
while not Cutscene.done do
|
||||||
local coords = GetWorldCoordFromScreenCoord(0.5, 0.5)
|
local coords = GetWorldCoordFromScreenCoord(0.5, 0.5)
|
||||||
if not lastCoords or (lastCoords and #(lastCoords - coords) > 100) then
|
if not lastCoords or #(lastCoords - coords) > 100 then
|
||||||
NewLoadSceneStartSphere(coords.x, coords.y, coords.z, 2000, 0)
|
NewLoadSceneStartSphere(coords.x, coords.y, coords.z, 2000, 0)
|
||||||
lastCoords = coords
|
lastCoords = coords
|
||||||
end
|
end
|
||||||
@@ -298,6 +343,7 @@ function Cutscene.Start(cutsceneData)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Control blocking thread
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while not Cutscene.done do
|
while not Cutscene.done do
|
||||||
DisableAllControlActions(0)
|
DisableAllControlActions(0)
|
||||||
@@ -306,43 +352,34 @@ function Cutscene.Start(cutsceneData)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
while not HasCutsceneFinished() and not Cutscene.done do
|
-- Main cutscene loop
|
||||||
|
while not HasCutsceneFinished() and not Cutscene.done do
|
||||||
Wait(0)
|
Wait(0)
|
||||||
if IsDisabledControlJustPressed(0, 200) then
|
if IsDisabledControlJustPressed(0, 200) then
|
||||||
DoScreenFadeOut(1000)
|
DoScreenFadeOut(FADE_DURATION)
|
||||||
Wait(1000)
|
Wait(FADE_DURATION)
|
||||||
StopCutsceneImmediately()
|
StopCutsceneImmediately()
|
||||||
Wait(500)
|
Wait(500)
|
||||||
Cutscene.done = true
|
Cutscene.done = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
DoScreenFadeIn(1000)
|
|
||||||
-- clean up any peds marked as 'script'
|
-- Cleanup
|
||||||
|
DoScreenFadeIn(FADE_DURATION)
|
||||||
for _, playerData in ipairs(cutsceneData.peds) do
|
for _, playerData in ipairs(cutsceneData.peds) do
|
||||||
local ped = playerData.ped
|
local ped = playerData.ped
|
||||||
if ped and DoesEntityExist(ped) and playerData.identifier == 'script' then
|
if not ped or not DoesEntityExist(ped) then goto continue end
|
||||||
|
|
||||||
|
if playerData.identifier == 'script' then
|
||||||
DeleteEntity(ped)
|
DeleteEntity(ped)
|
||||||
|
elseif playerData.identifier == 'localplayer' then
|
||||||
|
SetEntityCoords(ped, playerData.coords.x, playerData.coords.y, playerData.coords.z, false, false, false,
|
||||||
|
false)
|
||||||
end
|
end
|
||||||
if ped and DoesEntityExist(ped) and playerData.identifier == 'localplayer' then
|
::continue::
|
||||||
SetEntityCoords(ped, playerData.coords.x, playerData.coords.y, playerData.coords.z)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
Cutscene.done = true
|
Cutscene.done = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- RegisterCommand('cutscene', function(source, args, rawCommand)
|
return Cutscene
|
||||||
-- if not Cutscene.done then return end
|
|
||||||
-- local cutscene = args[1]
|
|
||||||
-- if not cutscene then return print("Usage: /cutscene <cutscene_name>") end
|
|
||||||
|
|
||||||
|
|
||||||
-- local cutsceneData = Cutscene.Create(cutscene, nil, {1, 1, 1 })
|
|
||||||
-- Cutscene.Start(cutsceneData)
|
|
||||||
|
|
||||||
|
|
||||||
-- end, false)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Cutscene
|
|
||||||
@@ -0,0 +1,329 @@
|
|||||||
|
-- DUI (Direct User Interface) Manager for FiveM
|
||||||
|
-- Basic table-based implementation with full mouse support
|
||||||
|
|
||||||
|
---@class DUI
|
||||||
|
DUI = {}
|
||||||
|
|
||||||
|
-- Constants
|
||||||
|
local DEFAULT_WIDTH <const> = 1280
|
||||||
|
local DEFAULT_HEIGHT <const> = 720
|
||||||
|
|
||||||
|
-- Store active DUI instances
|
||||||
|
local activeInstances = {}
|
||||||
|
local instanceCounter = 0
|
||||||
|
|
||||||
|
-- Mouse tracking state
|
||||||
|
local mouseState = {
|
||||||
|
tracking = false,
|
||||||
|
activeId = nil,
|
||||||
|
lastX = 0,
|
||||||
|
lastY = 0,
|
||||||
|
isPressed = false,
|
||||||
|
currentButton = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Mouse button constants
|
||||||
|
local MOUSE_BUTTONS <const> = {
|
||||||
|
LEFT = "left",
|
||||||
|
MIDDLE = "middle",
|
||||||
|
RIGHT = "right"
|
||||||
|
}
|
||||||
|
|
||||||
|
---@class DUIInstance
|
||||||
|
---@field id number Unique identifier for this DUI instance
|
||||||
|
---@field url string URL loaded in the DUI
|
||||||
|
---@field width number Width of the DUI
|
||||||
|
---@field height number Height of the DUI
|
||||||
|
---@field handle number DUI browser handle
|
||||||
|
---@field txd string Texture dictionary name
|
||||||
|
---@field txn string Texture name
|
||||||
|
---@field active boolean Whether the DUI is active
|
||||||
|
---@field trackMouse boolean Whether mouse tracking is enabled for this instance
|
||||||
|
---@field mouseScale table<string, number> Scale factors for mouse coordinates
|
||||||
|
|
||||||
|
-- Create a new DUI instance
|
||||||
|
---@param url string URL to load
|
||||||
|
---@param width? number Width of the DUI (default: 1280)
|
||||||
|
---@param height? number Height of the DUI (default: 720)
|
||||||
|
---@return number|nil id The DUI instance ID if successful, nil if failed
|
||||||
|
function DUI.Create(url, width, height)
|
||||||
|
if not url or type(url) ~= "string" then
|
||||||
|
return print("DUI.Create: URL is required and must be a string")
|
||||||
|
end
|
||||||
|
|
||||||
|
width = width or DEFAULT_WIDTH
|
||||||
|
height = height or DEFAULT_HEIGHT
|
||||||
|
instanceCounter = instanceCounter + 1
|
||||||
|
|
||||||
|
local id = instanceCounter
|
||||||
|
local handle = CreateDui(url, width, height)
|
||||||
|
|
||||||
|
if not handle then
|
||||||
|
return print("DUI.Create: Failed to create DUI instance")
|
||||||
|
end
|
||||||
|
|
||||||
|
local instance = {
|
||||||
|
id = id,
|
||||||
|
url = url,
|
||||||
|
width = width,
|
||||||
|
height = height,
|
||||||
|
handle = handle,
|
||||||
|
txd = "dui_" .. id,
|
||||||
|
txn = "texture_" .. id,
|
||||||
|
active = true,
|
||||||
|
trackMouse = false,
|
||||||
|
mouseScale = {
|
||||||
|
x = 1.0,
|
||||||
|
y = 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Create runtime texture
|
||||||
|
local duiHandle = GetDuiHandle(handle)
|
||||||
|
CreateRuntimeTextureFromDuiHandle(CreateRuntimeTxd(instance.txd), instance.txn, duiHandle)
|
||||||
|
|
||||||
|
activeInstances[id] = instance
|
||||||
|
return id
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Destroy a DUI instance
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.Destroy(id)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return false end
|
||||||
|
|
||||||
|
if instance.handle then
|
||||||
|
DestroyDui(instance.handle)
|
||||||
|
end
|
||||||
|
|
||||||
|
activeInstances[id] = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set URL for a DUI instance
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@param url string New URL to load
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.SetURL(id, url)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return false end
|
||||||
|
|
||||||
|
SetDuiUrl(instance.handle, url)
|
||||||
|
instance.url = url
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Send a message to the DUI
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@param message table Message to send (will be JSON encoded)
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.SendMessage(id, message)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return false end
|
||||||
|
|
||||||
|
SendDuiMessage(instance.handle, json.encode(message))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Mouse interaction functions
|
||||||
|
|
||||||
|
-- Move mouse cursor on DUI
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@param x number X coordinate
|
||||||
|
---@param y number Y coordinate
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.MoveMouse(id, x, y)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return false end
|
||||||
|
|
||||||
|
SendDuiMouseMove(instance.handle, x, y)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Simulate mouse button press
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@param button "left"|"middle"|"right" Mouse button to simulate
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.MouseDown(id, button)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return false end
|
||||||
|
|
||||||
|
if not MOUSE_BUTTONS[button:upper()] then
|
||||||
|
return print("DUI.MouseDown: Invalid button. Must be 'left', 'middle', or 'right'")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Update mouse state
|
||||||
|
if instance.trackMouse then
|
||||||
|
mouseState.isPressed = true
|
||||||
|
mouseState.currentButton = button
|
||||||
|
end
|
||||||
|
|
||||||
|
SendDuiMouseDown(instance.handle, button)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Simulate mouse button release
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@param button "left"|"middle"|"right" Mouse button to simulate
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.MouseUp(id, button)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return false end
|
||||||
|
|
||||||
|
if not MOUSE_BUTTONS[button:upper()] then
|
||||||
|
return print("DUI.MouseUp: Invalid button. Must be 'left', 'middle', or 'right'")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Update mouse state
|
||||||
|
if instance.trackMouse then
|
||||||
|
mouseState.isPressed = false
|
||||||
|
mouseState.currentButton = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
SendDuiMouseUp(instance.handle, button)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Simulate mouse wheel movement
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@param deltaY number Vertical scroll amount
|
||||||
|
---@param deltaX number Horizontal scroll amount
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.MouseWheel(id, deltaY, deltaX)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return false end
|
||||||
|
|
||||||
|
SendDuiMouseWheel(instance.handle, deltaY, deltaX)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Click helper function (combines MoveMouse, MouseDown, and MouseUp)
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@param x number X coordinate
|
||||||
|
---@param y number Y coordinate
|
||||||
|
---@param button? "left"|"middle"|"right" Mouse button to click (default: "left")
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.Click(id, x, y, button)
|
||||||
|
button = button or "left"
|
||||||
|
|
||||||
|
if not DUI.MoveMouse(id, x, y) then return false end
|
||||||
|
if not DUI.MouseDown(id, button) then return false end
|
||||||
|
|
||||||
|
-- Small delay to simulate real click
|
||||||
|
Citizen.Wait(50)
|
||||||
|
|
||||||
|
return DUI.MouseUp(id, button)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Enable or disable mouse tracking for a DUI instance
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@param enabled boolean Whether to enable mouse tracking
|
||||||
|
---@param scaleX? number Scale factor for X coordinates (default: 1.0)
|
||||||
|
---@param scaleY? number Scale factor for Y coordinates (default: 1.0)
|
||||||
|
---@return boolean success Whether the operation was successful
|
||||||
|
function DUI.TrackMouse(id, enabled, scaleX, scaleY)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return false end
|
||||||
|
|
||||||
|
instance.trackMouse = enabled
|
||||||
|
instance.mouseScale.x = scaleX or 1.0
|
||||||
|
instance.mouseScale.y = scaleY or 1.0
|
||||||
|
|
||||||
|
if enabled then
|
||||||
|
mouseState.tracking = true
|
||||||
|
mouseState.activeId = id
|
||||||
|
elseif mouseState.activeId == id then
|
||||||
|
mouseState.tracking = false
|
||||||
|
mouseState.activeId = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Update mouse coordinates from screen position
|
||||||
|
---@param screenX number Screen X coordinate
|
||||||
|
---@param screenY number Screen Y coordinate
|
||||||
|
---@return boolean updated Whether coordinates were updated
|
||||||
|
local function UpdateMousePosition(screenX, screenY)
|
||||||
|
if not mouseState.tracking or not mouseState.activeId then return false end
|
||||||
|
|
||||||
|
local instance = activeInstances[mouseState.activeId]
|
||||||
|
if not instance or not instance.trackMouse then return false end
|
||||||
|
|
||||||
|
-- Scale coordinates based on DUI dimensions and scale factors
|
||||||
|
local scaledX = screenX * instance.mouseScale.x
|
||||||
|
local scaledY = screenY * instance.mouseScale.y
|
||||||
|
|
||||||
|
-- Only update if position changed
|
||||||
|
if scaledX ~= mouseState.lastX or scaledY ~= mouseState.lastY then
|
||||||
|
mouseState.lastX = scaledX
|
||||||
|
mouseState.lastY = scaledY
|
||||||
|
DUI.MoveMouse(mouseState.activeId, scaledX, scaledY)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Mouse tracking thread
|
||||||
|
Citizen.CreateThread(function()
|
||||||
|
while true do
|
||||||
|
if mouseState.tracking and mouseState.activeId then
|
||||||
|
local instance = activeInstances[mouseState.activeId]
|
||||||
|
if instance and instance.trackMouse then
|
||||||
|
-- Get current cursor position
|
||||||
|
local screenX, screenY = GetNuiCursorPosition()
|
||||||
|
UpdateMousePosition(screenX, screenY)
|
||||||
|
|
||||||
|
-- Handle held mouse buttons
|
||||||
|
if mouseState.isPressed and mouseState.currentButton then
|
||||||
|
-- Keep the button pressed state
|
||||||
|
SendDuiMouseDown(instance.handle, mouseState.currentButton)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Citizen.Wait(0)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Utility functions
|
||||||
|
|
||||||
|
-- Get textures for a DUI instance
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@return string|nil txd, string|nil txn Texture dictionary and name, or nil if instance not found
|
||||||
|
function DUI.GetTextures(id)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
if not instance then return nil, nil end
|
||||||
|
|
||||||
|
return instance.txd, instance.txn
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check if a DUI instance exists
|
||||||
|
---@param id number DUI instance ID
|
||||||
|
---@return boolean exists Whether the instance exists and is active
|
||||||
|
function DUI.Exists(id)
|
||||||
|
local instance = activeInstances[id]
|
||||||
|
return instance ~= nil and instance.active
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get all active DUI instances
|
||||||
|
---@return table<number, DUIInstance> instances Table of active DUI instances
|
||||||
|
function DUI.GetActiveInstances()
|
||||||
|
return activeInstances
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Cleanup all DUI instances
|
||||||
|
function DUI.CleanupAll()
|
||||||
|
for id in pairs(activeInstances) do
|
||||||
|
DUI.Destroy(id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Automatic cleanup on resource stop
|
||||||
|
AddEventHandler('onResourceStop', function(resourceName)
|
||||||
|
if GetCurrentResourceName() ~= resourceName then return end
|
||||||
|
DUI.CleanupAll()
|
||||||
|
end)
|
||||||
|
|
||||||
|
return DUI
|
||||||
@@ -1,40 +1,84 @@
|
|||||||
Scaleform = {}
|
---@class Scaleform
|
||||||
|
local Scaleform = {}
|
||||||
|
|
||||||
function SetupScaleform(scaleform, Buttons)
|
-- Constants
|
||||||
local scaleform = RequestScaleformMovie(scaleform)
|
local SCALEFORM_TIMEOUT = 5000
|
||||||
local timeout = 5000
|
local BACKGROUND_COLOR_VALUE = 80
|
||||||
|
local CONTROL_TYPE = 2
|
||||||
|
local RENDER_WAIT_TIME = 2
|
||||||
|
|
||||||
|
-- Local utility functions
|
||||||
|
local function setupButton(scaleform, button)
|
||||||
|
PushScaleformMovieFunction(scaleform, button.type)
|
||||||
|
|
||||||
|
if button.int then
|
||||||
|
PushScaleformMovieFunctionParameterInt(button.int)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle key index setup
|
||||||
|
if button.keyIndex then
|
||||||
|
if type(button.keyIndex) == "table" then
|
||||||
|
for _, keyCode in pairs(button.keyIndex) do
|
||||||
|
N_0xe83a3e3557a56640(GetControlInstructionalButton(CONTROL_TYPE, keyCode, true))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(CONTROL_TYPE, button.keyIndex[1],
|
||||||
|
true))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle button name setup
|
||||||
|
if button.name then
|
||||||
|
BeginTextCommandScaleformString("STRING")
|
||||||
|
AddTextComponentScaleform(button.name)
|
||||||
|
EndTextCommandScaleformString()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle background color
|
||||||
|
if button.type == 'SET_BACKGROUND_COLOUR' then
|
||||||
|
for _ = 1, 4 do
|
||||||
|
PushScaleformMovieFunctionParameterInt(BACKGROUND_COLOR_VALUE)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
PopScaleformMovieFunctionVoid()
|
||||||
|
end
|
||||||
|
|
||||||
|
---Creates and sets up a scaleform movie
|
||||||
|
---@param scaleformName string The name of the scaleform to load
|
||||||
|
---@param buttons table Array of button configurations
|
||||||
|
---@return number scaleform The loaded scaleform handle
|
||||||
|
local function setupScaleform(scaleformName, buttons)
|
||||||
|
local scaleform = RequestScaleformMovie(scaleformName)
|
||||||
|
local timeout = SCALEFORM_TIMEOUT
|
||||||
|
|
||||||
|
-- Wait for scaleform to load
|
||||||
while not HasScaleformMovieLoaded(scaleform) and timeout > 0 do
|
while not HasScaleformMovieLoaded(scaleform) and timeout > 0 do
|
||||||
timeout = timeout - 1
|
timeout = timeout - 1
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
assert(timeout > 0, 'Scaleform failed to load')
|
|
||||||
|
if timeout <= 0 then
|
||||||
|
error('Scaleform failed to load: ' .. scaleformName)
|
||||||
|
end
|
||||||
|
|
||||||
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 0, 0)
|
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 0, 0)
|
||||||
for i = 1,#Buttons do
|
|
||||||
PushScaleformMovieFunction(scaleform, Buttons[i].type)
|
-- Setup each button
|
||||||
if Buttons[i].int then PushScaleformMovieFunctionParameterInt(Buttons[i].int) end
|
for _, button in ipairs(buttons) do
|
||||||
if Buttons[i].keyIndex then
|
setupButton(scaleform, button)
|
||||||
if type(Buttons[i].keyIndex) == "table" then
|
|
||||||
for _, v in pairs(Buttons[i].keyIndex) do N_0xe83a3e3557a56640(GetControlInstructionalButton(2, v, true)) end
|
|
||||||
else
|
|
||||||
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(2, Buttons[i].keyIndex[1], true))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if Buttons[i].name then
|
|
||||||
BeginTextCommandScaleformString("STRING")
|
|
||||||
AddTextComponentScaleform(Buttons[i].name)
|
|
||||||
EndTextCommandScaleformString()
|
|
||||||
end
|
|
||||||
if Buttons[i].type == 'SET_BACKGROUND_COLOUR' then
|
|
||||||
for u = 1,4 do PushScaleformMovieFunctionParameterInt(80) end
|
|
||||||
end
|
|
||||||
PopScaleformMovieFunctionVoid()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return scaleform
|
return scaleform
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Sets up instructional buttons with default configuration
|
||||||
|
---@param buttons table Optional custom button configuration
|
||||||
|
---@return number scaleform The configured instructional buttons scaleform
|
||||||
function Scaleform.SetupInstructionalButtons(buttons)
|
function Scaleform.SetupInstructionalButtons(buttons)
|
||||||
buttons = buttons or {
|
buttons = buttons or {
|
||||||
|
-- Default button configuration commented out
|
||||||
|
-- Uncomment and modify as needed
|
||||||
-- {type = "CLEAR_ALL"},
|
-- {type = "CLEAR_ALL"},
|
||||||
-- {type = "SET_CLEAR_SPACE", int = 200},
|
-- {type = "SET_CLEAR_SPACE", int = 200},
|
||||||
-- {type = "SET_DATA_SLOT", name = config?.place_object?.name or 'Place Object:', keyIndex = config?.place_object?.key or {223}, int = 5},
|
-- {type = "SET_DATA_SLOT", name = config?.place_object?.name or 'Place Object:', keyIndex = config?.place_object?.key or {223}, int = 5},
|
||||||
@@ -46,34 +90,41 @@ function Scaleform.SetupInstructionalButtons(buttons)
|
|||||||
-- {type = "DRAW_INSTRUCTIONAL_BUTTONS"},
|
-- {type = "DRAW_INSTRUCTIONAL_BUTTONS"},
|
||||||
-- {type = "SET_BACKGROUND_COLOUR"},
|
-- {type = "SET_BACKGROUND_COLOUR"},
|
||||||
}
|
}
|
||||||
local scaleform = SetupScaleform("instructional_buttons", buttons)
|
|
||||||
|
|
||||||
return scaleform
|
return setupScaleform("instructional_buttons", buttons)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Active scaleform tracking
|
||||||
|
local activeScaleform = nil
|
||||||
|
|
||||||
local runningScaleform = nil
|
---Runs a scaleform with optional update callback
|
||||||
|
---@param scaleform number The scaleform handle to run
|
||||||
|
---@param onUpdate function Optional callback for updates during runtime
|
||||||
function Scaleform.Run(scaleform, onUpdate)
|
function Scaleform.Run(scaleform, onUpdate)
|
||||||
if runningScaleform then return end
|
if activeScaleform then return end
|
||||||
runningScaleform = scaleform
|
activeScaleform = scaleform
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while runningScaleform do
|
while activeScaleform do
|
||||||
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
|
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
|
||||||
|
|
||||||
if onUpdate then
|
if onUpdate then
|
||||||
shouldQuit = onUpdate()
|
local shouldStop = onUpdate()
|
||||||
if shouldQuit then
|
if shouldStop then
|
||||||
Scaleform.Stop()
|
Scaleform.Stop()
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Wait(2)
|
|
||||||
|
Wait(RENDER_WAIT_TIME)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Stops the currently running scaleform
|
||||||
function Scaleform.Stop()
|
function Scaleform.Stop()
|
||||||
runningScaleform = nil
|
activeScaleform = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
exports("Scaleform", Scaleform)
|
exports("Scaleform", Scaleform)
|
||||||
return Scaleform
|
return Scaleform
|
||||||
@@ -495,6 +495,7 @@ print("Result:", result)
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|
||||||
AddEventHandler('onResourceStop', function(resource)
|
AddEventHandler('onResourceStop', function(resource)
|
||||||
if resource ~= GetCurrentResourceName() then return end
|
if resource ~= GetCurrentResourceName() then return end
|
||||||
for _, blip in pairs(blipIDs) do
|
for _, blip in pairs(blipIDs) do
|
||||||
|
|||||||
@@ -103,14 +103,14 @@ Framework.GetPlayerInventory = function(src)
|
|||||||
local playerItems = xPlayer.getInventory()
|
local playerItems = xPlayer.getInventory()
|
||||||
local repackedTable = {}
|
local repackedTable = {}
|
||||||
for _, v in pairs(playerItems) do
|
for _, v in pairs(playerItems) do
|
||||||
if v.count > 0 then
|
if v.count > 0 then
|
||||||
table.insert(repackedTable, {
|
table.insert(repackedTable, {
|
||||||
name = v.name,
|
name = v.name,
|
||||||
count = v.count,
|
count = v.count,
|
||||||
--metadata = v.metadata,
|
--metadata = v.metadata,
|
||||||
--slot = v.slot,
|
--slot = v.slot,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return repackedTable
|
return repackedTable
|
||||||
end
|
end
|
||||||
@@ -133,9 +133,9 @@ Framework.GetPlayerMetadata = function(src, metadata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- defualt esx Available tables are
|
-- defualt esx Available tables are
|
||||||
-- identifier, accounts, group, inventory, job, job_grade, loadout,
|
-- identifier, accounts, group, inventory, job, job_grade, loadout,
|
||||||
-- metadata, position, firstname, lastname, dateofbirth, sex, height,
|
-- metadata, position, firstname, lastname, dateofbirth, sex, height,
|
||||||
-- skin, status, is_dead, id, disabled, last_property, created_at, last_seen,
|
-- skin, status, is_dead, id, disabled, last_property, created_at, last_seen,
|
||||||
-- phone_number, pincode
|
-- phone_number, pincode
|
||||||
Framework.GetStatus = function(src, column)
|
Framework.GetStatus = function(src, column)
|
||||||
local xPlayer = ESX.GetPlayerFromId(src)
|
local xPlayer = ESX.GetPlayerFromId(src)
|
||||||
@@ -250,7 +250,10 @@ end
|
|||||||
Framework.SetPlayerJob = function(src, name, grade)
|
Framework.SetPlayerJob = function(src, name, grade)
|
||||||
local xPlayer = ESX.GetPlayerFromId(src)
|
local xPlayer = ESX.GetPlayerFromId(src)
|
||||||
if not xPlayer then return end
|
if not xPlayer then return end
|
||||||
if not ESX.DoesJobExist(name, grade) then lib.print.error("Job Does Not Exsist In Framework :NAME "..name.." Grade:"..grade) return end
|
if not ESX.DoesJobExist(name, grade) then
|
||||||
|
lib.print.error("Job Does Not Exsist In Framework :NAME " .. name .. " Grade:" .. grade)
|
||||||
|
return
|
||||||
|
end
|
||||||
return xPlayer.setJob(name, grade, true)
|
return xPlayer.setJob(name, grade, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -301,14 +304,14 @@ end
|
|||||||
Framework.GetOwnedVehicles = function(src)
|
Framework.GetOwnedVehicles = function(src)
|
||||||
local citizenId = Framework.GetPlayerIdentifier(src)
|
local citizenId = Framework.GetPlayerIdentifier(src)
|
||||||
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "'")
|
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "'")
|
||||||
local vehicles = {}
|
local vehicles = {}
|
||||||
for i=1, #result do
|
for i = 1, #result do
|
||||||
local vehicle = result[i].vehicle
|
local vehicle = result[i].vehicle
|
||||||
local plate = result[i].plate
|
local plate = result[i].plate
|
||||||
local model = json.decode(vehicle).model
|
local model = json.decode(vehicle).model
|
||||||
table.insert(vehicles, {vehicle = model, plate = plate})
|
table.insert(vehicles, { vehicle = model, plate = plate })
|
||||||
end
|
end
|
||||||
return vehicles
|
return vehicles
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Framework.RegisterUsableItem(item, cb)
|
-- Framework.RegisterUsableItem(item, cb)
|
||||||
@@ -339,7 +342,7 @@ AddEventHandler("playerDropped", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
lib.callback.register('community_bridge:Callback:GetFrameworkJobs', function(source)
|
lib.callback.register('community_bridge:Callback:GetFrameworkJobs', function(source)
|
||||||
return Framework.GetFrameworkJobs() or {}
|
return Framework.GetFrameworkJobs() or {}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Framework.Commands = {}
|
Framework.Commands = {}
|
||||||
@@ -351,5 +354,3 @@ Framework.Commands.Add = function(name, help, arguments, argsrequired, callback,
|
|||||||
arguments = arguments
|
arguments = arguments
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return Framework
|
|
||||||
@@ -238,7 +238,7 @@ Framework.AddHunger = function(src, value)
|
|||||||
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
|
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
|
||||||
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, playerData.metadata.thirst)
|
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, playerData.metadata.thirst)
|
||||||
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
||||||
|
|
||||||
return newHunger
|
return newHunger
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ end
|
|||||||
Framework.RevivePlayer = function(src)
|
Framework.RevivePlayer = function(src)
|
||||||
src = tonumber(src)
|
src = tonumber(src)
|
||||||
if not src then return false end
|
if not src then return false end
|
||||||
TriggerClientEvent('hospital:client:Revive', src)
|
TriggerClientEvent('hospital:client:Revive', src)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -413,7 +413,8 @@ end
|
|||||||
Framework.AddItem = function(src, item, amount, slot, metadata)
|
Framework.AddItem = function(src, item, amount, slot, metadata)
|
||||||
local player = QBCore.Functions.GetPlayer(src)
|
local player = QBCore.Functions.GetPlayer(src)
|
||||||
if not player then return end
|
if not player then return end
|
||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata})
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src,
|
||||||
|
{ action = "add", item = item, count = amount, slot = slot, metadata = metadata })
|
||||||
return player.Functions.AddItem(item, amount, slot, metadata)
|
return player.Functions.AddItem(item, amount, slot, metadata)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -422,7 +423,8 @@ end
|
|||||||
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
||||||
local player = QBCore.Functions.GetPlayer(src)
|
local player = QBCore.Functions.GetPlayer(src)
|
||||||
if not player then return end
|
if not player then return end
|
||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src,
|
||||||
|
{ action = "remove", item = item, count = amount, slot = slot, metadata = metadata })
|
||||||
return player.Functions.RemoveItem(item, amount, slot or nil)
|
return player.Functions.RemoveItem(item, amount, slot or nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -452,12 +454,13 @@ end
|
|||||||
---@return table
|
---@return table
|
||||||
Framework.GetOwnedVehicles = function(src)
|
Framework.GetOwnedVehicles = function(src)
|
||||||
local citizenId = Framework.GetPlayerIdentifier(src)
|
local citizenId = Framework.GetPlayerIdentifier(src)
|
||||||
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" .. citizenId .. "'")
|
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" ..
|
||||||
|
citizenId .. "'")
|
||||||
local vehicles = {}
|
local vehicles = {}
|
||||||
for i=1, #result do
|
for i = 1, #result do
|
||||||
local vehicle = result[i].vehicle
|
local vehicle = result[i].vehicle
|
||||||
local plate = result[i].plate
|
local plate = result[i].plate
|
||||||
table.insert(vehicles, {vehicle = vehicle, plate = plate})
|
table.insert(vehicles, { vehicle = vehicle, plate = plate })
|
||||||
end
|
end
|
||||||
return vehicles
|
return vehicles
|
||||||
end
|
end
|
||||||
@@ -493,5 +496,3 @@ Framework.Commands = {}
|
|||||||
Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...)
|
Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...)
|
||||||
QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
|
QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Framework
|
|
||||||
@@ -237,7 +237,7 @@ end
|
|||||||
Framework.RevivePlayer = function(src)
|
Framework.RevivePlayer = function(src)
|
||||||
src = tonumber(src)
|
src = tonumber(src)
|
||||||
if not src then return false end
|
if not src then return false end
|
||||||
TriggerClientEvent('hospital:client:Revive', src)
|
TriggerClientEvent('hospital:client:Revive', src)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -375,7 +375,8 @@ end
|
|||||||
Framework.AddItem = function(src, item, amount, slot, metadata)
|
Framework.AddItem = function(src, item, amount, slot, metadata)
|
||||||
local player = QBox:GetPlayer(src)
|
local player = QBox:GetPlayer(src)
|
||||||
if not player then return end
|
if not player then return end
|
||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata})
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src,
|
||||||
|
{ action = "add", item = item, count = amount, slot = slot, metadata = metadata })
|
||||||
return player.Functions.AddItem(item, amount, slot, metadata)
|
return player.Functions.AddItem(item, amount, slot, metadata)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -389,7 +390,8 @@ end
|
|||||||
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
||||||
local player = QBox:GetPlayer(src)
|
local player = QBox:GetPlayer(src)
|
||||||
if not player then return end
|
if not player then return end
|
||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src,
|
||||||
|
{ action = "remove", item = item, count = amount, slot = slot, metadata = metadata })
|
||||||
return player.Functions.RemoveItem(item, amount, slot)
|
return player.Functions.RemoveItem(item, amount, slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -411,12 +413,13 @@ end
|
|||||||
---@return table
|
---@return table
|
||||||
Framework.GetOwnedVehicles = function(src)
|
Framework.GetOwnedVehicles = function(src)
|
||||||
local citizenId = Framework.GetPlayerIdentifier(src)
|
local citizenId = Framework.GetPlayerIdentifier(src)
|
||||||
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" .. citizenId .. "'")
|
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" ..
|
||||||
|
citizenId .. "'")
|
||||||
local vehicles = {}
|
local vehicles = {}
|
||||||
for i=1, #result do
|
for i = 1, #result do
|
||||||
local vehicle = result[i].vehicle
|
local vehicle = result[i].vehicle
|
||||||
local plate = result[i].plate
|
local plate = result[i].plate
|
||||||
table.insert(vehicles, {vehicle = vehicle, plate = plate})
|
table.insert(vehicles, { vehicle = vehicle, plate = plate })
|
||||||
end
|
end
|
||||||
return vehicles
|
return vehicles
|
||||||
end
|
end
|
||||||
@@ -449,5 +452,3 @@ AddEventHandler("playerDropped", function()
|
|||||||
local src = source
|
local src = source
|
||||||
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return Framework
|
|
||||||
Reference in new issue
Block a user