Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: ESX Implementation #92

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/Walk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ if Config.WalkingStylesEnabled and Config.PersistentWalk then
Wait(3000)
handleWalkstyle()
end)

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', handleWalkstyle)
RegisterNetEvent('esx:playerLoaded', handleWalkstyle)

Expand Down
93 changes: 93 additions & 0 deletions client/frameworks/esx.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
if Config.Framework ~= 'esx' then return end

local framework = 'es_extended'
local state = GetResourceState(framework)

if state == 'missing' or state == "unknown" then
-- Framework can't be used if it's missing or unknown
return
end

ESX, PlayerData, isLoggedIn = nil, nil, false

-- ESX core parts
ESX = exports[framework]:getSharedObject()
PlayerData = ESX.GetPlayerData()
isLoggedIn = false

RegisterNetEvent('esx:onPlayerSpawn', function()
PlayerData = ESX.GetPlayerData()
isLoggedIn = true
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 = ESX.GetPlayerData()
isLoggedIn = true
end
end)

function CanUseFavKeyBind()
return not ESX.PlayerData.dead
end

-- Added events
RegisterNetEvent('animations:client:PlayEmote', function(args)
if not ESX.PlayerData.dead then
EmoteCommandStart(source, args)
end
end)

if Config.SqlKeybinding then
RegisterNetEvent('animations:client:BindEmote', function(args)
if not ESX.PlayerData.dead then
EmoteBindStart(source, args)
end
end)

RegisterNetEvent('animations:client:EmoteBinds', function()
if not ESX.PlayerData.dead then
EmoteBindsStart()
end
end)
end

RegisterNetEvent('animations:client:EmoteMenu', function()
if not ESX.PlayerData.dead then
OpenEmoteMenu()
end
end)

RegisterNetEvent('animations:client:ListEmotes', function()
if not ESX.PlayerData.dead then
EmotesOnCommand()
end
end)

RegisterNetEvent('animations:client:Walk', function(args)
if not ESX.PlayerData.dead then
WalkCommandStart(source, args)
end
end)

RegisterNetEvent('animations:client:ListWalks', function()
if not ESX.PlayerData.dead 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)
4 changes: 2 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Config = {
FavKeybind = 'capital', -- Get the button string here https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/
SqlKeybinding = false, -- If you have the SQL imported enable this to turn on keybinding.
NotificationsAsChatMessage = false, -- If you don't like native GTA 5 notifications, you can disable them here to have messages in the chat.
Framework = 'qb-core', -- Used for few framework-dependent things. Accepted values: 'qb-core', false
Framework = 'qb-core', -- Used for few framework-dependent things. Accepted values: 'qb-core', 'esx' or false
Search = true, -- Used to enable or disable the search feature in the menu.
CancelPreviousEmote = false, -- If turned on, playing an emote will cancel the previous one.
DisableControls = false, -- Disable specific controls when menu is open, can be configured in NativeUI.lua:2452 (approximately)
Expand Down Expand Up @@ -138,4 +138,4 @@ Config.Credits = {
{title = "Thanks <font color=\"#ff451d\">DRX Animations 👑</font>", subtitle = "<font color=\"#ff451d\">DRX Animations 👑</font> for the custom animations"},
{title = "Thanks <font color=\"#12ab0a\">Radial 🫡</font>", subtitle = "<font color=\"#12ab0a\">Radial</font> on discord for contributing animations code"},
{title = "<font color=\"#FF25B1\"><b>TayMcKenzieNZ 🇳🇿<b></font>", subtitle = "<font color=\"#FF25B1\">TayMcKenzieNZ 🇳🇿</font> Previous maintainer of RP Emotes."},
}
}
53 changes: 53 additions & 0 deletions server/frameworks/esx.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
if Config.Framework ~= 'esx' then return end

local framework = 'esx'
local state = GetResourceState(framework)

if state == 'missing' or state == "unknown" then
-- Framework can't be used if it's missing or unknown
return
end

local ESX = exports['es_extended']:getSharedObject()

ESX.RegisterCommand('e', 'Play an emote', {{ name="emotename", help="dance, camera, sit or any valid emote."}}, true, function(source, args)
TriggerClientEvent('animations:client:PlayEmote', source, args)
end)

ESX.RegisterCommand('emote', 'Play an emote', {{ name="emotename", help="dance, camera, sit or any valid emote."}}, true, function(source, args)
TriggerClientEvent('animations:client:PlayEmote', source, args)
end)

if Config.SqlKeybinding then
ESX.RegisterCommand('emotebind', 'Bind an emote', {{ name="key", help="num4, num5, num6, num7. num8, num9. Numpad 4-9!"}, { name="emotename", help="dance, camera, sit or any valid emote."}}, true, function(source, args)
TriggerClientEvent('animations:client:BindEmote', source, args)
end)

ESX.RegisterCommand('emotebinds', 'Check your currently bound emotes.', {}, false, function(source)
TriggerClientEvent('animations:client:EmoteBinds', source)
end)
end

ESX.RegisterCommand('emotemenu', 'Open rpemotes menu (F3) by default.', {}, false, function(source)
TriggerClientEvent('animations:client:EmoteMenu', source)
end)

ESX.RegisterCommand('em', 'Open rpemotes menu (F3) by default.', {}, false, function(source)
TriggerClientEvent('animations:client:EmoteMenu', source)
end)

ESX.RegisterCommand('emotes', 'List available emotes.', {}, false, function(source)
TriggerClientEvent('animations:client:ListEmotes', source)
end)

ESX.RegisterCommand('walk', 'Set your walkingstyle.', {{ name="style", help="/walks for a list of valid styles"}}, true, function(source, args)
TriggerClientEvent('animations:client:Walk', source, args)
end)

ESX.RegisterCommand('walks', 'List available walking styles.', {}, false, function(source)
TriggerClientEvent('animations:client:ListWalks', source)
end)

ESX.RegisterCommand('nearby', 'Share emote with a nearby player.', {{ name="emotename", help="hug, handshake, bro or any valid shared emote."}}, true, function(source, args)
TriggerClientEvent('animations:client:Nearby', source, args)
end)