Skip to content

feat(es_extended): add static player methods#1601

Merged
Kenshiin13 merged 7 commits into
esx-framework:devfrom
Kenshiin13:static-player
Jan 23, 2025
Merged

feat(es_extended): add static player methods#1601
Kenshiin13 merged 7 commits into
esx-framework:devfrom
Kenshiin13:static-player

Conversation

@Kenshiin13

@Kenshiin13 Kenshiin13 commented Jan 22, 2025

Copy link
Copy Markdown
Contributor

Description

Introducing static ESX Player methods to streamline player handling. Instead of dealing with a bloated xPlayer object that can impact performance as player counts grow, this implementation provides a lightweight alternative by dynamically calling only the required functionality through exports.


Motivation

The current xPlayer object is overly bloated, storing unnecessary data that scales poorly with larger player bases. This approach addresses these performance concerns while maintaining a syntax familiar to ESX developers.


Implementation Details

The ESX.Player object uses a metamethod to return a lightweight table containing only the player's server ID when called. If the requested player is offline, it simply returns nil. For any subsequent method calls, the stored server ID is used to trigger the appropriate export, ensuring efficient and dynamic behavior.


Usage Example

local src = 1
local xPlayer = ESX.Player(src)
if (not xPlayer) then
    print("player not found")
    return
end

print(xPlayer.getIdentifier())

local identifier = "char1:12754a0705e35cda21ced87c7daf329730135087"
local xTarget = ESX.Player(identifier)
if (not xTarget) then
    print("target not found")
    return
end

print(xTarget.getIdentifier())

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.

@Kenshiin13 Kenshiin13 marked this pull request as ready for review January 22, 2025 15:18
@Kenshiin13 Kenshiin13 self-assigned this Jan 22, 2025
Arctos2win
Arctos2win previously approved these changes Jan 22, 2025

@Arctos2win Arctos2win left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@Arctos2win Arctos2win left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Kenshiin13 Kenshiin13 merged commit 2dac443 into esx-framework:dev Jan 23, 2025
@Kenshiin13 Kenshiin13 deleted the static-player branch January 23, 2025 11:32
@Kenshiin13

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for Next Update

Development

Successfully merging this pull request may close these issues.

2 participants