Callbacks & Notifications

ฟังก์ชันฝั่ง Client สำหรับเรียก callback ไปยัง Server และแสดงข้อความแจ้งเตือน (Notification/Help) ภายในเกม

Callbacks & Notifications (Client)

หน้านี้รวบรวมฟังก์ชันฝั่ง Client-side สำหรับ

  • เรียก callback ไปยัง Server และรับผลลัพธ์กลับมา

  • ลงทะเบียน callback ฝั่ง Client ให้ Server เรียกใช้งาน

  • แสดง Notification / Help Notification ให้ผู้เล่น

ก่อนเริ่ม (แนะนำ)

  • ตั้งค่าการเรียกใช้ Framework ให้ถูกต้องตาม Framework Usage

  • อย่าใช้ข้อมูลฝั่ง Client เป็น "แหล่งข้อมูลจริง" สำหรับเงิน/Item/สิทธิ์

circle-exclamation

ESX.TriggerServerCallback

เรียก callback ที่ลงทะเบียนไว้ฝั่ง Server แล้วรับผลลัพธ์กลับมา

รองรับ 2 รูปแบบ:

  • Callback style: ส่งฟังก์ชันรับผลลัพธ์เข้ามา

  • Promise style: ส่ง nil แทน callback แล้วรับค่ากลับโดยตรง (ต้องอยู่ใน thread/coroutine)

รูปแบบการใช้งาน (Syntax)

พารามิเตอร์ (Parameters)

Name
Type
Description

name

string

ชื่อ callback ที่ฝั่ง Server ลงทะเบียนไว้

cb

function

Callback function(...) หรือ nil เพื่อใช้ promise style

...

any

พารามิเตอร์เพิ่มเติมที่จะส่งไปให้ฝั่ง Server

ค่าที่ส่งคืน (Returns)

  • Callback style: ไม่มีการคืนค่าโดยตรง (ผลลัพธ์จะเข้าที่ cb)

  • Promise style: คืนค่าที่ Server ส่งกลับมา (ชนิดข้อมูลขึ้นกับ callback)

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

Callback style

Promise style

circle-info

ถ้าใช้ promise style (ส่ง nil เป็น callback) ต้องเรียกภายใน CreateThread หรือ coroutine เท่านั้น


ESX.RegisterClientCallback

ลงทะเบียน callback ฝั่ง Client เพื่อให้ Server เรียกใช้งานได้

เหมาะกับงานที่ Server ต้องการ “ถามข้อมูลจาก Client” เช่น พิกัดปัจจุบัน, สถานะ UI, หรือข้อมูลที่มีเฉพาะในเครื่องผู้เล่น

รูปแบบการใช้งาน (Syntax)

พารามิเตอร์ (Parameters)

Name
Type
Description

name

string

ชื่อ callback ที่ต้องการลงทะเบียน

cb

function

Callback function(respond, ...) โดย respond(...) ใช้สำหรับส่งค่ากลับไปยังฝั่ง Server

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

circle-info

Client callback จะถูกล้างให้อัตโนมัติเมื่อ resource ที่ลงทะเบียนหยุดทำงาน

circle-exclamation

ESX.ShowNotification

แสดง notification ให้ผู้เล่นผ่าน nc_notify export

รองรับการส่งข้อความแบบ string หรือส่งเป็น options table

รูปแบบการใช้งาน (Syntax)

พารามิเตอร์ (Parameters)

Name
Type
Description

options

string|table

ข้อความ notification หรือ table สำหรับกำหนดรูปแบบ/ระยะเวลา

Options table

Field
Type
Description

title

string

ข้อความหลักที่แสดง

type

string

ประเภท (เช่น 'success', 'error', 'warning', 'info')

description

string

(ไม่บังคับ) รายละเอียดเพิ่มเติม

duration

number

(ไม่บังคับ) ระยะเวลา (ms)

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

circle-exclamation

ESX.ShowHelpNotification

แสดง Help Notification สไตล์ GTA (กล่องดำมุมซ้ายบน)

รูปแบบการใช้งาน (Syntax)

พารามิเตอร์ (Parameters)

Name
Type
Description

msg

string

ข้อความที่ต้องการแสดง

thisFrame

boolean

true = แสดงเฉพาะเฟรมนี้ (ต้องเรียกทุก tick), false = แสดงแบบค้าง

beep

boolean

เล่นเสียง beep หรือไม่ (ค่าเริ่มต้น: true)

duration

number

(ไม่บังคับ) ระยะเวลา (ms) (ค่าเริ่มต้น: -1 = ค้าง)

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

circle-info

ถ้าใช้ thisFrame = true ต้องเรียกทุกเฟรม ไม่เช่นนั้นข้อความจะหายทันที


ESX.ShowFloatingHelpNotification

แสดง Help Notification แบบ “ลอย” ที่พิกัด 3D ในโลกเกม

รูปแบบการใช้งาน (Syntax)

พารามิเตอร์ (Parameters)

Name
Type
Description

msg

string

ข้อความที่ต้องการแสดง

coords

vector3

พิกัดโลกสำหรับแสดงข้อความ

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

circle-exclamation

ESX.ShowAdvancedNotification

แสดง Advanced Notification สไตล์ GTA (มีไอคอน/ผู้ส่ง/หัวข้อ)

รูปแบบการใช้งาน (Syntax)

พารามิเตอร์ (Parameters)

Name
Type
Description

sender

string

ชื่อผู้ส่งที่แสดงใน notification

subject

string

หัวข้อ (subject)

msg

string

เนื้อหาข้อความ

textureDict

string

Texture dict สำหรับไอคอน (เช่น CHAR_BANKING)

iconType

number

ชนิดไอคอน (index)

flash

boolean

(ไม่บังคับ) ให้กระพริบหรือไม่

saveToBrief

boolean

(ไม่บังคับ) บันทึกลง brief (ค่าเริ่มต้น: true)

hudColorIndex

number

(ไม่บังคับ) สีพื้นหลัง (HUD color index)

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


ESX.GetVehicleType

ดึง “ประเภทยานพาหนะ” จากโมเดลที่ระบุ (ชื่อหรือ hash)

ฟังก์ชันนี้ช่วยแก้กรณีที่ type ของรถ vanilla บางรุ่นไม่ตรงตามที่คาดหวัง

รูปแบบการใช้งาน (Syntax)

พารามิเตอร์ (Parameters)

Name
Type
Description

model

string|number

ชื่อโมเดล หรือ model hash

ค่าที่ส่งคืน (Returns)

Type
Description

string

ประเภทยานพาหนะ: 'automobile', 'bike', 'boat', 'heli', 'plane', 'submarine', 'trailer', 'train' หรือ nil

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

Last updated