Commands (Server-side)
Commands
onExecuted
ทำงานเมื่อดำเนินการใช้คำสั่งเสร็จสิ้นแล้ว
บรรทัดที่ 29
function Commands.onExecuted(source, command, success, response)
local client <const> = (source > 0 and source or nil)
if success then
return respHandler[command.key](client, response)
elseif client then
return Commands.sendClientMessage(client, false, ("Failed to execute command '^3%s^7': ^1%s^7."):format(command.raw, response.message))
end
print(("[^1ERROR^7] Failed to execute command '^3%s^7': ^1%s^7."):format(command.raw, response.message))
end
Parameters
- source:
integer- Net ID ของผู้เล่นที่ใช้คำสั่ง หรือ
0หากใช้คำสั่งที่ Server Console
- Net ID ของผู้เล่นที่ใช้คำสั่ง หรือ
- command:
table<{ [key]: any }>- ข้อมูลของคำสั่งที่ใช้งาน (ดูรายละเอียดด้านล่าง)
- success:
boolean- สถานะการใช้งานคำสั่ง
- response:
table<{ [key]: any }>- ข้อมูลตอบกลับของคำสั่ง (ดูรายละเอียดด้านล่าง)
- command
- response
| Field | Type | Description |
|---|---|---|
key | string | คีย์ของคำสั่ง |
name | string | ชื่อของคำสั่ง |
raw | string | ข้อมูลของคำสั่งที่ใช้ |
args | table<{ [index]: string }> | ข้อมูลอาร์กิวเมนต์ของคำสั่งที่ใช้ |
Success
ข้อมูลตอบกลับเมื่อใช้คำสั่งสำเร็จ คุณสามารถดูรายละเอียดได้ที่ respHandler
Failed
ข้อมูลตอบกลับเมื่อใช้คำสั่งล้มเหลว
| Field | Type | Description |
|---|---|---|
type | string | ประเภทของข้อผิดพลาด |
message | string | ข้อความของข้อผิดพลาด |
sendClientMessage
ส่งข้อความไปยังฝั่งไคลเอนต์เมื่อใช้คำสั่งเสร็จสิ้นแล้ว
บรรทัดที่ 18
function Commands.sendClientMessage(client, success, message)
TriggerClientEvent('chat:addMessage', client, {
multiline = true, color = success and { 0, 255, 0 } or { 255, 0, 0 }, args = { '»', message }
})
end
Parameters
- client:
integer- Net ID ของผู้เล่นที่ใช้คำสั่ง
- success:
boolean- สถานะการใช้งานคำสั่ง
- message:
string- ข้อความตอบกลับจากการใช้คำสั่งที่จะส่งไปยังฝั่ง Client
respHandler
จัดการข้อมูลการตอบกลับเมื่อใช้คำสั่งสำเร็จ โดยจะถูกเรียกใช้งานจากฟังก์ชัน onExecuted
addBypass
ทำงานเมื่อใช้คำสั่ง "เพิ่มสิทธิ์ข้ามกฎการตรวจสอบ" สำเร็จ
บรรทัดที่ 44
function respHandler.addBypass(client, resp)
local bypassTypes <const> = {}
for _, bypassType in ipairs(resp.bypassTypes) do
bypassTypes[#bypassTypes + 1] = ('^2%s^7'):format(bypassType)
end
local message <const> = ("[^2INFO^7] Successfully added bypass for identifier '^5%s^7'\n[^2INFO^7] Bypass Types: %s")
:format(resp.identifier, table.concat(bypassTypes, ', '))
if client then
return Commands.sendClientMessage(client, true, message)
end
print(message)
end
Parameters
- client:
integer|nil- Net ID ของผู้เล่น หรือ
nilหากใช้คำสั่งที่ Server Console
- Net ID ของผู้เล่น หรือ
- resp:
table<{ [key]: any }>- ข้อมูลตอบกลับของคำสั่ง
- identifier:
string- ตัวระบุของผู้เล่น
- bypassTypes:
string[]- ประเภทของ bypass ที่ถูกเพิ่ม
- identifier:
- ข้อมูลตอบกลับของคำสั่ง
removeBypass
ทำงานเมื่อใช้คำสั่ง "ลบสิทธิ์ข้ามกฎการตรวจสอบ" สำเร็จ
บรรทัดที่ 64
function respHandler.removeBypass(client, resp)
local bypassTypes <const> = {}
for _, bypassType in ipairs(resp.bypassTypes) do
bypassTypes[#bypassTypes + 1] = ('^1%s^7'):format(bypassType)
end
local message <const> = ("[^2INFO^7] Successfully removed bypass for identifier '^5%s^7'\n[^2INFO^7] Removed Bypass Types: %s")
:format(resp.identifier, table.concat(bypassTypes, ', '))
if client then
return Commands.sendClientMessage(client, true, message)
end
print(message)
end
Parameters
- client:
integer|nil- Net ID ของผู้เล่น หรือ
nilหากใช้คำสั่งที่ Server Console
- Net ID ของผู้เล่น หรือ
- resp:
table<{ [key]: any }>- ข้อมูลตอบกลับของคำสั่ง
- identifier:
string- ตัวระบุของผู้เล่น
- bypassTypes:
string[]- ประเภทของ bypass ที่ถูกลบออก
- identifier:
- ข้อมูลตอบกลับของคำสั่ง