Command API
ทุกอย่างที่คำสั่งเรียกใช้ได้อย่างปลอดภัยอยู่ใน CommandAPI:
local CommandAPI = require(script:FindFirstAncestor("HD Admin").Core.CommandAPI)
การโหลด¶
loadCommands Server¶
CommandAPI.loadCommands(details): Commands
โมดูลแพ็กใน Config > Commands ใช้ฟังก์ชันนี้โหลด ติดแท็ก และปรับชุดคำสั่งของตัวเอง ลองเปิดแพ็กไหนก็ได้ในนั้นเพื่อดูตัวอย่างการใช้งานจริง
พรอมต์¶
prompt Shared¶
-- In a server command module
CommandAPI.prompt(promptType: PromptType, player: Player, text: string, options: PromptOptions?): PromptHandle
-- In a client command module
CommandAPI.prompt(promptType: PromptType, text: string, options: PromptOptions?): PromptHandle
แสดงการแจ้งเตือน ข้อความ หรือการ์ด ถ้าต้องการพรอมต์แบบมีปุ่มกด ดูที่ bindPrompt
| ประเภทพรอมต์ | สิ่งที่แสดง |
|---|---|
"info" "success" "warn" "error" |
การแจ้งเตือนด้านข้างพร้อมเสียงเอฟเฟกต์ |
"message" |
ข้อความกลางหน้าจอ เช่นที่ใช้ใน ;message |
"hint" |
แถบเล็กๆ ด้านบนหน้าจอ เช่นที่ใช้ใน ;hint |
"privateMessage" |
การแจ้งเตือนด้านข้างที่ค้างอยู่ และเปิดข้อความเต็มเมื่อกด |
"alert" |
การแจ้งเตือนด้านข้างที่ค้างอยู่ เล่นเสียงวนจนกว่าจะปิดเสียง และเปิดข้อความเต็มเมื่อกด |
"action" |
การแจ้งเตือนด้านข้างที่มีปุ่มและตัวควบคุม สร้างได้ด้วย task:bindPrompt |
CommandAPI.prompt("success", task.caller, "Quest complete!", {duration = 5})
ฟังก์ชันนี้คืนค่าเป็น connection ที่เรียก connection:Disconnect() เพื่อจบพรอมต์ได้ เอาไปใส่ janitor ของงานก็ได้ พรอมต์จะจบทันทีที่คำสั่งจบ:
task.janitor:add(CommandAPI.prompt("hint", task.target, "You're frozen until an admin releases you", {duration = 0})) -- 0 means "infinite"
ตัวเลือก
ทุกตัวเลือกเป็นของเสริม และใช้ได้กับพรอมต์ทุกประเภท ยกเว้นแถวนั้นจะบอกไว้:
| ตัวเลือก | ชนิด | ทำหน้าที่อะไร |
|---|---|---|
title |
string | หัวข้อเหนือข้อความ privateMessage และ alert ตั้งเอง |
duration |
number | จำนวนวินาทีก่อนที่พรอมต์จะปิดเอง ถ้าไม่ใส่ จะคำนวณจากความยาวข้อความ 0 คือให้อยู่บนหน้าจอจนกว่าจะถูกปิดหรือ disconnect |
subtext |
string | บรรทัดเล็กๆ ใต้ข้อความ |
icon |
string | รูป rbxassetid:// ที่มาแทนไอคอนของการแจ้งเตือน |
color |
Color3 | เปลี่ยนสีข้อความของ hint |
dismissable |
boolean | false ซ่อนปุ่มปิด ทำให้ปิดได้แค่ด้วย duration หรือ handle เท่านั้น |
openPage |
string | กดที่การแจ้งเตือนแล้วเปิดแผงควบคุมไปที่หน้านี้ เช่น "Commands", "Roles", "Settings" หรือ "About" |
openProfile |
boolean | กดที่การแจ้งเตือนแล้วเปิดโปรไฟล์ของผู้เล่นคนนั้นเอง |
openImage |
table | {image = "rbxassetid://...", title = "Map", ratio = 16/9} กดที่การแจ้งเตือนแล้วเปิดรูปกลางหน้าจอ |
linkButtons |
table | ปุ่มเล็กๆ ที่ท้ายการแจ้งเตือน {label = "Roles", page = "Roles"} เปิดหน้าหนึ่ง และ {label = "Profile", profile = true} เปิดโปรไฟล์ของเขา ใส่ style = "Neutral" เพื่อให้ปุ่มดูจางลง และ hideAfterPress = true เพื่อปิดการแจ้งเตือนหลังกดปุ่ม ถ้าเรียกจาก LocalScript ผ่าน Client API ใช้ {label = "Shop", onActivate = function() ... end, icon = "rbxassetid://..."} เพื่อรันฟังก์ชันของคุณเองแทนได้ |
roleBadges |
table | ป้ายบทบาทใต้หัวข้อ {{name = "Admin", color = Color3.fromRGB(255, 170, 0)}} |
countdown |
number | นับถอยหลังสดๆ จากจำนวนวินาทีนี้ ตรงที่มี %TIME% อยู่ในข้อความ |
fromUserId |
number | แสดงรูปอวาตาร์ ชื่อ และบทบาทสูงสุดของผู้ใช้คนนั้นในฐานะผู้ส่ง message, privateMessage หรือ alert |
userText |
boolean | แสดงข้อความตามที่เขียนไว้เป๊ะๆ โดยไม่ตีความแท็ก rich text เป็นต้น |
CommandAPI.prompt("info", task.caller, "You've unlocked the VIP role", {
title = "New role",
openPage = "Roles",
roleBadges = {{name = "VIP", color = Color3.fromRGB(255, 170, 0)}},
})
ถ้าต้องการพรอมต์แบบมีปุ่มกด ดูที่ bindPrompt
ตัวละคร¶
getHumanoid Shared¶
CommandAPI.getHumanoid(player: Player?): Humanoid?
Humanoid ของผู้เล่น หรือ nil ถ้าตัวละครยังไม่อยู่ในเกม
getHRP Shared¶
CommandAPI.getHRP(player: Player?): BasePart?
HumanoidRootPart ของผู้เล่น หรือ nil
getHead Shared¶
CommandAPI.getHead(player: Player?): (BasePart?, Model?)
Head ของผู้เล่นและตัวละครของเขา หรือ nil
getNeck Shared¶
CommandAPI.getNeck(player: Player?): Motor6D?
ข้อต่อคอของผู้เล่น หรือ nil ใช้ได้ทั้งโครง R6 และ R15
getTorso Shared¶
CommandAPI.getTorso(player: Player?): Instance?
ลำตัวของผู้เล่น หรือ nil ใช้ได้ทั้งโครง R6 และ R15
loadCharacter Server¶
CommandAPI.loadCharacter(player: Player?)
รีสปอว์นตัวละครของผู้เล่น ให้ใช้ฟังก์ชันนี้แทน player:LoadCharacter() เสมอ เพื่อให้งานของ HD Admin รู้ว่าการรีสปอว์นครั้งนี้ตั้งใจทำ
ผู้เล่น¶
getUserInfoAsync Shared¶
CommandAPI.getUserInfoAsync(userId: number | string): (boolean, UserInfo | string)
คืนค่า true กับ UserInfo ของผู้ใช้คนไหนก็ได้ แม้จะออฟไลน์อยู่ หรือคืน false กับเหตุผล ผลลัพธ์ถูกแคชไว้ เรียกซ้ำจึงไม่เสียอะไรเพิ่ม
getNameFromUserIdAsync Shared¶
CommandAPI.getNameFromUserIdAsync(userId: number | string): (boolean, string)
คืนค่า true กับชื่อของผู้ใช้ หรือ false กับเหตุผล ใช้ได้กับผู้ใช้ที่ออฟไลน์
teleportAsync Server¶
CommandAPI.teleportAsync(player: Player?, cframe: CFrame): (boolean, string)
ย้ายตัวละครของผู้เล่นไปที่ CFrame ที่ระบุ โดยให้ลุกจากที่นั่งก่อน เพื่อไม่ให้ลากที่นั่งตามไปด้วย
getAllowedTargets Server¶
CommandAPI.getAllowedTargets(task: Task, options: {players: {Player}?}?): ({Player}, {Player})
ผู้เล่นที่คำสั่งใช้กับได้ โดยค่าเริ่มต้นคือทุกคนในเซิร์ฟเวอร์ ยกเว้น คนที่เปิด Block commands ไว้ใน You Settings
unequipTools Server¶
CommandAPI.unequipTools(player: Player?): (boolean, string)
เก็บเครื่องมือที่ผู้เล่นถืออยู่กลับเข้ากระเป๋า
งาน¶
getTasks Shared¶
CommandAPI.getTasks(commandKey: string?, targetUserId: number?): {Task}
คืนงานที่กำลังทำงานอยู่ จะกรองตามคำสั่งและเป้าหมายก็ได้ งานเหล่านี้คืออ็อบเจกต์เดียวกับที่ API ของงาน อธิบายไว้
getTasksByCallerId Shared¶
CommandAPI.getTasksByCallerId(callerUserId: number): {Task}
งานทั้งหมดที่กำลังทำงานอยู่และเริ่มโดยผู้สั่งคนนั้น
แชท¶
systemMessage Shared¶
-- In a server command module
CommandAPI.systemMessage(player: Player, text: string)
-- In a client command module
CommandAPI.systemMessage(text: string)
ส่งข้อความสไตล์ระบบเข้าไปในแชทของผู้เล่น
checkTextLimit Server¶
CommandAPI.checkTextLimit(task: Task, textKind: "Message" | "SurfaceText" | "ChatText" | "Reason"): (boolean, number?)
HD Admin จำกัดการส่งฟีเจอร์ที่เกี่ยวกับข้อความ ตามนโยบายความปลอดภัยด้านอายุของ Roblox ฟังก์ชันนี้ใช้เช็กเวลาคูลดาวน์ตรงนั้น
คืนค่า true เมื่อแสดงข้อความได้ ไม่เช่นนั้นคืน false พร้อมเวลาคูลดาวน์ที่เหลือ
args = {"Player", "Leaderstat", {arg = "String", textSurface = "None"}},
run = function(task)
local stat = task:getArg("Leaderstat")
local text = task:getArg("String")
if stat:IsA("StringValue") then
if not CommandAPI.checkTextLimit(task, "SurfaceText") then
return
end
end
stat.Value = text
end,
| ประเภท | ใช้ร่วมกันโดย |
|---|---|
"Message" |
ข้อความ hint การแจ้งเตือน alert ข้อความส่วนตัว และโพล |
"SurfaceText" |
ชื่อ ตำแหน่ง ชื่อทีม และสถิติ |
"ChatText" |
แท็กแชทและชื่อในแชท |
"Reason" |
เหตุผลของการเตะและแบน |
forceBubbleChat Shared¶
CommandAPI.forceBubbleChat(target: Player | Model, text: string)
แสดงบับเบิลแชทเหนือตัวละครของผู้เล่น หรือเหนือโมเดลหรือพาร์ตที่คุณส่งเข้าไปแทน
ชุดแต่งตัว¶
getDescription Server¶
CommandAPI.getDescription(humanoid: Humanoid): HumanoidDescription
HumanoidDescription ปัจจุบันของ humanoid
applyDescription Server¶
CommandAPI.applyDescription(humanoid: Humanoid?, description: HumanoidDescription?, properties: {[string]: any}?): HumanoidDescription?
ใส่ HumanoidDescription อย่างปลอดภัย และลองใหม่ถ้า Roblox ปฏิเสธในครั้งแรก ส่ง properties เข้าไปเพื่อปรับบางฟิลด์ทับบน description ตั้งต้น
outfitBuff Server¶
CommandAPI.outfitBuff(target: Player, properties: {[string]: any})
ใส่ค่า HumanoidDescription เป็นบัฟที่ย้อนกลับเองเมื่องานจบ คำสั่งอย่าง ;wormify จึงเก็บกวาดตัวเองได้
setFakeBodyParts Server¶
CommandAPI.setFakeBodyParts(character: Model, info: {[string]: any}): (() -> ())?
สลับส่วนของร่างกายเป็นของปลอมที่คำสั่งสร้างขึ้น และคืนฟังก์ชันที่ใช้ใส่ของเดิมกลับ
clearFakeBodyParts Server¶
CommandAPI.clearFakeBodyParts(character: Model)
เอาส่วนของปลอมเหล่านั้นออกอีกครั้ง
runBundleId Server¶
CommandAPI.runBundleId(task: Task, bundleId: number, properties: {[string]: any}?)
แต่งตัวเป้าหมายของงานด้วยบันเดิลจากแคตตาล็อก และคืนชุดเดิมของเขาเมื่องานจบ
แอสเซ็ต¶
registerSound Shared¶
CommandAPI.registerSound(sound: Sound)
ต้องเรียกกับ Sound ทุกอันที่คำสั่งของคุณสร้างขึ้น เพื่อให้การตั้งค่าระดับเสียงและพิทช์ของเกมมีผลกับเสียงนั้น
setAnchored Shared¶
CommandAPI.setAnchored(instance: Instance, anchored: boolean)
ล็อกหรือปลดล็อกทุกพาร์ตที่อยู่ใต้ instance นั้น
setTransparency Shared¶
CommandAPI.setTransparency(instance: Instance, transparency: number)
ปรับความโปร่งใสของทุกพาร์ตที่อยู่ใต้ instance นั้น
promptPurchaseAsync Server¶
CommandAPI.promptPurchaseAsync(assetId: number, player: Player?, infoType: Enum.InfoType?)
เปิดหน้าต่างให้ผู้เล่นซื้อแอสเซ็ต โดยเลือกขั้นตอนการซื้อที่ถูกต้องตามประเภทของแอสเซ็ต
ownsAssetAsync Server¶
CommandAPI.ownsAssetAsync(assetId: number, player: Player?): boolean
เช็กว่าผู้เล่นเป็นเจ้าของแอสเซ็ตนี้หรือไม่
isTypeAsync Server¶
CommandAPI.isTypeAsync(assetId: number, assetType: Enum.AssetType | Enum.BundleType): (boolean, string?)
ตรวจว่าแอสเซ็ตเป็นประเภทที่ระบุหรือไม่ คืน true หรือคืน false พร้อมเหตุผล
loadAssetCommand Server¶
CommandAPI.loadAssetCommand(assetType: Enum.AssetType, task: Task, assetId: number, callback: (item: Instance) -> ())
ตรวจว่าแอสเซ็ตเป็นประเภทที่ระบุและได้รับอนุญาต แล้วแทรกเข้ามา จากนั้นส่งให้ callback ของคุณเอาไปวาง คำสั่ง ;gear ใช้ฟังก์ชันนี้
getToolsInfoAsync Server¶
CommandAPI.getToolsInfoAsync(): (boolean, {ToolInfo} | string)
คืนค่า true กับ ToolInfo ของทุกเครื่องมือที่ ;give ใช้ได้ หรือคืน false กับเหตุผล
ยูทิลิตี¶
getTargets Server¶
CommandAPI.getTargets(targetType: "All" | "Others" | "Nearby" | "OthersNearby", originPlayer: Player?, radius: number?): {Player}
แปลงตัวกำหนดเป้าหมายเป็นผู้เล่นที่ครอบคลุมอยู่ ณ ตอนนั้น "Nearby" และ "OthersNearby" วัดระยะจากผู้เล่นต้นทาง โดยใช้ radius เป็นหน่วย stud (ค่าเริ่มต้นคือ 50)
setCameraSubject Client¶
CommandAPI.setCameraSubject(newSubject: Instance)
หันกล้องของผู้เล่นในเครื่องไปที่เป้าหมายใหม่ เช่น Humanoid ของผู้เล่นอีกคนสำหรับ ;view
runPromptCommand Server¶
CommandAPI.runPromptCommand(promptType: PromptType, task: Task, targets: {Player}, text: string, options: PromptOptions?)
ตัวขับเคลื่อนเบื้องหลัง ;message, ;hint และพรอมต์แบบเดียวกัน มันกรองข้อความ แสดงพรอมต์ให้เป้าหมายทุกคน และให้งานยังทำงานอยู่จนกว่าพรอมต์จะหมดเวลา
runEmoteId Server¶
CommandAPI.runEmoteId(task: Task, emoteId: number, speed: number?, looped: boolean?)
เล่นแอนิเมชันอีโมตกับเป้าหมายของงาน และหยุดเมื่องานจบ
createEmoteCommand Server¶
CommandAPI.createEmoteCommand(emoteName: string, emoteId: number, properties: {[string]: any}?): Command
คืนคำสั่งอีโมตที่สมบูรณ์ พร้อมใส่ลงในอาร์เรย์คำสั่งของคุณ properties ใช้เขียนทับฟิลด์ไหนก็ได้ของคำสั่งที่สร้างขึ้น
createBundleCommand Server¶
CommandAPI.createBundleCommand(commandName: string, bundleId: number, properties: {[string]: any}?): Command
ทำงานแบบเดียวกัน แต่สำหรับคำสั่งบันเดิลอย่าง ;ratdance
bindEmotePrompt Server¶
CommandAPI.bindEmotePrompt(task: Task, target: Player, emoteId: number, emoteName: string?, isLooped: boolean?)
ผูกการ์ดอีโมตเข้ากับงาน เพื่อให้เป้าหมายกดบันทึกอีโมตเป็นรายการโปรดหรือดูในแคตตาล็อกได้
openProfile Server¶
CommandAPI.openProfile(player: Player?, userId: number)
เปิดป็อปอัปโปรไฟล์ของผู้ใช้ที่ระบุให้ผู้เล่นดู
openPage Server¶
CommandAPI.openPage(player: Player?, pageId: string, tabLabel: string?)
เปิดแผงควบคุมของผู้เล่นตรงไปที่หน้าที่ระบุ และจะเปิดไปที่แท็บใดแท็บหนึ่งของหน้านั้นก็ได้
openEmotes Server¶
CommandAPI.openEmotes(player: Player?)
เปิดป็อปอัปอีโมตให้ผู้เล่น
colourRoleName Shared¶
CommandAPI.colourRoleName(role): string
ชื่อบทบาทที่ห่อด้วยสีของบทบาทนั้น สำหรับใช้กับ rich text
isTableEmpty Shared¶
CommandAPI.isTableEmpty(tbl: {[any]: any}): boolean
เช็กว่าตารางไม่มีสมาชิกเลยหรือไม่ รวมถึงสมาชิกที่ใช้คีย์ ซึ่ง #tbl นับไม่เจอ
round Shared¶
CommandAPI.round(number: number, decimalPlaces: number?): number
ปัดเลขตามจำนวนทศนิยมที่ระบุ ถ้าไม่ระบุจะปัดเป็นจำนวนเต็ม
ชนิดข้อมูล¶
Commands¶
type Commands = {Command}
อาร์เรย์ที่โมดูลคำสั่งคืนออกมา
Command¶
ตารางคำสั่งหนึ่งรายการใน Commands (name, args, run และอื่นๆ) ดูฟิลด์ทั้งหมดได้ที่ คำสั่งกำหนดเอง
Task¶
อ็อบเจกต์งานที่ส่งเข้าฟังก์ชัน run ทุกตัว อธิบายครบทุกอย่างอยู่ใน API ของงาน
ClientCommands¶
ฝั่งไคลเอนต์ที่เทียบเท่ากับ Commands โมดูล Client เป็นตัวคืนค่านี้
ClientCommand¶
ตารางคำสั่งฝั่งไคลเอนต์หนึ่งรายการใน ClientCommands
UserInfo¶
type UserInfo = {
userId: number | string,
userName: string,
userImage: string,
userDisplayName: string,
userTopRole: {key: string, name: string, color: Color3}?,
}
userTopRole จะมีเฉพาะผู้เล่นที่อยู่ในเซิร์ฟเวอร์นี้
ToolInfo¶
type ToolInfo = {
name: string,
textureId: string,
tool: Tool?,
}
PromptType¶
type PromptType = "info" | "success" | "warn" | "error" | "message" | "hint" | "privateMessage" | "alert" | "vote" | "voteResults" | "action"
สตริงประเภทพรอมต์ ดูว่าแต่ละอันแสดงอะไรได้ที่ prompt
PromptOptions¶
ตารางตัวเลือกที่ prompt รับ ดูรายการทั้งหมดได้ที่ prompt
PromptHandle¶
handle ที่ prompt คืนมา ใช้ handle:Disconnect() เพื่อปิดพรอมต์ก่อนเวลา