วิธีติดตั้ง ox_lib FiveM แบบถูกต้อง ใช้งานกับ Script ได้ทันที
การติดตั้ง ox_lib ใน FiveM ไม่ได้มีเพียงการนำ Folder ไปใส่ใน resources แล้วจบ เพราะ Script ที่ต้องใช้ Library จะต้องโหลด ox_lib ก่อน และ Resource ลูกต้อง Import Library ผ่าน fxmanifest.lua อย่างถูกต้อง
โครงสร้างพื้นฐานคือ
FXServer
↓
ox_lib
↓
Framework / Custom Scripts
ตัวอย่าง
ox_lib
↓
ox_target
ox_inventory
Qbox
ox_core
Custom Jobs
Custom Scripts
ถ้า ox_lib ไม่ทำงาน Resources ที่พึ่งมันอาจ Error ตามกันเป็นจำนวนมาก
① ox_lib คืออะไร
ox_lib คือ Standalone Development Library สำหรับ FiveM
มันให้ระบบสำเร็จรูป เช่น
Notification
Progress Bar
Progress Circle
Context Menu
Input Dialog
Text UI
Radial Menu
Skill Check
Callbacks
Points
Zones
Cache
Locale
Utilities
ให้ Scripts อื่นเรียกใช้
ดังนั้น
ox_lib
≠ Framework
คุณสามารถใช้กับ
ESX
QBCore
Qbox
ox_core
Standalone
ได้
② ก่อนติดตั้งต้องเตรียมอะไร
อย่างน้อยควรมี
FiveM FXServer
Server Data
server.cfg
สิทธิ์แก้ resources/
สิทธิ์ Restart Server
และควรใช้ FXServer รุ่นปัจจุบัน
Current ox_lib Manifest ยังมี Runtime Constraints สำหรับ
OneSync
Server Build
จึงไม่ควรติดตั้ง Library ปัจจุบันบน Artifact เก่ามากแล้วพยายามแก้ Source เพื่อหลบ Requirement
③ วิธีที่แนะนำคือใช้ Release
สำหรับ Server Owner ทั่วไปให้ใช้
ox_lib Release
ที่ Build พร้อมใช้งาน
ไม่ควรเลือก
Code → Download ZIP
จาก Source Repository เป็นวิธีแรก ถ้าไม่เข้าใจ Build Process
เพราะ UI ของ ox_lib ต้องมี Build Files ด้วย
④ Release ต่างจาก Source อย่างไร
Release
โดยทั่วไปมี
Lua Files
Resource Files
Locales
Web UI Build
fxmanifest.lua
init.lua
พร้อมใช้งาน
Source
มี Source Code สำหรับพัฒนา
ส่วน Web UI อาจต้อง
Install Dependencies
↓
Build
↓
สร้าง web/build
ก่อน
สำหรับการเปิด Server จริง Release จึงง่ายกว่า
⑤ Current ox_lib Version คืออะไร
ณ เวลาตรวจสอบข้อมูลสำหรับบทความนี้ Current Repository/Release Workflow อยู่ที่
ox_lib 3.39.0
แต่ Version สามารถเปลี่ยนได้ตลอด
ดังนั้นอย่ายึดเลขนี้เป็น Version ถาวร
หลักคือ
ใช้ Current Stable Release
และตรวจ Minimum Version ที่ Resource ลูกกำหนด
⑥ แตกไฟล์ ox_lib
หลัง Download Release แล้วแตกไฟล์
ควรได้ Folder
ox_lib/
├── fxmanifest.lua
├── init.lua
├── imports/
├── locales/
├── resource/
└── web/
โครงสร้างจริงอาจมี Files เพิ่มเติมตาม Version
สิ่งสำคัญคือ
fxmanifest.lua
ต้องอยู่ที่ Root ของ Resource
⑦ วาง ox_lib ไว้ตรงไหน
ตัวอย่าง
resources/
└── [ox]/
└── ox_lib/
หรือ
resources/
└── ox_lib/
ก็ได้
Bracket Folder เช่น
[ox]
เป็นเพียง Category สำหรับจัด Resources
ชื่อ Resource จริงยังเป็น
ox_lib
⑧ ระวัง Folder ซ้อน
ข้อผิดพลาดที่พบบ่อยคือ
resources/
└── ox_lib/
└── ox_lib/
├── fxmanifest.lua
└── init.lua
แบบนี้ผิด
ควรเป็น
resources/
└── ox_lib/
├── fxmanifest.lua
├── init.lua
└── ...
FiveM ต้องเห็น Manifest ที่ Root ของ Resource
⑨ อย่า Rename ox_lib
ควรใช้ชื่อ
ox_lib
ตามต้นฉบับ
อย่าเปลี่ยนเป็น
my_lib
ox_lib_new
oxlib
เพราะ Scripts จำนวนมาก Import ด้วย
@ox_lib/init.lua
ถ้าชื่อ Resource เปลี่ยน Path นี้ก็ใช้ไม่ได้
⑩ เพิ่ม ox_lib ใน server.cfg
เพิ่ม
ensure ox_lib
ก่อน Resources ที่ต้องใช้ Library
ตัวอย่าง
ensure ox_lib
ensure my_script
ไม่ควรกลับกันเป็น
ensure my_script
ensure ox_lib
ถ้า my_script ต้อง Import Library ตั้งแต่ Start
⑪ ถ้าใช้ [ox] สามารถ ensure ทั้ง Folder ได้ไหม
สามารถใช้ Resource Category เช่น
ensure [ox]
ได้
แต่ต้องระวัง Dependency Order
ถ้าใน [ox] มีหลาย Resources ที่พึ่งกันเอง การสั่งเป็นกลุ่มอาจอ่านลำดับ Debug ยากกว่า
สำหรับ Base Stack มักทำให้ชัด เช่น
ensure oxmysql
ensure ox_lib
ensure ox_core
ensure ox_target
ensure ox_inventory
ตาม Dependency จริง
⑫ Start ox_lib
หลังเพิ่ม Resource แล้วสามารถใช้
refresh
เพื่อให้ FXServer Rescan Resources
จากนั้น
ensure ox_lib
ถ้า Library มีอยู่และถูกต้องควร Start ได้
สำหรับ Server Boot ปกติให้เก็บ
ensure ox_lib
ไว้ใน server.cfg
⑬ refresh ต่างจาก ensure อย่างไร
refresh
ใช้ Rescan Resource Directories/Manifests
เหมาะหลังเพิ่ม Folder ใหม่ขณะ Server เปิดอยู่
ส่วน
ensure ox_lib
หมายถึง
ยังไม่ Start → Start
Start อยู่แล้ว → Restart
ดังนั้นถ้าเพิ่ง Copy Resource เข้ามาระหว่าง Server เปิด
refresh
ensure ox_lib
เป็น Workflow ที่เข้าใจง่าย
⑭ ตรวจ Server Console หลัง Start
อย่าดูเพียง
Started resource ox_lib
แล้วจบ
ให้ตรวจว่าหลังจากนั้นมี
SCRIPT ERROR
Unable to load UI
Missing dependency
Version error
หรือไม่
Resource Started ไม่ได้การันตีว่า UI และ Modules ทุกส่วนพร้อมใช้งาน
⑮ Current ox_lib ต้องการ OneSync
Current fxmanifest.lua ประกาศ Runtime Dependency
/onesync
ดังนั้น OneSync ต้องพร้อมตาม Requirement ของ Resource
ถ้า Server Config เก่ามากหรือปิด Features ที่ Resource ต้องใช้ ควรแก้ Server Configuration
ไม่ควรลบ Dependency จาก fxmanifest.lua เพื่อบังคับให้ Start
⑯ Current ox_lib มี Minimum Server Build
Manifest ปัจจุบันประกาศ Constraint
/server:7290
ใน Snapshot ที่ตรวจสอบ
หมายความว่า Server Build ต้องผ่าน Requirement นั้น
อย่างไรก็ตามเลข Minimum สามารถเปลี่ยนในอนาคต
วิธีที่เหมาะสมคือใช้ Current Recommended FXServer Artifact มากกว่าจำเลข Build ตายตัว
⑰ ตั้งค่า ox_lib ผ่าน Convars
ox_lib ใช้ Convars สำหรับ Configuration
ตัวอย่างจาก Current Documentation
setr ox:primaryColor blue
setr ox:primaryShade 8
setr ox:userLocales 1
setr ox:progressPropLimit 2
ไม่จำเป็นต้องแก้ Library Source เพียงเพื่อปรับค่าพื้นฐานเหล่านี้
⑱ ox:primaryColor คืออะไร
ใช้กำหนด Primary Color ของ UI Components
เช่น
setr ox:primaryColor blue
ช่วยให้ Interface หลายส่วนของ ox_lib ใช้ Theme กลาง
ไม่ควรแก้ CSS Bundle โดยตรงเพียงเพื่อเปลี่ยน Theme ธรรมดา
⑲ ox:primaryShade คืออะไร
ใช้กำหนด Shade ของ Primary Color
ตัวอย่าง
setr ox:primaryShade 8
ควรใช้ค่าตามระบบ Theme ที่ Documentation รองรับ
ถ้าต้อง Custom UI ลึกกว่านั้นจึงค่อยพิจารณา Build UI Source เอง
⑳ ox:userLocales คืออะไร
ตัวอย่าง
setr ox:userLocales 1
เปิดให้ Users เลือก Locale ผ่านระบบ Library ตามความสามารถปัจจุบัน
แต่ Resources ต้องมี Translation Files ของภาษานั้นด้วย
เปิด Convar นี้ไม่ได้ทำให้ Scripts ทั้ง Serverแปลภาษาไทยอัตโนมัติ
㉑ ox:progressPropLimit คืออะไร
ใช้กำหนดจำนวน Props สูงสุดที่ Progress Function สามารถ Spawn ตาม Configuration
เช่น
setr ox:progressPropLimit 2
เหมาะกับ Scripts ที่ใช้ Animation + Props ใน Progress Action
ควรใช้ค่าที่สมเหตุสมผล ไม่เพิ่มสูงโดยไม่มีเหตุผล
㉒ ตั้ง ACE Permissions ให้ ox_lib
Current Installation Documentation ระบุให้เพิ่ม ACE Permissions
add_ace resource.ox_lib command.add_ace allow
add_ace resource.ox_lib command.remove_ace allow
add_ace resource.ox_lib command.add_principal allow
add_ace resource.ox_lib command.remove_principal allow
ถ้าติดตั้ง Manual ควรตรวจส่วนนี้ด้วย
โดยเฉพาะ Features ที่ต้องจัดการ ACL/Principals
㉓ server.cfg ตัวอย่างพื้นฐาน
สามารถมีโครงสร้างประมาณ
setr ox:primaryColor blue
setr ox:primaryShade 8
setr ox:userLocales 1
setr ox:progressPropLimit 2
add_ace resource.ox_lib command.add_ace allow
add_ace resource.ox_lib command.remove_ace allow
add_ace resource.ox_lib command.add_principal allow
add_ace resource.ox_lib command.remove_principal allow
ensure ox_lib
จากนั้นค่อย Start Resources ที่พึ่ง Library
㉔ วิธีให้ Custom Script ใช้ ox_lib
สมมติมี Resource
my_script
เปิด
my_script/fxmanifest.lua
แล้วเพิ่ม
shared_script '@ox_lib/init.lua'
ก่อน Scripts ที่ต้องใช้ Library
㉕ ตัวอย่าง fxmanifest.lua
fx_version 'cerulean'
game 'gta5'
shared_script '@ox_lib/init.lua'
client_script 'client.lua'
server_script 'server.lua'
dependency 'ox_lib'
จากนั้น client.lua สามารถเรียก
lib.notify({
title = 'ทดสอบ',
description = 'ox_lib ทำงานแล้ว',
type = 'success'
})
ได้
㉖ shared_script สำคัญอย่างไร
บรรทัด
shared_script '@ox_lib/init.lua'
ทำให้ Resource Import Library Initializer
หลังจากนั้นจะมี Globals สำคัญ เช่น
lib
require
cache
ตาม Current Library Architecture
ถ้าไม่ Import แต่ Code เรียก
lib.notify(...)
ก็อาจพบ
attempt to index a nil value (global 'lib')
㉗ ถ้ามี Shared Scripts อื่นด้วย
ใช้
shared_scripts {
'@ox_lib/init.lua',
'shared/*.lua'
}
ได้
ควรให้ ox_lib Import ก่อน File ที่ต้องเรียก lib
เพื่อให้ Initialization Order อ่านง่ายและคาดการณ์ได้
㉘ ox_libs ใน fxmanifest คืออะไร
Current Documentation ยังรองรับการระบุ Modules ที่ต้อง Import
ตัวอย่าง
ox_libs {
'locale',
'math',
'table',
}
Library ยังสามารถ Load Modules แบบ Dynamic เมื่อเรียกใช้งาน
จึงไม่จำเป็นต้องโหลดทุก Module ด้วยตนเองในทุก Resource
㉙ dependency 'ox_lib' ควรใส่ไหม
ถ้า Resource ใช้งาน ox_lib เป็น Requirement จริง การประกาศ
dependency 'ox_lib'
ช่วยทำให้ Manifest บอก Dependency ชัดเจน
ควบคู่กับ
shared_script '@ox_lib/init.lua'
ทำให้ Resource อ่านแล้วเข้าใจง่ายว่าไม่สามารถทำงานโดยไม่มี Library
㉚ ทดสอบ ox_lib ด้วย Notification
สร้าง Client Script ง่าย ๆ
RegisterCommand('testoxlib', function()
lib.notify({
title = 'ox_lib',
description = 'ติดตั้งสำเร็จ',
type = 'success'
})
end)
เข้า Server แล้วใช้
/testoxlib
ถ้า Notification แสดง แปลว่าอย่างน้อย
Resource
Import
Client Library
UI
ทำงานได้
㉛ ทดสอบ lib.hasLoaded
Current Library มี
lib.hasLoaded()
เพื่อบอกสถานะการ Load
ถ้า UI Build ไม่มี ตัว Initializer ปัจจุบันจะตรวจและแสดง Error
นี่มีประโยชน์เพราะสามารถแยกได้ว่า Library โหลดสำเร็จจริงหรือเพียง Resource State เป็น Started
㉜ Unable to load UI คืออะไร
ถ้าเจอข้อความลักษณะ
Unable to load UI.
Build ox_lib or download the latest release.
สาเหตุสำคัญคือไฟล์
web/build/index.html
ไม่มี
Current Source ตรวจไฟล์นี้โดยตรง
กรณีนี้มักเกิดเพราะ Download Source Code ที่ยังไม่ได้ Build แทน Release
㉝ วิธีแก้ Unable to load UI ที่ถูกต้อง
มี 2 ทาง
วิธีง่าย
ใช้
Latest Release
ที่มี UI Build พร้อม
วิธี Developer
Build Source
cd ox_lib/web
bun i
bun run build
ถ้าไม่ได้แก้ UI เอง แนะนำใช้ Release
อย่า Download Web Files จากแหล่งสุ่มมาปะ Resource
㉞ อย่าแก้ Bundled CSS/JS โดยตรง
Documentation ระบุชัดว่า ถ้าต้องการแก้ UI ไม่ควร
de-bundle
un-minify
Release CSS/JS แล้วแก้
ควรแก้ Source แล้ว Build ใหม่
นี่ช่วยให้ Development Workflow ถูกต้องและ Update ได้ง่ายกว่า
㉟ ถ้าจะ Build UI ต้องมีอะไร
Current Guide ใช้
Node.js
Bun
และ Source Project
จากนั้น
cd ox_lib/web
bun i
bun run build
จึงสร้าง Web Build
สำหรับ Server Owner ที่ไม่ได้ทำ Front-end Development ไม่จำเป็นต้องทำขั้นตอนนี้
㊱ ox_lib must be started before this resource แก้อย่างไร
ถ้าเห็นข้อความประมาณ
ox_lib must be started before this resource
ตรวจ
① ox_lib Folder มีไหม
② ชื่อ Folder คือ ox_lib ไหม
③ ox_lib Start สำเร็จไหม
④ server.cfg เรียงถูกไหม
⑤ Resource ลูก Start ก่อน ox_lib หรือไม่
ตัวอย่างถูก
ensure ox_lib
ensure my_script
㊲ lib เป็น nil แก้อย่างไร
ถ้า Error
attempt to index a nil value (global 'lib')
ตรวจ fxmanifest.lua
ว่ามี
shared_script '@ox_lib/init.lua'
หรือไม่
จากนั้นตรวจว่า File ที่ใช้ lib ถูกโหลดหลัง Initializer
และตรวจว่า ox_lib Start อยู่
㊳ Couldn't find resource ox_lib แก้อย่างไร
ตรวจ Path
ควรเป็น
resources/[ox]/ox_lib/fxmanifest.lua
ไม่ใช่
resources/[ox]/ox_lib/ox_lib/fxmanifest.lua
จากนั้นใช้
refresh
แล้ว
ensure ox_lib
ใหม่
㊴ does not have a resource manifest แก้อย่างไร
ตรวจว่า Download Package ถูกต้อง
ใน Folder ox_lib ต้องมี
fxmanifest.lua
ถ้าไม่มี อาจ
แตก ZIP ผิด
Download Package ผิด
Folder ซ้อน
ไฟล์ไม่ครบ
อย่าสร้าง fxmanifest.lua เปล่า ๆ เองเพื่อให้ Error หาย
ควรติดตั้ง Package ที่ถูกต้อง
㊵ Script บอก ox_lib Version ต่ำเกินไป
Resource บางตัวกำหนด Minimum Version
ถ้าเห็น Error เช่น
ox_lib version x.x.x or higher required
ให้ Update ox_lib
ไม่ควรเข้าไปลบ Version Check ใน Script ลูก
เพราะ Script อาจใช้ Function ที่ Library เก่าไม่มีจริง
㊶ วิธี Update ox_lib
Workflow ที่ดีคือ
Backup
↓
ดู Current Version
↓
Download New Release
↓
Test Server
↓
หยุด Server
↓
Replace Resource
↓
Start
↓
ทดสอบ Scripts ที่พึ่ง ox_lib
ไม่ควร Update Production แบบสุ่มในช่วงผู้เล่นออนไลน์จำนวนมาก
㊷ อย่าเก็บ ox_lib หลาย Version
ไม่ควรมี
ox_lib
ox_lib_old
ox_lib_new
ox_lib_backup
อยู่ใน Resource Tree แล้วเผลอ Start หลายตัว
Backup ควรอยู่นอก Active Resources Directory หรือใช้ Version Control
ทำให้แน่ใจว่า Resource ที่ชื่อ
ox_lib
มี Source of Truth เพียงชุดเดียว
㊸ Restart ox_lib บน Live Server ควรระวังไหม
ควรระวัง
เพราะ Resources จำนวนมากอาจพึ่ง ox_lib
เช่น
ox_target
ox_inventory
Qbox resources
Custom Jobs
Custom UI
การ Restart Library กลางขณะ Server มีผู้เล่นอาจสร้าง Side Effects ให้ Resources ลูก
Production ควรทำใน Maintenance Window หากเป็น Update ใหญ่
㊹ ถ้าแก้ Custom Script ต้อง Restart ox_lib ไหม
โดยทั่วไปไม่จำเป็น
ถ้าแก้
my_script
ให้
restart my_script
ก่อน
อย่า Restart Dependency กลางโดยไม่มีเหตุผล
ช่วยลดผลกระทบต่อ Resources อื่น
㊺ ox_lib ใช้ Database ไหม
ox_lib ไม่ใช่ Database Resource
ดังนั้นการติดตั้ง Library เพียงอย่างเดียวไม่ต้องมี
oxmysql
เพื่อใช้ทุก Module
อย่าสับสนระหว่าง
ox_lib
→ Library
oxmysql
→ Database Interface
Resource ลูกอาจต้องใช้ทั้งสอง แต่เป็นคนละ Dependency
㊻ ox_lib ต้องใช้ Framework ไหม
ไม่ต้อง
สามารถสร้าง Standalone Resource เช่น
my_job
↓
ox_lib
โดยไม่ใช้
ESX
QBCore
Qbox
ได้
ตราบใดที่ Gameplay Logic ไม่ต้องใช้ Framework Player/Economy Data
㊼ ox_lib ใช้กับ ESX ได้ไหม
ได้
เช่น
ESX
+
ox_lib
Custom ESX Script สามารถใช้
lib.notify
lib.progressBar
lib.callback
lib.zones
ได้โดย Framework Logic ยังคงเป็น ESX
㊽ ox_lib ใช้กับ QBCore ได้ไหม
ได้
ตัวอย่าง
QBCore
→ Player / Money / Job
ox_lib
→ UI / Utilities / Callback
ทั้งสองไม่ได้แย่งหน้าที่กัน
Resource สามารถใช้ QBCore Framework Data พร้อมกับ OX UI/Utilities ได้
㊾ ox_lib ใช้กับ Qbox ได้ไหม
ได้ และพบมากใน Qbox ecosystem
Qbox และ Resources ที่เกี่ยวข้องใช้ ox_lib อย่างแพร่หลาย
ดังนั้น Qbox Server ใหม่มักมี
ensure ox_lib
ensure qbx_core
อยู่ใน Base Stack
㊿ ox_lib ใช้กับ ox_core ได้ไหม
ใช้ และเป็น Dependency สำคัญของ ox_core
Stack พื้นฐานอาจเป็น
oxmysql
↓
ox_lib
↓
ox_core
แล้วค่อยเพิ่ม Resources อื่น
51. ทดสอบ Callback หลังติดตั้ง
ฝั่ง Server
lib.callback.register('test:getData', function(source)
return {
success = true
}
end)
ฝั่ง Client
RegisterCommand('testcallback', function()
local data = lib.callback.await('test:getData', false)
print(data.success)
end)
ถ้า Client ได้ Response แสดงว่า Callback Layer ทำงาน
52. ทดสอบ Progress Bar
ตัวอย่าง
RegisterCommand('testprogress', function()
local finished = lib.progressBar({
duration = 3000,
label = 'กำลังทดสอบ...',
canCancel = true
})
print(finished)
end)
ถ้า UI แสดงและคืนค่าถูกต้อง แสดงว่า Client UI Components ทำงาน
53. ทดสอบ Text UI
RegisterCommand('showtext', function()
lib.showTextUI('[E] ทดสอบ ox_lib')
end)
RegisterCommand('hidetext', function()
lib.hideTextUI()
end)
ใช้เพียง Test
ใน Production ไม่ควรเรียก showTextUI ซ้ำทุก Frame
ควร Show/Hide เมื่อ State เปลี่ยน
54. ถ้า UI ทุกอย่างไม่ขึ้นให้ดู F8
เปิด
F8
แล้วหา Error เช่น
NUI error
module error
lib nil
failed to load
ถ้า Notification, Menu และ Progress พังพร้อมกัน แต่ Resource Started อยู่ ให้สงสัย
UI Build
Library Import
Client Error
ก่อน Framework
55. ถ้า Callback พังแต่ UI ใช้ได้
แปลว่า Client UI Layer อาจปกติ
ให้ตรวจ
Server Script Loaded?
Callback Name ตรง?
Server Console มี Error?
Resource Side ถูก?
อย่า Reinstall Library ทั้งตัวทันที
แยก Feature ที่เสียก่อน
56. Clear Cache ช่วย ox_lib Error ไหม
ไม่ใช่วิธีแรกสำหรับ Error เช่น
Missing ox_lib
lib is nil
Version too old
Unable to load UI
ปัญหาเหล่านี้มี Root Cause ชัดที่
Files
Import
Version
Build
Start Order
แก้ตรงจุดดีกว่า
57. Production Server ควร Pin Version ไหม
สำหรับ Server ใหญ่ควรบันทึก Version ที่ใช้งาน
อย่างน้อย
ox_lib version
วันที่ Update
Scripts สำคัญที่พึ่งมัน
เพราะ Library กลางอาจมี Resources พึ่งหลายสิบตัว
การ Update จึงควรควบคุมมากกว่า Resource เล็ก ๆ ตัวเดียว
58. ใช้ Test Server ก่อน Update
Workflow ที่ดี
Production ox_lib
↓
Backup
↓
Clone Test
↓
Update ox_lib
↓
Test ox_target
↓
Test ox_inventory
↓
Test Framework
↓
Test Custom Scripts
↓
Production
ช่วยลดโอกาส Update Library แล้ว Server RP หลายระบบพังพร้อมกัน
59. Checklist ติดตั้ง ox_lib
Files
ใช้ Current Release
Folder ชื่อ
ox_libfxmanifest.luaอยู่ Rootweb/build/index.htmlมีไม่มี Folder ซ้อน
server.cfg
ensure ox_lib
อยู่ก่อน Resources ที่พึ่ง Library
Config
ตั้ง Convars ที่ต้องการ
setr ox:primaryColor blue
setr ox:primaryShade 8
และค่าอื่นตาม Requirement
Permissions
ตั้ง ACE ตาม Current Documentation
Custom Resource
มี
shared_script '@ox_lib/init.lua'
ถ้าต้องใช้ Library
Testing
Notification ทำงาน
Progress ทำงาน
Callback ทำงาน
F8 ไม่มี Critical Error
Console ไม่มี Critical Error
60. วิธีติดตั้ง ox_lib แบบสั้นที่สุด
ถ้าต้องการเพียงขั้นตอนสำคัญ
① ใช้ FXServer ปัจจุบัน
② Download Latest ox_lib Release
③ แตกไฟล์
④ ตรวจ Folder ชื่อ ox_lib
⑤ ตรวจ fxmanifest.lua
⑥ ตรวจ web/build/index.html
⑦ วางใน resources/[ox]/ox_lib
⑧ เพิ่ม ensure ox_lib ใน server.cfg
⑨ ตั้ง Convars ตามต้องการ
⑩ เพิ่ม ACE Permissions
⑪ Restart Server หรือ refresh
⑫ ensure ox_lib
⑬ ตรวจ Console
⑭ ใน Script ลูกเพิ่ม
@ox_lib/init.lua
⑮ ประกาศ dependency ox_lib หากเป็น Requirement
⑯ Restart Script ลูก
⑰ ทดสอบ lib.notify
⑱ ทดสอบ Callback/UI ที่ Script ใช้
⑲ ตรวจ F8
⑳ Backup Base ที่ทำงานแล้ว
ตัวอย่างโครงสร้างที่ถูกต้อง
resources/
│
├── [ox]/
│ ├── ox_lib/
│ │ ├── fxmanifest.lua
│ │ ├── init.lua
│ │ ├── imports/
│ │ ├── locales/
│ │ ├── resource/
│ │ └── web/
│ │
│ ├── ox_target/
│ └── ox_inventory/
│
└── [custom]/
└── my_script/
├── fxmanifest.lua
├── client.lua
└── server.lua
จากนั้น
ensure ox_lib
ensure ox_target
ensure ox_inventory
ensure my_script
ตาม Dependencies ของ Stack จริง
ตัวอย่าง Custom Script พร้อมใช้งาน
fxmanifest.lua
fx_version 'cerulean'
game 'gta5'
shared_script '@ox_lib/init.lua'
client_script 'client.lua'
dependency 'ox_lib'
client.lua
RegisterCommand('oxcheck', function()
lib.notify({
title = 'ox_lib',
description = 'Library พร้อมใช้งาน',
type = 'success'
})
end)
เข้า Server แล้วใช้
/oxcheck
ถ้ามี Notification แสดง Library Integration ขั้นพื้นฐานทำงานแล้ว
สรุปวิธีติดตั้ง ox_lib FiveM
วิธีติดตั้ง ox_lib ที่ถูกต้องคือใช้ Current Release ที่ Build พร้อมแล้ว นำ Folder ox_lib ไปไว้ใน resources, Start Library ก่อน Resources ลูก และ Import Library ใน Script ผ่าน
shared_script '@ox_lib/init.lua'
โครงสร้างหลักคือ
ox_lib
↓
Framework / Library-dependent resources
↓
Custom Scripts
Current Documentation ใช้ Convars สำหรับ Configuration เช่น
setr ox:primaryColor blue
setr ox:primaryShade 8
setr ox:userLocales 1
setr ox:progressPropLimit 2
พร้อม ACE Permissions สำหรับ Resource ตามที่ Documentation กำหนด
อีกจุดสำคัญมากคือ Current ox_lib มี Web UI อยู่ที่
web/build/index.html
ถ้าเจอ
Unable to load UI
มักต้องตรวจว่าดาวน์โหลด Current Release หรือ Build Source สำเร็จแล้ว ไม่ควรพยายามแก้ NUI Code ก่อนตรวจไฟล์นี้
Current Manifest ยังมี Runtime Requirements สำหรับ OneSync และ Server Build ดังนั้นถ้าใช้ FXServer รุ่นเก่ามาก แนวทางที่ถูกคือ Update Server Artifact ไม่ใช่ลบ Dependency Constraints เพื่อบังคับ Library ให้ทำงาน
สำหรับ comsiam วิธีที่ปลอดภัยที่สุดคือทดสอบ ox_lib แยกก่อนด้วย Notification หรือ Progress ง่าย ๆ จากนั้นจึง Start ox_target, ox_inventory, Framework และ Custom Scripts ที่พึ่ง Library ทำให้สามารถหาต้นเหตุได้ทันทีหาก Resource ชั้นบนมีปัญหา
และสำหรับ Production comsiam แนะนำอย่า Restart หรือ Update ox_lib แบบสุ่มในช่วงที่ Server มีผู้เล่น เพราะมันอาจเป็น Dependency กลางของ Resources จำนวนมาก ควร Backup, ทดสอบ Version ใหม่บน Test Server และตรวจ Resources สำคัญทั้งหมดก่อนนำขึ้น Production
Comments
Post a Comment