ox_target คืออะไร ใช้งานอย่างไรใน FiveM
ox_target คือ Targeting Resource หรือระบบ Third-eye สำหรับ FiveM ที่ทำให้ผู้เล่นสามารถมองไปยัง NPC, Player, Vehicle, Object หรือพื้นที่ที่กำหนด แล้วเลือกคำสั่งที่ต้องการจาก Target Menu ได้
แทนที่จะใช้ระบบเดิมแบบ
เดินไป Marker
↓
เห็นข้อความ
↓
กด E
↓
เปิดเมนู
สามารถเปลี่ยนเป็น
มอง NPC / รถ / Object / Zone
↓
เปิด Target
↓
เลือก Action
↓
ทำงาน
ตัวอย่างการใช้งาน เช่น
มอง NPC
→ ซื้อของ
→ เริ่มงาน
→ เปิด Garage
มอง Player
→ ค้นตัว
→ ใส่กุญแจมือ
→ ช่วยชีวิต
มองรถ
→ เปิดประตู
→ เปิดท้ายรถ
→ ตรวจทะเบียน
มอง Object
→ เปิด Stash
→ Craft Item
→ ใช้งานเครื่องจักร
Current ox_target ถูกออกแบบเป็น Standalone Targeting Resource จึงไม่จำเป็นต้องใช้ Framework เพื่อให้ระบบ Target พื้นฐานทำงาน แต่มี Integration เพิ่มเติมกับ Framework เช่น ox_core, ESX และ qbx_core
① ox_target คืออะไรแบบง่ายที่สุด
สมมติ Server มี NPC ขายรถ
ระบบเก่าอาจทำ
NPC
↓
Marker
↓
[E] เปิดร้านรถ
แต่ ox_target สามารถทำ
NPC
↓
เล็ง Target
↓
ซื้อรถ
ทดลองขับ
ดูรายการรถ
หลาย Options อยู่บน Entity ตัวเดียวกันได้
นี่ทำให้ Interaction ของ FiveM RP ดูสะอาดกว่าการวาง Marker และข้อความจำนวนมากทั่ว Map
② ทำไมถึงเรียกว่า Third-eye
Community FiveM มักเรียกระบบ Target ว่า
Third Eye
เพราะ Player เปิด Target Mode แล้วระบบจะตรวจสิ่งที่ Player กำลังมอง
จากนั้นแสดง Options ที่ใช้กับ Entity หรือ Zone นั้นได้
ตัวอย่าง
เปิด Third-eye
↓
มองท้ายรถ
↓
เห็น "เปิดท้ายรถ"
หรือ
มองตำรวจ
↓
เห็น "แสดงบัตร"
ตาม Script ที่ติดตั้ง
③ ox_target เป็น Framework หรือไม่
ไม่ใช่
ox_target
≠ Framework
มันคือ Standalone Target Resource
Framework เช่น
ESX
QBCore
Qbox
ox_core
มีหน้าที่เกี่ยวกับ Player/Character/Jobs/Money
ส่วน ox_target มีหน้าที่หลักด้าน
Interaction
Entity Targeting
Zones
Options
จึงสามารถใช้ Target โดยไม่ใช้ Framework ได้
④ ox_target ต้องใช้ ox_lib หรือไม่
ต้องใช้
Current fxmanifest.lua ประกาศ
dependency 'ox_lib'
และ Import
@ox_lib/init.lua
ดังนั้น Start Order พื้นฐานคือ
ensure ox_lib
ensure ox_target
ถ้า ox_lib Error ตัว ox_target ก็สามารถ Error ตามได้
⑤ ox_target ใช้กับ Framework อะไรได้บ้าง
Current Documentation ระบุ Framework Integrations ได้แก่
ox_core
ESX
qbx_core
Framework ไม่จำเป็นสำหรับระบบ Target พื้นฐาน แต่ Integration ช่วยเพิ่ม Feature เช่นการตรวจ
Groups
Jobs
Items
ตาม Framework ที่ใช้
⑥ QBCore ใช้ ox_target ได้ไหม
สามารถมี Community Integration หรือ Custom Scripts ที่รองรับได้ แต่ Current Official Framework Integration ระบุ qbx_core ไม่ใช่ qb-core เป็น Framework Integration หลัก
จึงควรแยก
QBCore
≠
Qbox
ให้ชัด
ถ้า Script QBCore เดิมใช้ qb-target ไม่ควรเปลี่ยนเป็น ox_target แล้วคาดว่า APIs ทั้งหมดเหมือนกันโดยอัตโนมัติ
⑦ ox_target มี qtarget compatibility หรือไม่
มี Compatibility Layer สำหรับ
qtarget
Current Manifest ยังประกาศ
provide 'qtarget'
และ Source มี Compatibility Exports สำหรับ Functions หลายรายการ เช่น
AddBoxZone
AddPolyZone
AddCircleZone
AddTargetEntity
AddTargetModel
AddTargetBone
แต่ Compatibility ไม่ได้หมายความว่า Script ทุกตัวจาก Target ระบบอื่นจะทำงาน 100% โดยไม่ตรวจ
⑧ ox_target ทำงานกับอะไรได้บ้าง
เป้าหมายหลัก ได้แก่
Ped
Player
Vehicle
Object
Model
Network Entity
Local Entity
Zone
ดังนั้น Developer สามารถเลือก Target ให้ละเอียดตั้งแต่
NPC ทุกตัว
ไปจนถึง
NPC ตัวนี้เท่านั้น
ได้
⑨ Global Ped Target คืออะไร
ใช้เพิ่ม Option ให้ NPC/Ped ทั้งหมด
Current API มี
exports.ox_target:addGlobalPed(options)
ตัวอย่างแนวคิด
exports.ox_target:addGlobalPed({
{
name = 'talk_to_ped',
label = 'พูดคุย',
icon = 'fa-solid fa-comments',
distance = 2.0,
onSelect = function(data)
print('Talking to ped')
end
}
})
Option นี้สามารถปรากฏกับ Ped ทั่วไปตามเงื่อนไขที่กำหนด
⑩ Global Player Target คืออะไร
ใช้เพิ่ม Options ให้ Player Entities
API คือ
exports.ox_target:addGlobalPlayer(options)
เหมาะกับระบบ เช่น
Police
→ ใส่กุญแจมือ
→ ค้นตัว
→ พาขึ้นรถ
EMS
→ ตรวจอาการ
→ ช่วยชีวิต
ทั่วไป
→ แสดงบัตรประชาชน
แต่ Permissions และ Security ต้องตรวจ Server-side อีกชั้น
⑪ Global Vehicle Target คืออะไร
ใช้เพิ่ม Options ให้รถทั้งหมด
exports.ox_target:addGlobalVehicle(options)
เช่น
ตรวจทะเบียน
เปิด Hood
เปิด Trunk
ซ่อมรถ
ลากรถ
ค้นรถ
Current ox_target เองยังมี Built-in Vehicle Options บางส่วน เช่นการเปิด/ปิดประตูรถเมื่อเปิด Defaults
⑫ Global Object Target คืออะไร
ใช้กับ Object Entities ทั้งหมดผ่าน
exports.ox_target:addGlobalObject(options)
เหมาะกับระบบ เช่น
ตู้
ลัง
เครื่องขายของ
Workbench
เครื่อง ATM
Object ที่ Script Spawn
โดยใช้ canInteract กรองว่า Object ใดควรแสดง Option
⑬ addModel คืออะไร
ถ้าต้องการ Target เฉพาะ Model สามารถใช้
exports.ox_target:addModel(models, options)
เช่นต้องการให้เฉพาะ ATM Models มี
ใช้งาน ATM
โดยไม่ต้อง Register Entity ทีละตัว
ตัวอย่างแนวคิด
exports.ox_target:addModel('prop_atm_01', {
{
name = 'use_atm',
label = 'ใช้ ATM',
icon = 'fa-solid fa-credit-card',
distance = 2.0
}
})
⑭ addEntity คืออะไร
ใช้กับ Networked Entity
Current API รับ
Network ID
ผ่าน
exports.ox_target:addEntity(netIds, options)
เหมาะเมื่อ Entity ถูก Network ให้ Player หลายคนเห็น
เช่น
Mission Vehicle
Networked NPC
Shared Object
⑮ addLocalEntity คืออะไร
ใช้กับ Local Entity Handle
exports.ox_target:addLocalEntity(entity, options)
เหมาะกับ Entity ที่ Client สร้างและใช้เฉพาะใน Context นั้น
ความต่างหลักคือ
addEntity
→ Network ID
addLocalEntity
→ Entity Handle
ใช้ให้ตรงกับชนิด Entity ที่สร้าง
⑯ Network ID กับ Entity Handle อย่าสับสน
ตัวอย่าง
local entity = CreatePed(...)
ค่าที่ได้คือ Entity Handle
ถ้าต้องใช้ Network Target อาจต้องแปลง
local netId = NetworkGetNetworkIdFromEntity(entity)
แล้วใช้กับ
exports.ox_target:addEntity(netId, options)
อย่าส่ง Entity Handle ไปยัง API ที่คาด Network ID โดยไม่ตรวจ Documentation
⑰ ox_target มี Zone หรือไม่
มี และเป็นความสามารถสำคัญมาก
รองรับ
Sphere Zone
Box Zone
Poly Zone
ใช้สร้างพื้นที่ Target ที่ไม่จำเป็นต้องมี Entity จริง
เช่น
หน้าประตู
เคาน์เตอร์ร้าน
จุด Craft
Garage
Boss Menu
Warehouse
⑱ Sphere Zone คืออะไร
เป็นพื้นที่ Target ทรงกลมรอบ Coordinates
Current API
exports.ox_target:addSphereZone({
coords = vec3(...),
radius = 2.0,
options = {}
})
เหมาะกับจุด Interaction ที่ไม่ต้องการ Shape ซับซ้อน
⑲ ตัวอย่าง Sphere Zone
exports.ox_target:addSphereZone({
coords = vec3(100.0, 200.0, 30.0),
radius = 1.5,
options = {
{
name = 'open_shop',
icon = 'fa-solid fa-store',
label = 'เปิดร้าน',
distance = 2.0,
onSelect = function()
print('Open shop')
end
}
}
})
Player เข้าใกล้และเปิด Target ก็สามารถเลือก Option ได้
⑳ Box Zone คืออะไร
ใช้สร้าง Target Area ทรงกล่อง
API คือ
exports.ox_target:addBoxZone(...)
สามารถกำหนด
coords
size
rotation
เหมาะกับพื้นที่รูปทรงชัด เช่น
Counter
Door
Elevator
Garage Terminal
Workbench
㉑ ตัวอย่าง Box Zone
exports.ox_target:addBoxZone({
coords = vec3(100.0, 200.0, 30.0),
size = vec3(2.0, 1.0, 2.0),
rotation = 90.0,
debug = false,
options = {
{
name = 'garage_menu',
label = 'เปิด Garage',
icon = 'fa-solid fa-car',
distance = 2.0,
onSelect = function()
print('Open garage')
end
}
}
})
เหมาะกับจุดใช้งานที่ต้องการควบคุมพื้นที่แม่นยำ
㉒ Poly Zone คืออะไร
ใช้กำหนด Polygon จากหลาย Points
exports.ox_target:addPolyZone(...)
เหมาะกับพื้นที่ที่
ไม่เป็นวงกลม
ไม่เป็นสี่เหลี่ยมตรง ๆ
เช่นพื้นที่ Building หรือ Compound ที่มี Shape ซับซ้อน
โดยกำหนด points หลายจุดและ thickness
㉓ Zone แบบไหนควรเลือก
Sphere
เหมาะกับ
NPC จุดเดียว
โต๊ะเล็ก
Marker กลางพื้นที่
Box
เหมาะกับ
ประตู
Counter
เครื่องจักร
Garage Panel
Poly
เหมาะกับ
พื้นที่หลายมุม
Building Zone
Custom Area
ใช้ Shape ง่ายที่สุดที่ตอบโจทย์จะดูแลง่ายกว่า
㉔ debug Zone มีประโยชน์มาก
ระหว่างพัฒนาเปิด
debug = true
เพื่อดู Shape ของ Zone
ช่วยตรวจปัญหา เช่น
Zone เล็กเกิน
Zone ลอยสูง
Rotation ผิด
Coordinates ผิด
หลัง Setup เสร็จควรปิด Debug สำหรับ Production หากไม่จำเป็น
㉕ drawSprite คืออะไร
Zone APIs รองรับ
drawSprite
เพื่อแสดง Sprite ที่จุดกึ่งกลาง Zone
Default ปัจจุบันของ Zone API ระบุว่าเปิดไว้
สามารถปิดได้หากต้องการ Interaction ที่สะอาดขึ้น
㉖ Target Option มีอะไรบ้าง
Current TargetOption รองรับ Properties สำคัญ เช่น
label
name
icon
iconColor
distance
bones
offset
offsetAbsolute
offsetSize
groups
items
anyItem
canInteract
menuName
openMenu
onSelect
export
event
serverEvent
command
นี่คือหัวใจของ ox_target
㉗ label คืออะไร
ข้อความที่ Player เห็น
ตัวอย่าง
label = 'เปิดร้าน'
หรือ
label = 'ค้นตัว'
ควรเขียนสั้นและสื่อ Action ชัดเจน
㉘ name คืออะไร
ใช้เป็น Identifier ของ Target Option
เช่น
name = 'police_search_player'
มีประโยชน์ตอน Remove Option
Current Remove APIs สามารถระบุชื่อ Option ที่ต้องการลบได้
ควรให้ Name ไม่ซ้ำกันในระบบที่เกี่ยวข้อง
㉙ icon คืออะไร
ใช้ Font Awesome Icon Name
ตัวอย่าง
icon = 'fa-solid fa-car'
หรือ
icon = 'fa-solid fa-box'
ช่วยให้ Target Menu อ่าน Action ได้ง่ายขึ้น
㉚ distance คืออะไร
กำหนดระยะสูงสุดที่ Option จะแสดง
เช่น
distance = 2.0
แปลว่า Player ต้องอยู่ใกล้ Target ประมาณ 2 Game Units ตาม Context จึงจะเห็น Option
ไม่ควรตั้ง
distance = 100
โดยไม่มีเหตุผล เพราะจะทำให้ Interaction แสดงไกลเกินไป
㉛ groups ใช้จำกัด Job ได้
Current TargetOption รองรับ
groups = 'police'
หรือ
groups = {
police = 2
}
เพื่อกำหนด Group/Grade Requirement
ตัวอย่าง
Police Grade 2+
→ เปิด Evidence Room
แต่ groups เป็น Framework-dependent
จึงต้องใช้ Framework Integration ที่รองรับ
㉜ groups ไม่ได้หมายถึง Job อย่างเดียวเสมอไป
Documentation ระบุว่า Groups ขึ้นกับ Framework และอาจหมายถึง
Jobs
Gangs
Groups
ตาม Framework
ดังนั้นอย่า Hardcode สมมติว่า groups แปลว่า ESX Job ทุก Server
ต้องดู Player Group Architecture ของ Framework ที่ใช้
㉝ items ใช้จำกัด Item ได้
สามารถกำหนด
items = 'lockpick'
เพื่อให้ Option แสดงเฉพาะ Player ที่มี Item
หรือ
items = {
lockpick = 1
}
สำหรับจำนวนที่ต้องมี
นี่มีประโยชน์กับ Interaction เช่น
Lockpick Door
Repair Vehicle
Use Keycard
㉞ anyItem คืออะไร
ถ้า items มีหลายรายการ โดยปกติ Logic อาจต้องการตาม Configuration ของ Target
สามารถใช้
anyItem = true
เพื่อให้ Player มี Item อย่างใดอย่างหนึ่งจากรายการก็ผ่าน
เช่น
police_keycard
OR
master_keycard
ไม่จำเป็นต้องมีครบทุกชนิด
㉟ canInteract คืออะไร
canInteract เป็น Function สำหรับตัดสินแบบ Dynamic ว่า Option ควรแสดงหรือไม่
Signature ปัจจุบันประมาณ
canInteract = function(entity, distance, coords, name, bone)
return true
end
สามารถตรวจ
Entity
Distance
Vehicle State
Custom State
Local Variables
ก่อนแสดง Option
㊱ ตัวอย่าง canInteract
สมมติให้เปิด Hood เฉพาะรถดับเครื่อง
canInteract = function(entity)
return not GetIsVehicleEngineRunning(entity)
end
ถ้า Engine เปิดอยู่ Option จะไม่แสดง
ทำให้ Target Menu แสดงเฉพาะ Action ที่ใช้ได้จริงในสถานการณ์นั้น
㊲ อย่าใช้ canInteract แทน Server Security
canInteract ทำงานใน Client Context
จึงไม่ควรใช้เป็น Security Boundary สำหรับ
Money
Items
Rewards
Permissions สำคัญ
ตัวอย่าง
canInteract
→ ตรวจว่าเป็น police
ช่วยซ่อน Option ได้
แต่ Event ฝั่ง Server ยังต้องตรวจ Job/Permission ซ้ำ
㊳ onSelect คืออะไร
เป็น Callback ที่ทำงานเมื่อ Player เลือก Option
ตัวอย่าง
onSelect = function(data)
print(data.entity)
end
เหมาะกับ Client Logic ที่ไม่จำเป็นต้อง Trigger Event แยก
data จะมีข้อมูลเกี่ยวกับ Target ที่เลือก
㊴ data มีอะไรบ้าง
Current Documentation ระบุข้อมูลหลัก เช่น
entity
coords
distance
zone
โดย zone มีเมื่อ Option มาจาก Zone
ถ้าเป็น serverEvent ค่า Entity ที่ส่งจะถูกแปลงเป็น Network ID ตาม Current Target Callback Behavior
㊵ event คืออะไร
ใช้ Trigger Client Event
ตัวอย่าง
event = 'myshop:client:open'
เมื่อ Player เลือก Option ox_target จะ Trigger Event นี้
เหมาะกับ Client-side UI หรือ Gameplay Flow
㊶ serverEvent คืออะไร
ใช้ Trigger Server Event
serverEvent = 'myjob:server:start'
เหมาะเมื่อ Action ต้องให้ Server เป็นผู้ตัดสิน เช่น
Reward
Inventory
Money
Permissions
Database
แต่ Event ฝั่ง Serverต้อง Validate ข้อมูลอีกครั้ง
㊷ command คืออะไร
Target Option สามารถเรียก Command ได้
ตัวอย่าง
command = 'somecommand'
แต่สำหรับ Custom Systems ระยะยาว มักอ่านง่ายกว่าถ้าใช้
onSelect
event
serverEvent
export
ตาม Architecture ของ Resource
㊸ ถ้ามีหลาย Action ระบบเลือกอะไร
Current Documentation กำหนด Priority เมื่อเลือก Option เป็น
1. onSelect
2. export
3. event
4. serverEvent
5. command
ดังนั้นไม่ควรใส่ทุก Action Type ลง Option เดียวโดยไม่เข้าใจ Priority
เลือกวิธีเดียวที่เหมาะกับงานจะชัดกว่า
㊹ bones ใช้ทำอะไร
ใช้ Target เฉพาะ Bone ของ Entity
ตัวอย่าง Vehicle Bones
door_dside_f
door_pside_f
door_dside_r
door_pside_r
เหมาะกับ
ประตูรถ
ล้อ
เครื่องยนต์
ท้ายรถ
ทำให้ผู้เล่นต้องมองตำแหน่งที่ถูกต้องบน Vehicle ก่อนเห็น Option
㊺ ox_target มี Built-in Vehicle Door Interaction
Current Defaults Source เพิ่ม Global Vehicle Options สำหรับ
ประตูคนขับหน้า
ประตูผู้โดยสารหน้า
ประตูหลัง
Hood
Trunk
และตรวจสถานะ เช่น Door Lock ก่อนอนุญาต Interaction
Feature นี้ควบคุมได้ด้วย Convar Defaults
㊻ ปิด Built-in Target Options ได้ไหม
ได้
Current Config มี
setr ox_target:defaults 1
ถ้าไม่ต้องการ Built-in Options ให้ปรับตาม Configuration
เช่นปิดแล้วสร้าง Vehicle Interactions เองทั้งหมด
เหมาะกับ Server ที่มี Vehicle Script Custom อยู่แล้ว
㊼ Default Hotkey คืออะไร
Current Documentation ใช้
setr ox_target:defaultHotkey LMENU
โดย LMENU โดยทั่วไปคือ Left Alt ตาม FiveM Input Mapper
จึงมักเห็นผู้เล่นกด
Left Alt
เพื่อเปิด Third-eye
แต่ Server สามารถเปลี่ยน Key ได้
㊽ Toggle กับ Hold ต่างกันอย่างไร
Current Config มี
setr ox_target:toggleHotkey 0
ค่า 0 หมายถึงแนวทาง Hold ตาม Default
ถ้าเปิด Toggle Mode ผู้เล่นกดหนึ่งครั้งเพื่อเปิด/ปิด Target แทนการกดค้าง
เลือกตาม UX ของ Server
㊾ ox_target:leftClick คืออะไร
Current Config มี
setr ox_target:leftClick 1
ใช้เปิดให้ Left Click เลือก Target Option
ถ้าปิด ระบบจะใช้ Behavior อื่นตาม Current Target Controls
Server ควรทดสอบ Controls กับ UI/Keybinds อื่นเพื่อไม่ให้ชนกัน
㊿ ox_target:drawSprite คืออะไร
Current Default
setr ox_target:drawSprite 1
ใช้แสดง Circle/Sprite บริเวณ Targetable Zone
หาก Server ต้องการ UI ที่ Minimal สามารถปรับได้
แต่ตอน Development เปิดไว้ช่วยหา Zone ได้ง่าย
51. ox_target:debug คืออะไร
เปิดด้วย
setr ox_target:debug 1
Current Documentation ระบุว่า Debug Mode ช่วยแสดง
Testing Options
Entity Outlines
Raycast Indicator
มีประโยชน์มากตอนสร้าง Custom Target
Production ปกติควรปิดถ้าไม่ต้องใช้
52. ตัวอย่าง Config พื้นฐาน
setr ox_target:toggleHotkey 0
setr ox_target:defaultHotkey LMENU
setr ox_target:drawSprite 1
setr ox_target:defaults 1
setr ox_target:debug 0
setr ox_target:leftClick 1
ensure ox_lib
ensure ox_target
จากนั้นค่อย Start Resources ที่ต้องใช้ Target
53. ตัวอย่าง Target NPC
สมมติ Spawn NPC ไว้แล้ว
exports.ox_target:addLocalEntity(ped, {
{
name = 'job_start',
icon = 'fa-solid fa-briefcase',
label = 'เริ่มงาน',
distance = 2.0,
onSelect = function(data)
TriggerEvent('myjob:start')
end
}
})
Player จะเห็น Option เมื่อเปิด Target และมอง NPC ในระยะที่กำหนด
54. Target NPC เฉพาะ Model
ถ้าไม่ต้องการเก็บ Entity Handle สามารถใช้ Model
exports.ox_target:addModel('s_m_m_doctor_01', {
{
name = 'doctor_talk',
label = 'พูดคุยกับหมอ',
icon = 'fa-solid fa-user-doctor',
distance = 2.0,
onSelect = function()
print('doctor')
end
}
})
แต่จำไว้ว่า Option จะใช้กับ Model นั้นทุก Entity
55. ตัวอย่าง Target Vehicle
exports.ox_target:addGlobalVehicle({
{
name = 'vehicle_check',
icon = 'fa-solid fa-car',
label = 'ตรวจสอบรถ',
distance = 2.0,
onSelect = function(data)
local vehicle = data.entity
print(vehicle)
end
}
})
จากนั้นสามารถเพิ่ม canInteract เพื่อจำกัดตาม Vehicle State
56. ตัวอย่างเฉพาะตำรวจ
exports.ox_target:addGlobalVehicle({
{
name = 'police_vehicle_search',
label = 'ค้นรถ',
icon = 'fa-solid fa-magnifying-glass',
groups = {
police = 0
},
distance = 2.0,
serverEvent = 'police:server:searchVehicle'
}
})
แต่ Server Event ต้องตรวจ Job จริงอีกครั้ง
อย่าเชื่อ groups ฝั่ง Target เป็น Security เพียงชั้นเดียว
57. ตัวอย่างใช้ Item
exports.ox_target:addBoxZone({
coords = vec3(100.0, 200.0, 30.0),
size = vec3(1.0, 1.0, 2.0),
options = {
{
name = 'unlock_door',
label = 'สะเดาะกุญแจ',
icon = 'fa-solid fa-lock-open',
items = 'lockpick',
distance = 2.0,
serverEvent = 'door:server:lockpick'
}
}
})
Target จะช่วยกรอง UI
แต่ Server ยังต้องตรวจ Item lockpick ซ้ำก่อนปลดล็อกจริง
58. Target กับ ox_inventory ใช้ร่วมกันอย่างไร
ox_inventory สามารถใช้ ox_target เป็น Interaction Layer
เช่น
Target NPC
↓
Open Shop
Target Stash
↓
Open Inventory
Target Crafting Bench
↓
Open Crafting
นี่เป็นเหตุผลที่ OX-first Stack มักเห็นสอง Resources นี้อยู่ด้วยกัน
59. ox_inventory ต้องใช้ ox_target เสมอไหม
ไม่
ox_target เป็น Optional Integration ของ Inventory
ถ้าไม่ใช้ Target สามารถตั้ง
setr inventory:target false
และใช้ Marker/Interaction System รูปแบบอื่นได้
ดังนั้น
ox_inventory
≠ ต้องมี ox_target เสมอ
60. Target Shops เหมาะอย่างไร
แทนที่จะมี Marker ตลอดเวลา
Shop
↓
Circle Marker
↓
Press E
สามารถใช้
มอง NPC
↓
Target
↓
ซื้อสินค้า
ช่วยให้พื้นที่ร้านดูสะอาดและ Immersive มากขึ้น
Target กับ Police Job
สามารถสร้าง Options เช่น
ค้นตัว
ใส่กุญแจมือ
ลากตัว
พาขึ้นรถ
ตรวจรถ
ยึดรถ
แต่ Permissions ต้องตรวจ Server-side
เช่น Event
police:server:cuff
ควรตรวจ
Player เป็น Police?
Target ถูกต้อง?
ระยะห่างสมเหตุสมผล?
Player State ถูกต้อง?
ก่อนทำ Action
Target กับ EMS
ใช้กับ Player ได้ เช่น
ตรวจชีพจร
ช่วยชีวิต
รักษา
นำขึ้นเปล
groups = 'ambulance' ช่วยกรอง Option
แต่ Server ต้องตรวจ Job และ State ซ้ำ
Target กับ Mechanic
ใช้กับ Vehicle Bones ได้ดี
เช่น
Engine
Wheel
Door
Trunk
Player ต้องมองส่วนรถที่ถูกต้อง
จากนั้นแสดง
ซ่อมเครื่อง
เปลี่ยนยาง
ตรวจสภาพ
ทำให้ Interaction ดูสมจริงกว่าเมนู Vehicle กลางเพียงตัวเดียว
Target กับ Door System
ประตูไม่จำเป็นต้องเป็น ox_target อย่างเดียว เพราะ Door State ควรถูกจัดการโดย Door Resource
Architecture ที่ดีคือ
ox_target
↓
Player เลือก Action
↓
Door Resource
↓
Server Permission
↓
Lock / Unlock
ไม่ควรให้ Client Target เปลี่ยน Door Security State เองโดยไม่มี Server Validation
Target กับ Garage
สร้าง Zone
Garage Terminal
แล้ว Option
เปิด Garage
เก็บรถ
ดูรถที่ยึด
สามารถใช้ groups จำกัด Garage เฉพาะ Job ได้
เช่น
Police Garage
EMS Garage
Mechanic Garage
Target กับ Business
เหมาะกับ
Boss Menu
Employee Management
Storage
Crafting
Cash Register
Computer
สามารถแบ่ง Target Zones ตามจุดจริงใน MLO
ทำให้ Player ไม่ต้องเปิด Command เพื่อใช้ระบบองค์กร
Target กับ Housing
สามารถ Target
ประตูบ้าน
ตู้เสื้อผ้า
Storage
Furniture
Garage
แต่ต้องให้ Housing Resource เป็น Source of Truth สำหรับ
Owner
Keys
Access
ไม่ควรใช้ canInteract อย่างเดียวตัดสิน Ownership
วิธีลบ Target Option
Global Options มี Remove APIs
เช่น
exports.ox_target:removeGlobalVehicle('vehicle_check')
หรือสำหรับ Models
exports.ox_target:removeModel(model, 'use_atm')
การตั้ง name ให้ Option จึงสำคัญมาก
ลบ Zone อย่างไร
เมื่อสร้าง Zone API จะ Return
id
เก็บไว้
local zoneId = exports.ox_target:addBoxZone(...)
จากนั้นลบ
exports.ox_target:removeZone(zoneId)
Current API ยังรองรับการ Remove ผ่านชื่อ Zone หากกำหนด name
ทำไมต้องลบ Dynamic Targets
ถ้า Resource สร้าง Dynamic Entity หรือ Zone แล้วไม่ Remove เมื่อหมดอายุ อาจเกิด
Target ซ้ำ
Option ซ้ำ
Zone ค้าง
Memory/State สะสม
ดังนั้น Lifecycle ควรเป็น
Create
↓
Add Target
↓
ใช้งาน
↓
Remove Target
↓
Delete Entity
ให้ครบ
Option ซ้ำเกิดจากอะไร
เช่น Resource เรียก
addGlobalVehicle
ทุกครั้งที่ Player Spawn โดยไม่ Remove ตัวเดิม
อาจทำให้ Target Option ซ้ำ
ควร Register Global Options เพียงครั้งเดียวตาม Resource Lifecycle
และใช้ name ที่ชัดเจน
canInteract หนักทำให้ Performance มีปัญหาได้ไหม
ได้
canInteract ถูกประเมินใน Targeting Flow
ถ้าใส่ Logic หนัก เช่น
Database Query
Long Loop
Complex Calculation
ทุกครั้งที่ระบบตรวจ Option จะไม่เหมาะ
Client canInteract ควรเป็น Logic เบา ๆ
เช่น
State
Distance
Entity Type
Cached Values
ข้อมูลสำคัญค่อย Validate ฝั่ง Server เมื่อ Player Select
อย่า Query Database ใน canInteract
Database เป็น Server-side Source
ไม่ควรทำ Architecture แบบ
ทุก Frame ที่ Target Entity
↓
Query Database
↓
ถามว่าเปิด Option ไหม
ควร Cache State หรือใช้ Framework State สำหรับ UX
เมื่อเลือก Action จริงค่อยให้ Serverตรวจ Database/Authority
Target Option เยอะเกินไปดีไหม
ไม่
มองรถแล้วเห็น
20 Options
ทำให้ UX แย่
ควรแสดงเฉพาะ Action ที่เกี่ยวข้องกับ
Job
State
Bone
Distance
Item
Context
ด้วย groups, items, canInteract และ Menus
openMenu กับ menuName คืออะไร
Current TargetOption รองรับ Sub-menu Pattern
openMenu
เปิด Context Menu ภายใน Target
และ Options ที่มี
menuName
จะปรากฏเมื่อ Menu Name นั้น Active
ช่วยจัด Options จำนวนมากเป็น Layer
ตัวอย่าง
Vehicle
↓
Vehicle Actions
├── Doors
├── Mechanic
└── Police
แทนแสดงทุก Action พร้อมกัน
Security ของ ox_target
ต้องจำหลักนี้
ox_target
=
Interaction UI
ไม่ใช่
ox_target
=
Server Security
แม้ Option จะมี
groups = 'police'
ผู้ไม่หวังดีอาจพยายาม Trigger Server Event โดยตรง
ดังนั้น Server Event ต้องตรวจ Permission ซ้ำเสมอ
ตัวอย่าง Security ที่ผิด
RegisterNetEvent('police:server:reward', function()
GiveMoney(source, 100000)
end)
ถ้า Event นี้ไม่มี Validation ต่อให้ Target แสดงเฉพาะตำรวจ Script ก็ยังเสี่ยง
เพราะผู้โจมตีอาจ Trigger Event โดยไม่ผ่าน Target UI
ตัวอย่างแนวคิดที่ถูก
Target
↓
Player เลือก Action
↓
Server Event
↓
ตรวจ Player
↓
ตรวจ Job
↓
ตรวจ Position
↓
ตรวจ State
↓
ทำ Action
Target มีหน้าที่ช่วย UX
Server มีหน้าที่เป็น Authority
ox_target ทำให้ Server เบากว่า Marker เสมอไหม
ไม่ควรเหมารวม
ox_target ถูกออกแบบให้เป็น Targeting Resource ที่มีประสิทธิภาพ แต่ Performance จริงขึ้นอยู่กับ
จำนวน Options
จำนวน Zones
canInteract Logic
Custom Scripts
Entity Count
ถ้า Developer Register Target จำนวนมหาศาลและใส่ canInteract หนัก ๆ ก็ยังสร้างภาระได้
ควรตรวจ Resmon จริง
Current ox_target Version
Current fxmanifest.lua บน Source ที่ตรวจสอบระบุ
1.18.1
แต่ Version สามารถเปลี่ยนได้
จึงควรใช้ Current Release/Source ที่ Project แนะนำในวันที่ติดตั้งจริง
ไม่ควรยึดเลขนี้เป็น Requirement ถาวร
Current ox_lib Requirement
Current ox_target/client/main.lua ตรวจ
ox_lib >= 3.30.0
ใน Source Snapshot ปัจจุบัน
ถ้า ox_lib ต่ำกว่านี้ Target อาจไม่ Initialization
ดังนั้นเมื่อเจอ Dependency Error ให้ Update Stack ให้ Compatible
ไม่ควรลบ checkDependency
ox_target ไม่ทำงานควรตรวจอะไร
ใช้ลำดับ
① ox_lib Start หรือไม่
② ox_lib Version ผ่านหรือไม่
③ ox_target Folder ถูกหรือไม่
④ fxmanifest.lua มีหรือไม่
⑤ ox_target Start สำเร็จหรือไม่
⑥ F8 มี Client Error หรือไม่
⑦ Hotkey ถูกหรือไม่
⑧ Framework Integration ถูกหรือไม่
⑨ Target Options Register หรือไม่
⑩ canInteract Return true หรือไม่
Target เปิดไม่ได้
ตรวจ Config
setr ox_target:defaultHotkey LMENU
จากนั้นตรวจว่า Key Mapping ไม่ชนกับ Script อื่น
ดู Client F8 ด้วย
ถ้า Target Resource มี Error ตั้งแต่ Load Hotkey ย่อมไม่ทำงาน
Target เปิดแต่ไม่มี Option
นี่หมายความว่าตัว Target System อาจทำงานแล้ว
ให้ตรวจ
Target ถูก Register หรือยัง
Entity/Model ถูกไหม
Distance ไกลเกินไหม
Groups ผ่านไหม
Items ครบไหม
canInteract คืน true ไหม
ไม่ควร Reinstall Resource ทันที
NPC มี Target บางตัวแต่บางตัวไม่มี
ถ้าใช้ addModel
ตรวจ Model ของ NPC แต่ละตัว
ถ้าใช้ addEntity
ตรวจ Network ID
ถ้าใช้ addLocalEntity
ตรวจ Entity Handle
นี่เป็นปัญหา Scope ของ Target มากกว่า Core Resource
Option ขึ้นแต่กดแล้วไม่ทำงาน
ตรวจ Action Type
onSelect
export
event
serverEvent
command
จากนั้นดู F8/Console ตาม Side ที่ทำงาน
ถ้าใช้
serverEvent
ดู Server Console
ถ้าใช้
event
ดู Client F8
Zone ไม่ตรงตำแหน่ง
เปิด
debug = true
แล้วดู Shape จริง
ตรวจ
coords
size
rotation
radius
thickness
แทนการแก้ Coordinates แบบเดาสุ่ม
Debug Mode ของ Target ช่วยงานนี้ได้มาก
ox_target กับ ox_inventory Start Order
ถ้า ox_inventory เปิด Target Integration
ควรใช้
ensure oxmysql
ensure ox_lib
ensure framework
ensure ox_target
ensure ox_inventory
หาก ox_target ยังไม่ Start ตอน Inventory Initialize Inventory อาจปิด Target Integration พร้อม Warning
อย่า Restart ox_target กลาง Production แบบสุ่ม
Resources เช่น
ox_inventory
Jobs
Housing
Police
Garage
อาจ Register Zones/Targets ไว้กับ ox_target
การ Restart Target กลาง Session อาจทำให้ Registration State หายหรือ Resources ลูกต้อง Register ใหม่
Core Dependency Updates ควรทำใน Maintenance Window
ถ้าแก้ Job Script ต้อง Restart ox_target ไหม
ปกติไม่จำเป็น
ถ้าแก้
my_job
ให้
restart my_job
ก่อน
Resource ควร Cleanup Target ตอน Stop และ Register ใหม่ตอน Start
ไม่จำเป็นต้อง Restart ox_target ทุกครั้ง
Checklist ใช้ ox_target
Dependencies
ox_libติดตั้งox_libStart ก่อนVersion Compatible
ox_target
Folder ชื่อ
ox_targetfxmanifest.luaอยู่ RootResource Start สำเร็จ
F8 ไม่มี Critical Error
Config
setr ox_target:toggleHotkey 0
setr ox_target:defaultHotkey LMENU
setr ox_target:drawSprite 1
setr ox_target:defaults 1
setr ox_target:debug 0
setr ox_target:leftClick 1
ปรับตาม Server
Interaction
ทดสอบ
Ped
Player
Vehicle
Object
Zone
Conditions
ตรวจ
distance
groups
items
canInteract
Security
Server Validate
Job
Items
Permission
Position
State
Rewards
ซ้ำ
ตาราง Functions สำคัญของ ox_target
| Function | ใช้ทำอะไร |
|---|---|
addGlobalPed | Target NPC/Ped ทั่วไป |
addGlobalPlayer | Target Player |
addGlobalVehicle | Target รถทั้งหมด |
addGlobalObject | Target Objects |
addModel | Target Model ที่ระบุ |
addEntity | Target Networked Entity |
addLocalEntity | Target Local Entity |
addSphereZone | สร้าง Zone ทรงกลม |
addBoxZone | สร้าง Zone ทรงกล่อง |
addPolyZone | สร้าง Polygon Zone |
removeZone | ลบ Zone |
removeModel | ลบ Options จาก Model |
removeEntity | ลบ Options จาก Network Entity |
removeLocalEntity | ลบ Options จาก Local Entity |
disableTargeting | เปิด/ปิดความสามารถ Target |
ox_target เหมาะกับ Server แบบไหน
เหมาะมากกับ
Serious RP
Economy RP
Qbox
ESX
ox_core
OX-first Server
Custom FiveM Server
โดยเฉพาะ Server ที่ต้องการ Interaction แบบ
โลกเกมเป็น UI
แทนการใช้ Commands หรือ Markers จำนวนมาก
Server แบบไหนอาจไม่จำเป็นต้องใช้
ถ้าเป็น
Drift
Freeroam
Simple Racing
Deathmatch
ที่มี Interaction น้อย Target System อาจไม่จำเป็น
อย่าติดตั้ง Resource เพียงเพราะ Server อื่นใช้
ให้ติดตั้งเมื่อ Gameplay ต้องการมันจริง
ข้อดีของ ox_target
ข้อดีสำคัญ ได้แก่
Standalone
Entity Targeting
Zone Targeting
Model Targeting
Vehicle Bones
Groups
Items
Distance
canInteract
Sub-menus
Framework Integration
OX Inventory Integration
qtarget Compatibility
Config ผ่าน Convars
ทำให้สร้าง Interaction ได้ยืดหยุ่นมาก
ข้อควรระวังของ ox_target
สิ่งที่ควรระวัง ได้แก่
Dependency Version
Start Order
Target ซ้ำ
Zones ไม่ถูก Cleanup
canInteract หนักเกิน
Framework Groups ผิด
Item Integration ผิด
Client-side Security
Target System Migration
และอย่าแก้ Core เพียงเพื่อเพิ่ม Gameplay Logic ของ Job เดียว
ใช้ Public Exports/APIs แทน
สรุป ox_target คืออะไร ใช้งานอย่างไร
ox_target คือ Standalone Third-eye Targeting Resource สำหรับ FiveM ที่ช่วยให้ Player Interaction กับ
Peds
Players
Vehicles
Objects
Models
Entities
Zones
ได้โดยมองไปยังเป้าหมายแล้วเลือก Action
Current APIs มีทั้ง
addGlobalPed
addGlobalPlayer
addGlobalVehicle
addGlobalObject
addModel
addEntity
addLocalEntity
addSphereZone
addBoxZone
addPolyZone
และ TargetOption สามารถกำหนดเงื่อนไขอย่าง
distance
groups
items
bones
canInteract
พร้อม Action เช่น
onSelect
export
event
serverEvent
command
จึงเหมาะกับการสร้างระบบ Police, EMS, Garage, Shops, Businesses, Stashes, Crafting และ Vehicle Interactions
Current ox_target เป็น Standalone Resource แต่ต้องใช้ ox_lib และมี Framework Integration สำหรับ ox_core, ESX และ qbx_core ส่วน OX Inventory สามารถใช้ ox_target เป็น Optional Interaction Layer ได้
สิ่งที่สำคัญมากคือ ox_target ควรถูกมองเป็น UX/Interaction Layer ไม่ใช่ Security Layer การตั้ง
groups = 'police'
ช่วยซ่อน Option จาก Player ที่ไม่เกี่ยวข้อง แต่ Server Event ยังต้องตรวจ Job, Permission, Position และ State ซ้ำก่อนทำ Action สำคัญ
แนวทางของ comsiam คือใช้ groups, items, distance, bones และ canInteract เพื่อลด Options ที่ไม่เกี่ยวข้อง ทำให้ผู้เล่นเห็นเฉพาะ Interaction ที่สมเหตุสมผลในขณะนั้น แทนการใส่ทุก Action ลง Target Menu เดียว
สำหรับ Server ขนาดใหญ่ comsiam แนะนำให้ Custom Resources Register และ Remove Targets ของตัวเองอย่างเป็นระบบ ไม่แก้ ox_target Core โดยตรง และเปิด Debug Mode เฉพาะตอนพัฒนา วิธีนี้ช่วยให้ Update Target Resource ง่ายกว่าและลดปัญหา Target/Zone ซ้ำในระยะยาว
Comments
Post a Comment