Skip to content

Conversation

HR0110
Copy link

@HR0110 HR0110 commented Sep 14, 2025

Description

This pull request changes the whole xPlayer code and the code around it, it fixes the code with xPlayer, optimizes it a bit and adds a new feature to the whole ESX table, ESX.XPlayerClass which is a metatable value which has .addHook and .removeHook fields that allow to add hooks to specific functions in the xPlayer, usable in all scripts that use es_extended's xPlayer. It allows the developers to change the code of the functions entirely or particulary. To the .addHook field, there is a isJustAddition parameter that sets whether or not the provided hook function is to replace the whole function or just be as addition that can stop the original function execute by returning false. This is going to be very helpful to any developer, working with ESX framework.

Usage Example

local xPlayer = ESX.Player(source)

xPlayer.addMoney(250) -- There is no output

local hookExample = ESX.XPlayerClass.addHook('addMoney', true, function(xPlayer, amount)
    print(('Player %s received $%s as cash.'):format(GetPlayerName(xPlayer.source), amount))
end)

xPlayer.addMoney(300) -- Output: `Player example received $300 as cash.`

local success = ESX.XPlayerClass.removeHook(hookExample)
print(success) -- And because the hook exists, the output will be `true`

xPlayer.addMoney(350) -- There is no output

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant