ox_lib Error แก้อย่างไร รวมวิธีแก้ ox_lib ใช้งานไม่ได้ใน FiveM
ปัญหา ox_lib Error ใน FiveM มักไม่ได้เกิดจาก Library เสียเพียงอย่างเดียว แต่เกิดจาก ติดตั้งผิด Package, Folder ซ้อน, Start Order ผิด, Version ไม่ตรงกับ Script, UI ไม่ได้ Build หรือ Resource ลูก Import ox_lib ไม่ถูกต้อง
ถ้า Server ขึ้น Error เช่น
ox_lib must be started before this resource
attempt to index a nil value (global 'lib')
Unable to load UI
Error importing module
หรือ
ox_lib version ... or higher is required
อย่าเริ่มจากการ Clear Cache หรือ Reinstall FiveM ทั้ง Server
ควรไล่ตรวจตามลำดับ
① ox_lib มีจริงไหม
↓
② Folder ถูกไหม
↓
③ Package เป็น Release หรือ Source
↓
④ ox_lib Start สำเร็จไหม
↓
⑤ Start Order ถูกไหม
↓
⑥ Resource ลูก Import ถูกไหม
↓
⑦ Version ตรงไหม
↓
⑧ FXServer / OneSync ผ่าน Requirement ไหม
↓
⑨ UI Build ครบไหม
↓
⑩ ค่อยตรวจ Script Code
วิธีนี้ช่วยหา Root Cause ได้เร็วกว่าการสุ่มแก้หลายอย่างพร้อมกัน
① ox_lib Error คืออะไร
ox_lib เป็น Library กลางที่ Resources จำนวนมากเรียกใช้
ตัวอย่าง
ox_target
ox_inventory
Qbox
ox_core
Custom Jobs
Paid Scripts
ดังนั้นถ้า Library มีปัญหา อาจเห็น Errors จาก Resources ลูกหลายตัวพร้อมกัน
ตัวอย่าง
ox_lib Error
↓
ox_inventory Error
↓
ox_target Error
↓
Job Script Error
↓
Phone Integration Error
อย่าพยายามแก้ Resource ชั้นบนทั้งหมดก่อน
ต้องแก้ ox_lib ให้สมบูรณ์ก่อน
② Error แรกสำคัญที่สุด
สมมติ Console มี
ox_lib error
ox_inventory error
shop error
police error
garage error
อย่าเริ่มจาก Garage
ควรย้อนขึ้นไปหา Error แรกสุด
ถ้า Root Cause คือ
ox_lib ไม่ Start
การแก้ Library ตัวเดียวอาจทำให้ Error ด้านล่างหายตามหลายรายการ
นี่เป็นหลักสำคัญในการ Debug Dependency Chain
③ ตรวจว่า ox_lib มีอยู่จริงหรือไม่
เปิด Folder
resources/
แล้วหา
ox_lib
ตัวอย่างที่ถูก
resources/
└── [ox]/
└── ox_lib/
├── fxmanifest.lua
├── init.lua
└── ...
ถ้าไม่มี Resource นี้ Script ที่ต้องใช้ ox_lib จะทำงานไม่ได้
④ Couldn't find resource ox_lib
ถ้า Console ขึ้น
Couldn't find resource ox_lib
หมายความว่า FXServer หา Resource ชื่อนี้ไม่พบ
ตรวจ
Folder มีจริงไหม
ชื่อ Folder ถูกไหม
อยู่ใต้ resources หรือไม่
Folder ซ้อนหรือไม่
Manifest อยู่ Root หรือไม่
จากนั้นใช้
refresh
แล้ว
ensure ox_lib
ใหม่
⑤ Folder ซ้อนเป็นปัญหาที่พบบ่อยมาก
ตัวอย่างผิด
resources/
└── [ox]/
└── ox_lib/
└── ox_lib/
├── fxmanifest.lua
└── init.lua
FiveM จะเห็น Folder ชั้นแรกเป็น Resource แต่ไม่พบ Manifest ที่ Root
โครงสร้างที่ถูกต้องคือ
resources/
└── [ox]/
└── ox_lib/
├── fxmanifest.lua
├── init.lua
├── imports/
├── resource/
└── web/
⑥ does not have a resource manifest
หากขึ้นประมาณ
does not have a resource manifest
ให้เข้า
resources/[ox]/ox_lib/
แล้วตรวจว่ามี
fxmanifest.lua
ที่ Root หรือไม่
ถ้าไม่มี มักเกิดจาก
Folder ซ้อน
Extract ZIP ผิด
Download Package ผิด
ไฟล์หาย
ไม่ควรสร้าง fxmanifest.lua เปล่าขึ้นมาเองเพียงเพื่อให้ Error หาย
⑦ อย่า Rename ox_lib
Resource ควรชื่อ
ox_lib
ไม่ใช่
oxlib
ox_lib_new
ox_lib-main
my_ox_lib
เพราะ Scripts จำนวนมากเรียก
@ox_lib/init.lua
โดยตรง
ถ้าชื่อ Resource เปลี่ยน Import Path จะไม่ตรง
⑧ GitHub ZIP อาจได้ชื่อ ox_lib-main
ถ้าดาวน์โหลด Source Repository แบบ ZIP อาจแตกออกมาเป็น
ox_lib-main
การ Rename เป็น
ox_lib
อย่างเดียวก็ยังไม่ได้รับประกันว่าจะพร้อมใช้ เพราะ Source อาจต้อง Build UI
สำหรับ Server Owner ทั่วไปจึงควรใช้ Release Build มากกว่า Source ZIP
⑨ ox_lib must be started before this resource
นี่เป็น Error ที่ตรงมาก
Current ox_lib/init.lua ตรวจ State ของ Resource
ถ้า
GetResourceState('ox_lib')
ไม่ใช่
started
จะ Error ว่า
ox_lib must be started before this resource
ดังนั้นให้ตรวจ Start Order ก่อน
⑩ Start Order ที่ถูกต้อง
ถ้ามี
ox_lib
และ
my_script
ควรเป็น
ensure ox_lib
ensure my_script
ไม่ใช่
ensure my_script
ensure ox_lib
เพราะ Script ลูก Import Library ตั้งแต่เริ่ม Resource
⑪ ถ้ามี oxmysql ด้วยควรเรียงอย่างไร
สำหรับ Stack ที่ใช้ Database
ตัวอย่าง
ensure oxmysql
ensure ox_lib
ensure my_framework
ensure ox_target
ensure ox_inventory
ลำดับจริงต้องยึด Dependency ของ Framework/Resources ที่ใช้
แต่หลักคือ Dependency ต้องพร้อมก่อน Resource ที่เรียกมัน
⑫ ensure [ox] แล้วทำไมยัง Error
บาง Server ใช้
ensure [ox]
เพื่อ Start Resources ทั้ง Category
วิธีนี้สะดวก แต่เมื่อมี Dependencies หลายชั้น Debug ยากขึ้น
สำหรับ Resources สำคัญแนะนำให้เขียนชัด เช่น
ensure oxmysql
ensure ox_lib
ensure qbx_core
ensure ox_target
ensure ox_inventory
แล้วค่อย
ensure [custom]
สำหรับ Scripts ชั้นบน
⑬ ox_lib Started แต่ Script ยัง Error
ถ้า Console บอก
Started resource ox_lib
แต่ Resource ลูกยัง Error
อย่ารีบสรุปว่า Library ปกติทั้งหมด
ต้องตรวจต่อว่า
UI โหลดไหม
Modules โหลดไหม
Version ถูกไหม
Resource ลูก Import ถูกไหม
Files ครบไหม
Resource State เป็น started เป็นเพียงหนึ่งเงื่อนไขเท่านั้น
⑭ lib is nil คืออะไร
Error ตัวอย่าง
attempt to index a nil value (global 'lib')
มักหมายความว่า Resource ที่เรียก
lib.notify(...)
ไม่ได้ Import ox_lib อย่างถูกต้อง
ให้เปิด
fxmanifest.lua
ของ Script นั้น
⑮ วิธีแก้ lib is nil
ตรวจว่ามี
shared_script '@ox_lib/init.lua'
หรือ
shared_scripts {
'@ox_lib/init.lua',
}
จากนั้นตรวจว่า ox_lib Start ก่อน Resource นั้น
แล้ว Restart
restart my_script
ไม่จำเป็นต้อง Restart Server ทั้งเครื่องทุกครั้ง
⑯ ตัวอย่าง 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 = 'Test',
description = 'ox_lib ทำงานแล้ว',
type = 'success'
})
ได้
⑰ Import ต้องอยู่ก่อน Script ที่ใช้ lib
ตัวอย่างที่อ่านง่าย
shared_script '@ox_lib/init.lua'
shared_script 'config.lua'
client_script 'client.lua'
ถ้า File Shared ของคุณใช้ lib ด้วย ก็ควรให้ Initializer ถูกโหลดก่อน
เป้าหมายคือให้ Resource Lifecycle ชัดเจน
⑱ Cannot load ox_lib more than once
Current Initializer ตรวจการโหลดซ้ำด้วย
หาก Resource Import ox_lib ซ้ำ อาจพบข้อความประมาณ
Cannot load ox_lib more than once
พร้อมคำแนะนำให้ลบ Duplicate Entries ออกจาก Manifest ของ Resource นั้น
⑲ ตัวอย่าง Import ซ้ำที่ผิด
ไม่ควรมี
shared_script '@ox_lib/init.lua'
shared_scripts {
'@ox_lib/init.lua',
'config.lua'
}
เพราะ Initializer ถูกเรียกสองครั้ง
แก้เป็น
shared_scripts {
'@ox_lib/init.lua',
'config.lua'
}
เพียงครั้งเดียว
⑳ อย่าใส่ @ox_lib/init.lua ใน fxmanifest ของ ox_lib เอง
ox_lib มี Manifest และ Initialization ของตัวเอง
ไม่ควรเปิด
ox_lib/fxmanifest.lua
แล้วเพิ่ม
shared_script '@ox_lib/init.lua'
เข้าไปเอง
Initializer สำหรับ Resources ลูก ไม่ใช่สิ่งที่ต้องเพิ่มซ้ำในตัว Library
㉑ Unable to load UI คืออะไร
Current ox_lib ตรวจไฟล์
web/build/index.html
ถ้าไม่พบ จะ Error ประมาณ
Unable to load UI.
Build ox_lib or download the latest release.
นี่เป็น Error ที่ชี้ Root Cause ค่อนข้างตรง
㉒ ทำไม web/build/index.html ถึงหาย
สาเหตุที่พบบ่อยที่สุดคือ Download
Source Code ZIP
แทน
Release Build
Source Repository มี Source สำหรับ Development แต่ Production UI อาจต้องผ่าน Build Process ก่อน
จึงไม่ควรเอา Source ZIP ทุก Project ไปวางใน resources โดยอัตโนมัติ
㉓ วิธีแก้ Unable to load UI ที่ง่ายที่สุด
ใช้ Current Official Release
จากนั้นตรวจ
ox_lib/
└── web/
└── build/
└── index.html
ว่ามีจริง
ถ้าไม่มี ให้สงสัย Package ที่ดาวน์โหลดมาก่อน
ไม่ใช่ Firewall หรือ FiveM Cache เป็นอันดับแรก
㉔ ถ้าต้องการ Build ox_lib เอง
เหมาะกับ Developer ที่แก้ Source/UI เอง
ต้องใช้ Development Workflow ของ Project เพื่อสร้าง
web/build/
ให้สมบูรณ์
ถ้าเพียงต้องการเปิด FiveM Server ไม่จำเป็นต้อง Build เอง
ใช้ Official Release จะง่ายกว่า
㉕ Error UI ไม่ควรแก้ด้วย Clear Cache
ถ้า Error บอกชัดว่า
web/build/index.html
ไม่มี
การล้าง
server cache
client cache
ไม่ได้สร้างไฟล์ที่หายขึ้นมา
ต้องแก้ Package/Build
นี่เป็นตัวอย่างว่าทำไมควรอ่าน Error ก่อนใช้วิธีแก้ยอดนิยม
㉖ ox_lib Version ต่ำเกินไป
Resource บางตัวตรวจ Version ด้วย
ตัวอย่าง Current ox_inventory Source ที่ตรวจสอบในขณะนี้ต้องการขั้นต่ำ
ox_lib 3.36.4
หรือสูงกว่าใน Source Snapshot ปัจจุบัน
ถ้า Library ต่ำกว่านั้น Inventory สามารถปฏิเสธการทำงานได้
㉗ Current ox_lib Version
Current Manifest ที่ตรวจสอบสำหรับบทความนี้ระบุ
3.39.0
แต่อย่ายึดเลขนี้เป็นค่าถาวร
เพราะ Releases สามารถเปลี่ยนได้
วิธีที่ถูกคือดู
Resource ที่ต้องใช้ ox_lib
↓
Minimum Version
↓
ox_lib Version ที่ติดตั้ง
ให้ตรงกัน
㉘ วิธีดู Version ของ ox_lib
เปิด
ox_lib/fxmanifest.lua
แล้วหา
version '3.39.0'
ตัวเลขจริงขึ้นกับ Release ที่ติดตั้ง
อย่าดูจากชื่อ ZIP อย่างเดียว
Manifest เป็นจุดตรวจที่ดีกว่า
㉙ อย่าลบ Version Check
ถ้า Resource ขึ้น
ox_lib version x.x.x or higher is required
ไม่ควรเข้า Script แล้วลบ Check
เพราะ Resource อาจเรียก Function หรือ API ที่ Library เก่าไม่มีจริง
แนวทางคือ
Backup
↓
Update ox_lib
↓
Test
㉚ ระวัง Update ox_lib ตัวเดียวใน Stack เก่ามาก
ในทางกลับกัน การ Update Library ไปใหม่สุดบน Server เก่าหลายปีโดยไม่ Test ก็มีความเสี่ยง
ควรตรวจ
Framework
ox_inventory
ox_target
Custom Scripts
Paid Scripts
ที่พึ่ง Library
แล้วทดสอบ Version ใหม่บน Test Server ก่อน Production
㉛ Error importing module คืออะไร
Current ox_lib โหลด Modules จาก Path เช่น
imports/<module>/
หาก Module Source โหลดไม่ได้หรือมี Syntax/Runtime Problem อาจเห็น
Error importing module (...)
ตัวอย่าง Module อาจเป็น
callback
zones
locale
math
table
ตาม Function ที่ Resource เรียก
㉜ Error importing module อาจเกิดจากอะไร
สาเหตุสำคัญ ได้แก่
ไฟล์ ox_lib ไม่ครบ
ไฟล์คนละ Version ปะปนกัน
Source ถูกแก้
Update ทับไม่สมบูรณ์
ใช้ Fork ที่ไม่ตรง
Syntax/Runtime incompatibility
หาก Official Release ใหม่สะอาดทำงานได้ แต่ชุดเดิมไม่ได้ ให้สงสัย Mixed Files
㉝ อย่า Update แบบทับไฟล์ครึ่งหนึ่ง
ตัวอย่างอันตราย
ox_lib 3.20
↓
Copy เฉพาะบาง Folder จาก 3.39
อาจกลายเป็น
init.lua Version A
imports Version B
resource Version C
web Version D
แล้วเกิด Error ที่วิเคราะห์ยากมาก
ควร Backup แล้ว Replace Resource เป็น Release เดียวกันทั้งชุด
㉞ No such export ใน ox_lib
ถ้า Scriptขึ้น
No such export ...
in resource ox_lib
ให้ตรวจก่อนว่า
Script ต้องการ ox_lib Version ไหน
ox_lib ที่ติดตั้ง Version ไหน
Files ถูกชุดเดียวกันไหม
Script เรียก API ปัจจุบันหรือ API เก่าหรือไม่
Error ลักษณะนี้มักเกี่ยวกับ API/Version มากกว่าการ Clear Cache
㉟ มี ox_lib สองชุดหรือไม่
ค้นหาใน Resource Tree
อย่าให้มี Active Copies เช่น
[ox]/ox_lib
[standalone]/ox_lib
[backup]/ox_lib
โดยเฉพาะถ้า Backup Folder ยังอยู่ใต้ resources
ควรเก็บ Backup นอก Active Resource Tree
หรือใช้ Git/Version Control แทน
㊱ ox_lib_old อยู่ใน resources มีปัญหาไหม
ถ้าไม่ Start อาจไม่ชนโดยตรง แต่สร้างความสับสนมาก
และ Category
ensure [ox]
อาจ Start Resource ที่คุณไม่ได้ตั้งใจหาก Folder Structure ไม่ดี
แนวทางที่สะอาดคือ
active resources
≠
backup storage
แยกกัน
㊲ OneSync Error
Current ox_lib Manifest ประกาศ Dependency
/onesync
ถ้า Server ไม่ผ่าน Requirement นี้ Resource อาจไม่ Start
ให้ตรวจ FXServer/txAdmin Configuration
ไม่ควรลบ
/onesync
ออกจาก Manifest เพื่อหลบ Error
เพราะ Library/Resources ที่พึ่งมันอาจต้องใช้ Behavior ดังกล่าวจริง
㊳ Server Build ต่ำเกินไป
Current ox_lib Manifest ที่ตรวจสอบมี Runtime Constraint
/server:7290
ดังนั้น Artifact เก่ากว่าค่าที่ Resource ต้องการอาจเปิดไม่ได้
แก้ด้วย
Update FXServer Artifact
ไม่ใช่ลบ /server: Constraint
ตัวเลข Requirement สามารถเปลี่ยนตาม Release ในอนาคต
㊴ Lua 5.4 Error
Current ox_lib/init.lua ตรวจ
Lua 5.4
หาก Environment ไม่เป็น Lua 5.4 จะ Error
บน FiveM รุ่นปัจจุบัน Lua 5.4 เป็น Runtime มาตรฐานอยู่แล้ว และ lua54 'yes' ไม่จำเป็นสำหรับ Resources รุ่นใหม่เหมือนในอดีต
ดังนั้นหากเจอ Lua Version Error บน Server ปัจจุบัน ให้สงสัย
FXServer เก่า
Resource เก่า
Manifest/Runtime ผิดยุค
ก่อน
㊵ ไม่ควรแก้ lua54 แบบสุ่ม
Tutorial รุ่นเก่าจำนวนมากแนะนำ
lua54 'yes'
แต่ใน FiveM ปัจจุบัน Lua 5.4 เป็นค่าใช้งานมาตรฐานและ directive นี้ถูกลดความจำเป็นลงแล้ว
ถ้าเจอ Error ควร Update Artifact และ Resource Version ให้สอดคล้องกัน
ไม่ใช่เพิ่ม/ลบ Directive แบบสุ่มจน Manifest ผิดจาก Official Source
㊶ Notification ไม่ขึ้นแต่ไม่มี Error
ถ้า
lib.notify(...)
ไม่แสดง
แต่ไม่มี Error ชัดเจน ให้ตรวจ
ox_lib UI พร้อมไหม
Function เรียกฝั่ง Client หรือไม่
Resource Client Script โหลดหรือไม่
F8 มี NUI Error หรือไม่
เรียกเร็วเกินช่วง UI Initialization หรือไม่
เริ่มจาก Client F8
เพราะ Notification เป็น Client UI
㊷ Progress Bar ไม่ขึ้น
ตรวจคล้าย Notification
lib ถูก Import?
Client Script ทำงาน?
UI Build มี?
F8 Error?
Arguments ถูก API ปัจจุบัน?
ถ้า Notification และ Progress ไม่ขึ้นพร้อมกัน ให้สงสัย Library/UI Layer
ถ้ามีเพียง Progress Script เดียวพัง ให้ดู Code ของ Script นั้นมากกว่า Reinstall Library
㊸ Context Menu ไม่เปิด
ตรวจว่า Menu ถูก
register
ก่อน
show
และ ID ตรงกันหรือไม่
Error UI บางอย่างเป็น Logic ของ Resource เอง ไม่ใช่ Library Install
ดังนั้นต้องแยก
ox_lib เสีย
ออกจาก
ใช้ ox_lib API ผิด
ให้ได้
㊹ Callback ไม่ทำงาน
ถ้า UI ใช้ได้แต่
lib.callback
ไม่ตอบ
ให้ตรวจ
Callback Name ตรงกันไหม
Server File โหลดไหม
Register ฝั่งถูกไหม
Client/Server Direction ถูกไหม
Server Console Error ไหม
Arguments ถูกไหม
ไม่จำเป็นต้อง Reinstall ox_lib เพราะ UI ใช้งานได้แสดงว่า Library ส่วนใหญ่โหลดอยู่แล้ว
㊺ Callback Name ต้องตรงกัน
ตัวอย่าง Server
lib.callback.register('shop:getData', function(source)
return true
end)
Client ต้องเรียก
lib.callback.await('shop:getData', false)
ถ้าเขียน
shop:getdata
คนละตัวพิมพ์
ก็เป็น Bug ของ Script ไม่ใช่ ox_lib Installation
㊻ Zones Error แก้อย่างไร
ถ้า Error ระบุ
imports/zones
ให้ดู Error ถัดจากชื่อ Module
เช่น
syntax error
unexpected symbol
attempt to call nil
ถ้าเกิดใน Official Library File ที่ไม่เคยแก้ ให้ตรวจ
Release ครบไหม
ไฟล์คนละ Versionไหม
ถูกแก้โดย Server Pack หรือไม่
FXServer ปัจจุบันไหม
ก่อนแก้ Library Code
㊼ ถ้า ox_lib จาก Server Pack ควรทำอย่างไร
Server Pack อาจมี Library ที่
เก่า
แก้เอง
ไฟล์ไม่ครบ
Fork ไม่ทราบที่มา
ก่อนใช้กับ Script ใหม่ควรตรวจ
Repository
Version
Changes
ถ้าไม่รู้ที่มา การเริ่มจาก Official Release ใน Test Serverมัก Debug ง่ายกว่า
㊽ อย่าผสม Fork โดยไม่รู้ตัว
ตัวอย่าง
ox_lib จาก Fork A
ox_inventory จาก Official
ox_target จาก Server Pack เก่า
อาจเกิด API/Version Mismatch
สำหรับ Core Dependencies ควรมี Source ที่ตรวจสอบได้และบันทึก Version ไว้
โดยเฉพาะ Production Server
㊾ ox_inventory บอก requires ox_lib
ถ้า ox_inventory ขึ้น
ox_inventory requires the ox_lib resource
ให้แก้
ox_lib
ก่อน
Current ox_inventory ตรวจว่ามี Global lib และตรวจ Minimum Dependency Versions ตอน Initialization
ดังนั้น Inventory Error อาจเป็นเพียงผลจาก Library ไม่พร้อม
㊿ ox_inventory Version Check ช่วยหาอะไร
Current Source มีการตรวจ Dependency อย่างเป็นระบบ
เช่น
oxmysql
ox_lib
ถ้า Version ไม่ผ่านจะหยุด Initialization
อย่ามอง Version Check เป็นสิ่งรบกวน
มันช่วยป้องกัน Resource ทำงานครึ่ง ๆ กลาง ๆ กับ API คนละรุ่น
51. Resource ลูกบอก Missing Module
ถ้าเจอ
module not found
หรือ Error จาก
imports/<module>
ให้ตรวจว่า Script อ้าง Module ที่ Current ox_lib มีจริงหรือไม่
โดยเฉพาะ Script เก่าที่เขียนกับ Library รุ่นเก่ามาก หรือ Script ใหม่ที่ต้องการ Library ใหม่กว่า
Version Compatibility เป็นจุดแรกที่ควรตรวจ
52. แยก Client Error กับ Server Error
F8
เหมาะกับ
Notification
Menu
Progress
TextUI
NUI
Client Module
Server Console
เหมาะกับ
Resource Start
Dependency
Server Callback
Database-related child script
Server Module
อย่าดู Console ฝั่งเดียวแล้วสรุปว่าไม่มี Error
53. วิธี Debug ที่เร็วที่สุด
ใช้ลำดับ
stop resource ลูก
↓
ensure ox_lib
↓
ตรวจว่า ox_lib สะอาด
↓
ensure resource ลูก
↓
อ่าน Error แรก
ถ้า Resource ลูกสิบตัวพังพร้อมกัน ให้ปิดไว้ก่อนแล้วทดสอบทีละตัว
ทำให้ Console อ่านง่ายมากขึ้น
54. สร้าง Script ทดสอบ ox_lib
สร้าง Resource เล็ก ๆ
fxmanifest.lua
fx_version 'cerulean'
game 'gta5'
shared_script '@ox_lib/init.lua'
client_script 'client.lua'
dependency 'ox_lib'
client.lua
RegisterCommand('oxlibtest', function()
lib.notify({
title = 'ox_lib',
description = 'Library ทำงานปกติ',
type = 'success'
})
end)
แล้วใช้
/oxlibtest
55. ถ้า Script ทดสอบทำงานแปลว่าอะไร
ถ้า Notification ขึ้น แปลว่าพื้นฐานต่อไปนี้ผ่านแล้ว
ox_lib Start
↓
Initializer Import
↓
Client lib Global
↓
NUI
↓
Notification Module
ถ้า Paid Script ยัง Error ต่อ
Root Cause มีโอกาสอยู่ใน
Paid Script
Version Compatibility
Configuration
Framework Integration
มากกว่า Installation พื้นฐานของ ox_lib
56. Clear Cache ควรใช้เมื่อไร
Cache อาจเกี่ยวกับปัญหา FiveM บางประเภท แต่ไม่ควรเป็นคำตอบแรกของ
Couldn't find resource
Missing fxmanifest
ox_lib must be started
lib nil
Unable to load UI
Version too old
เพราะ Errors เหล่านี้มีสาเหตุเชิงโครงสร้างที่ชัดกว่า
แก้ Files/Order/Version ให้ถูกก่อน
57. Restart ox_lib ระหว่างผู้เล่นออนไลน์ดีไหม
ไม่ควรทำโดยไม่จำเป็น
เพราะ Library อาจเป็น Dependency ของ
Inventory
Target
Framework
Jobs
Phone
Custom Scripts
การ Restart Dependency กลางอาจสร้าง Side Effects ให้ Resources ชั้นบน
Production Server ควรใช้ Maintenance Window สำหรับการ Update ใหญ่
58. ถ้าแก้ Script ลูกให้ Restart ตัวไหน
ถ้าแก้
my_job
ลอง
restart my_job
ก่อน
ไม่จำเป็นต้อง
restart ox_lib
ทุกครั้ง
Restart Dependency กลางเฉพาะเมื่อแก้หรือ Update Library จริง
59. Checklist แก้ ox_lib Error
Files
Folder ชื่อ
ox_libไม่มี Folder ซ้อน
fxmanifest.luaอยู่ Rootinit.luaมีweb/build/index.htmlมีใช้ Release ชุดเดียวกัน
Version
ox_libผ่าน Minimum Version ของ Scriptไม่มีไฟล์หลาย Version ปะปน
FXServer Artifact ผ่าน Requirement
Server
OneSync เปิดตาม Requirement
ox_libStart สำเร็จไม่มี Critical Error หลัง Start
Start Order
ensure ox_lib
ensure dependent_script
Script
มี
shared_script '@ox_lib/init.lua'
เพียงครั้งเดียว
Client
ตรวจ F8
UI ทำงาน
libไม่เป็น nil
Server
ตรวจ Console
Callback/Module ไม่มี Error
60. ตาราง ox_lib Error และวิธีแก้
| Error | สาเหตุที่ควรตรวจอันดับแรก | วิธีแก้ |
|---|---|---|
Couldn't find resource ox_lib | Path/ชื่อ Folder | วาง Resource ให้ถูกแล้ว refresh |
does not have a resource manifest | Folder ซ้อน/Package ผิด | ให้ fxmanifest.lua อยู่ Root |
ox_lib must be started before this resource | Start Order | ensure ox_lib ก่อน Script |
lib is nil | ไม่ได้ Import Library | เพิ่ม @ox_lib/init.lua |
Cannot load ox_lib more than once | Import ซ้ำ | ลบ Duplicate Entry |
Unable to load UI | ไม่มี web/build | ใช้ Release หรือ Build Source |
| Version too old | Dependency Version ไม่ถึง | Update ox_lib |
Error importing module | ไฟล์/Version/API | ตรวจ Release และ Mixed Files |
| OneSync requirement | Server Config | เปิด/ใช้ OneSync ตาม Requirement |
| Server build requirement | Artifact เก่า | Update FXServer |
| UI ไม่แสดง | Client/NUI | ตรวจ F8 และ UI Build |
| Callback ไม่ทำงาน | Script Logic/Side | ตรวจ Callback Register/Name/Console |
วิธีแก้ ox_lib Error แบบเร็วที่สุด
ถ้าต้องการ Checklist สั้น ๆ ให้ทำตามนี้
① หยุด Scripts ที่พึ่ง ox_lib ชั่วคราว
② ตรวจ Folder ox_lib
③ ตรวจ fxmanifest.lua
④ ตรวจ web/build/index.html
⑤ ตรวจ Version ใน fxmanifest.lua
⑥ ใช้ Official Release ถ้า Package ไม่แน่ใจ
⑦ ตรวจ FXServer Artifact
⑧ ตรวจ OneSync
⑨ ใส่ ensure ox_lib ก่อน Scripts ลูก
⑩ Start ox_lib
⑪ อ่าน Error ของ ox_lib ให้หมด
⑫ เปิด Script ลูกทีละตัว
⑬ ตรวจ @ox_lib/init.lua
⑭ ตรวจว่าไม่ได้ Import ซ้ำ
⑮ ตรวจ Minimum ox_lib Version
⑯ ตรวจ Client F8
⑰ ตรวจ Server Console
⑱ ทดสอบ lib.notify ด้วย Resource เล็ก ๆ
⑲ ถ้าทดสอบผ่าน ให้ Debug Script ลูก
⑳ Backup Working Version
สิ่งที่ไม่ควรทำเวลา ox_lib Error
อย่าทำแบบนี้เป็นวิธีแรก
Clear Cache
↓
Restart
↓
ยังพัง
↓
Clear Cache อีก
หรือ
ลบ Version Check
ลบ dependency
แก้ init.lua
Rename Resource
เพียงเพื่อให้ Error หาย
Error Check ส่วนใหญ่มีไว้บอกว่าระบบกำลังใช้ Stack ที่ไม่ตรง Requirement
การบังคับให้ Resource Start ไม่ได้หมายความว่ามันทำงานถูกต้อง
ลำดับการ Debug OX Stack
ถ้าใช้ Stack
oxmysql
ox_lib
qbx_core
ox_target
ox_inventory
custom_job
ให้ Debug
① oxmysql
↓
② ox_lib
↓
③ qbx_core
↓
④ ox_target
↓
⑤ ox_inventory
↓
⑥ custom_job
อย่าเริ่มจาก custom_job ถ้า ox_lib ยัง Error
นี่ช่วยลดเวลาหาปัญหาได้มาก
ถ้า Update แล้ว ox_lib พังทันที
ให้ถาม
Update ox_lib ตัวเดียวหรือหลายตัว?
Replace ครบทั้ง Folder หรือไม่?
มี Old Files ค้างไหม?
Dependent Resources รองรับ Version ใหม่ไหม?
หาก Production เพิ่งพังหลัง Update และมี Backup ที่รู้ว่าใช้งานได้ ควรพิจารณา Rollback เพื่อคืน Service ก่อน แล้วค่อยทดสอบ Version ใหม่ใน Test Environment
Server Pack เก่ากับ ox_lib ใหม่
เป็นคู่ที่ต้องระวัง
Server Pack เก่าอาจประกอบด้วย
FXServer เก่า
Framework เก่า
Inventory เก่า
Custom Forks
แต่เอา ox_lib รุ่นใหม่สุดมาทับตัวเดียว
ผลอาจเป็น Version Mismatch
ควร Update Stack อย่างมีแผน ไม่ใช่ Resource เดียวโดยไม่ดู Dependencies
สรุป ox_lib Error แก้อย่างไร
ปัญหา ox_lib Error ส่วนใหญ่สามารถไล่หาได้จาก 5 เรื่องหลัก
Files
Start Order
Import
Version
Runtime Requirements
ถ้าเจอ
ox_lib must be started before this resource
ให้ตรวจ server.cfg และ Start ox_lib ก่อน Resource ลูก
ถ้าเจอ
lib is nil
ให้ตรวจ fxmanifest.lua ของ Script ว่ามี
shared_script '@ox_lib/init.lua'
หรือไม่
ถ้าเจอ
Unable to load UI
ให้ตรวจ
web/build/index.html
และใช้ Official Release ที่ Build แล้ว หรือ Build Source ให้ครบ
ถ้าเจอ Version Error ให้ Update Dependency ให้ตรง Requirement ไม่ควรลบ Version Check ออกจาก Resource
Current ox_lib ที่ตรวจสอบในบทความนี้ระบุ Version 3.39.0 และ Manifest มี Runtime Constraints สำหรับ OneSync และ Server Build ขณะที่ Current ox_inventory ยังตรวจ Minimum ox_lib Version ของตัวเองก่อน Initialization แสดงให้เห็นว่า OX Resources ถูกออกแบบให้ตรวจ Compatibility ระหว่างกันจริง
แนวทางของ comsiam คือเมื่อ OX Stack พังหลาย Resource พร้อมกัน ให้หยุดมอง Error หลายร้อยบรรทัดแล้วกลับไปแก้ Dependency จากล่างขึ้นบน เช่น oxmysql → ox_lib → Framework → ox_target → ox_inventory → Custom Scripts เพราะ Error จำนวนมากด้านบนอาจเกิดจาก Root Cause เพียงตัวเดียว
สำหรับ Production Server comsiam แนะนำให้เก็บ Version ของ ox_lib ที่ใช้งานได้ไว้ใน Git หรือ Backup นอก Active Resources Directory และทดสอบ Update บน Test Server ก่อนเสมอ เนื่องจาก ox_lib อาจเป็น Dependency กลางของ Scripts จำนวนมาก การ Update ผิดเพียงครั้งเดียวจึงสามารถกระทบหลายระบบพร้อมกันได้
Comments
Post a Comment