xPlayer overview

ภาพรวม Player Object (xPlayer), Properties ที่พบบ่อย และหมวดหมู่ของ Methods ที่ใช้งานบ่อย

ภาพรวม xPlayer

xPlayer คือ Object ของผู้เล่นฝั่ง Server

ใช้สำหรับจัดการข้อมูลและการกระทำของผู้เล่นแบบรวมศูนย์

คุณสามารถดึงข้อมูล xPlayer ได้จาก ESX.GetPlayerFromId(source)

หรือใช้ ESX.GetPlayerFromIdentifier(identifier)

จากนั้นสามารถเรียก Methods ผ่าน Object นี้ได้โดยตรง

circle-info

xPlayer สามารถใช้งานได้ในสคริปต์ฝั่ง Server เท่านั้น

circle-exclamation

การดึงข้อมูล xPlayer

examples.lua
-- จาก server ID (source)
local xPlayer = ESX.GetPlayerFromId(source)

-- จาก identifier
local xPlayerByIdentifier = ESX.GetPlayerFromIdentifier('license:abc123')
circle-info

ESX.GetPlayerFromId() เป็นรูปแบบที่ใช้งานบ่อยที่สุด เมื่อคุณมี source จาก event/command อยู่แล้ว

Properties ที่พบบ่อย

ด้านล่างคือ properties ที่พบบ่อย

รายการจริงขึ้นกับเวอร์ชันและการปรับแต่งของเซิร์ฟเวอร์

Property
Type
Description

source

number

Server ID ของผู้เล่น

identifier

string

Identifier ของผู้เล่น

name

string

ชื่อตัวละคร

group

string

กลุ่มสิทธิ์ (เช่น 'user', 'admin')

job

table

ข้อมูลงานปัจจุบัน

accounts

table

ข้อมูลบัญชีเงิน

inventory

table

รายการ Item

loadout

table

รายการอาวุธ (loadout)

coords

table

พิกัดล่าสุด

weight

number

น้ำหนักปัจจุบัน

maxWeight

number

น้ำหนักสูงสุดที่ถือได้

metadata

table

พื้นที่เก็บ metadata

variables

table

พื้นที่เก็บตัวแปรชั่วคราว

health

number

เลือด/HP

armor

number

เกราะ

หมวดหมู่ Methods (Method categories)

  • Accounts — จัดการบัญชีเงิน

  • Inventory — จัดการ Item และน้ำหนัก

  • Weapons — จัดการอาวุธ (loadout)

  • Job — จัดการอาชีพและยศ

  • Status — จัดการสถานะ (hunger/thirst ฯลฯ)

  • General — Methods ทั่วไปของผู้เล่น

Usage Examples

ตัวอย่างการใช้งาน

circle-check

Last updated