From 7eaf5a3c96da94e5de811508dd6b6fc24fed9065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20RICATTE?= Date: Fri, 8 Jul 2022 16:07:21 +0200 Subject: [PATCH] =?UTF-8?q?feat(framework):=20=E2=9C=A8=20add=20required?= =?UTF-8?q?=20events=20for=20qb-core=20(#20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(framework): :sparkles: add required events for qb-core This should hopefully work as intended. Adding things that were added to https://github.com/qbcore-framework/dpemotes for qb servers using this version of dpemotes --- client/AnimationList.lua | 26 +++++++-- client/EmoteMenu.lua | 4 +- client/frameworks/qb-core.lua | 102 ++++++++++++++++++++++++++++++++++ config.lua | 2 + fxmanifest.lua | 5 +- version | 2 +- 6 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 client/frameworks/qb-core.lua diff --git a/client/AnimationList.lua b/client/AnimationList.lua index e6ab0db..536d4f2 100644 --- a/client/AnimationList.lua +++ b/client/AnimationList.lua @@ -3982,14 +3982,14 @@ DP.PropEmotes = { PropPlacement = { 0.0480, 0.0780, 0.0040, -81.6893, 2.5616, -15.7909 }, EmoteLoop = true, EmoteMoving = true, - }}, - ["cop4"] = { "amb@world_human_car_park_attendant@male@base", "base", "Cop 4", AnimationOptions = { + }}, + ["cop4"] = { "amb@world_human_car_park_attendant@male@base", "base", "Cop 4", AnimationOptions = { Prop = "prop_parking_wand_01", PropBone = 57005, PropPlacement = { 0.12, 0.05, 0.0, 80.0, -20.0, 180.0 }, EmoteLoop = true, EmoteMoving = true, - } }, + }}, ["leanphone"] = { "amb@world_human_leaning@male@wall@back@mobile@base", "base", "Leaning With Phone", AnimationOptions = { EmoteMoving = false, EmoteLoop = true, @@ -4005,12 +4005,28 @@ DP.PropEmotes = { PtfxPlacement = { -0.05, 0.3, 0.0, 0.0, 90.0, 90.0, 1.0 }, PtfxInfo = Config.Languages[Config.MenuLanguage]['pee'], PtfxWait = 3000, - } }, + }}, ["hump"] = { "timetable@trevor@skull_loving_bear", "skull_loving_bear", "Hump (Bear)", AnimationOptions = { Prop = 'prop_mr_raspberry_01', PropBone = 28422, PropPlacement = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, EmoteMoving = false, EmoteLoop = true, - } }, + }}, + ["eat"] = {"mp_player_inteat@burger", "mp_player_int_eat_burger_fp", "Eat", AnimationOptions = + { + Prop = "prop_cs_burger_01", + PropBone = 18905, + PropPlacement = {0.12, 0.028, 0.001, 10.0, 175.0}, + EmoteMoving = true, + EmoteLoop = true, + }}, + ["drink"] = {"mp_player_intdrink", "loop_bottle", "Drink", AnimationOptions = + { + Prop = "prop_ld_flow_bottle", + PropBone = 18905, + PropPlacement = {0.12, 0.008, 0.03, 240.0, -60.0}, + EmoteMoving = true, + EmoteLoop = true, + }}, } diff --git a/client/EmoteMenu.lua b/client/EmoteMenu.lua index f405f46..0d8594e 100644 --- a/client/EmoteMenu.lua +++ b/client/EmoteMenu.lua @@ -49,13 +49,13 @@ if Config.FavKeybindEnabled then while true do if IsControlPressed(0, Config.FavKeybind) then if not IsPedSittingInAnyVehicle(PlayerPedId()) then - if FavoriteEmote ~= "" then + if FavoriteEmote ~= "" and (not CanUseFavKeyBind or CanUseFavKeyBind()) then EmoteCommandStart(nil, { FavoriteEmote, 0 }) Wait(3000) end end end - Citizen.Wait(1) + Citizen.Wait(0) end end) end diff --git a/client/frameworks/qb-core.lua b/client/frameworks/qb-core.lua new file mode 100644 index 0000000..5f30aa0 --- /dev/null +++ b/client/frameworks/qb-core.lua @@ -0,0 +1,102 @@ +if Config.Framework ~= 'qb-core' then return end + +local framework = 'qb-core' +local state = GetResourceState(framework) + +if state == 'missing' or state == "unknown" then + -- Framework can't be used if it's missing or unknown + return +end + +QBCore, PlayerData, isLoggedIn = nil, nil, false + +-- QB core parts +QBCore = exports[framework]:GetCoreObject() +PlayerData = QBCore.Functions.GetPlayerData() +isLoggedIn = false + +RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() + PlayerData = QBCore.Functions.GetPlayerData() + isLoggedIn = true +end) + +RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() + PlayerData = {} + isLoggedIn = false +end) + +RegisterNetEvent('QBCore:Player:SetPlayerData', function(val) + PlayerData = val +end) + +-- This is here to get the player data when the resource is restarted instead of having to log out and back in each time +-- This won't set the player data too early as this only triggers when the server side is started and not the client side +AddEventHandler('onResourceStart', function(resource) + if resource == GetCurrentResourceName() then + Wait(200) + PlayerData = QBCore.Functions.GetPlayerData() + isLoggedIn = true + end +end) + +function CanUseFavKeyBind() + return not PlayerData.metadata['inlaststand'] and not PlayerData.metadata['isdead'] +end + +-- Added events +RegisterNetEvent('animations:client:PlayEmote', function(args) + if not PlayerData.metadata['inlaststand'] and not PlayerData.metadata['isdead'] then + EmoteCommandStart(source, args) + end +end) + +if Config.SqlKeybinding then + RegisterNetEvent('animations:client:BindEmote', function(args) + if not PlayerData.metadata['inlaststand'] and not PlayerData.metadata['isdead'] then + EmoteBindStart(source, args) + end + end) + + RegisterNetEvent('animations:client:EmoteBinds', function() + if not PlayerData.metadata['inlaststand'] and not PlayerData.metadata['isdead'] then + EmoteBindsStart() + end + end) +end + +RegisterNetEvent('animations:client:EmoteMenu', function() + if not PlayerData.metadata['inlaststand'] and not PlayerData.metadata['isdead'] then + OpenEmoteMenu() + end +end) + +RegisterNetEvent('animations:client:ListEmotes', function() + if not PlayerData.metadata['inlaststand'] and not PlayerData.metadata['isdead'] then + EmotesOnCommand() + end +end) + +RegisterNetEvent('animations:client:Walk', function(args) + if not PlayerData.metadata['inlaststand'] and not PlayerData.metadata['isdead'] then + WalkCommandStart(source, args) + end +end) + +RegisterNetEvent('animations:client:ListWalks', function() + if not PlayerData.metadata['inlaststand'] and not PlayerData.metadata['isdead'] then + WalksOnCommand() + end +end) + +-- Added by https://github.dev/qbcore-framework/dpemotes/ + +CanDoEmote = true +RegisterNetEvent('animations:ToggleCanDoAnims', function(bool) + CanDoEmote = bool +end) + +RegisterNetEvent('animations:client:EmoteCommandStart', function(args) + if CanDoEmote then + EmoteCommandStart(source, args) + end +end) diff --git a/config.lua b/config.lua index 8730155..54213df 100644 --- a/config.lua +++ b/config.lua @@ -40,6 +40,8 @@ Config = { CheckForUpdates = true, -- If you have the SQL imported enable this to turn on keybinding. SqlKeybinding = false, + -- Used for few framework dependent things. Accepted values: qb-core, false + Framework = false, } Config.KeybindKeys = { diff --git a/fxmanifest.lua b/fxmanifest.lua index 91c859b..008f491 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -6,7 +6,7 @@ fx_version 'adamant' game 'gta5' --- Comment the following linnes if you don't want to use the SQL keybinds +-- Comment the following lines if you don't want to use the SQL keybinds --#region oxmysql -- dependency 'oxmysql' -- server_script "@oxmysql/lib/MySQL.lua" @@ -23,7 +23,8 @@ server_scripts { client_scripts { 'NativeUI.lua', - 'client/*.lua' + 'client/*.lua', + 'client/frameworks/*.lua' } diff --git a/version b/version index bea0d09..6e16ebf 100644 --- a/version +++ b/version @@ -1 +1 @@ -207 \ No newline at end of file +208 \ No newline at end of file