คําสั่งผู้ดูแลระบบ เป็นคําหรือวลีที่ผู้ใช้ที่มีระดับการควบคุมบางอย่างสามารถพิมพ์ลงในหน้าต่างแชทเพื่อกระตุ้นการดําเนินการ ไลบรารีนี้ใช้โมดูลแชทซึ่งช่วยให้สามารถใช้งานคำสั่งผู้ดูแลระบบได้ง่ายบนระบบแชทเก่าได้โมดูลแชทฟังข้อความที่เข้ามาบนเซิร์ฟเวอร์และสามารถดำเนินการตามเกณฑ์ที่ต้องการได้
การตั้งค่า
ทุกครั้งที่สถานที่ Roblox โหลดจะตรวจสอบว่าบริการแชทว่างเปล่าหรือไม่หากไม่พบส่วนประกอบที่ต้องการ สถานที่จะใส่เวอร์ชันล่าสุดของส่วนประกอบเหล่านั้นซึ่งหมายความว่าการเขียนทับหรือทำการเปลี่ยนแปลงส่วนประกอบเหล่านี้ในประสบการณ์จะป้องกันไม่ให้พวกเขาได้รับการอัปเดต
ขั้นตอนแรกในการตั้งค่าคลังคำสั่งผู้ดูแลระบบคือการเพิ่มโมดูลแชทใหม่ในบริการแชทห้องสมุดในบทแนะนำนี้ดูแลการยกของหนักที่ดำเนินการโดยโมดูลแชทดังนั้นวัตถุเดียวที่คุณต้องเพิ่มในบริการแชทคือ ModuleScript ใหม่ชื่อของสคริปต์โมดูลของคุณสามารถเป็นอะไรก็ได้ แต่ฉันขอแนะนำบางอย่างที่เข้าใจได้เช่น AdminCommands
ใช้คำสั่งใหม่
แทนที่จะใช้โลจิสต์ส่วนใหญ่ของโมดูลแชทคุณจะต้องการโมดูลไลบรารีที่ทำงานจํานวนมากและเพิ่มฟังก์ชันเพิ่มเติมเท่านั้นวิธีที่ง่ายที่สุดในการเพิ่มไลบรารีในโมดูลของคุณคือการต้องการโดย assetId ที่ด้านบนของสคริปต์ของคุณ
local AdminCommands = require(1163352238)
โมดูลนี้ส่งคืนตารางฟังก์ชันที่มีฟังก์ชัน Run เป็นฟังก์ชันที่สำคัญที่สุดห้องสมุดมีฟังก์ชัน Run สำหรับโมดูลแชทของมันเป็นสิ่งสำคัญที่คำสั่งของผู้ดูแลระบบจะส่งฟังก์ชันนี้ Run กลับไปยังบริการแชทฟังก์ชันจะถูกจัดเรียงตามชื่อของมัน, Run , และคุณสามารถส่งคืนสิ่งต่อไปนี้ได้เหมือนกับว่า Run เป็นคุณสมบัติของตารางการแสดงผล AdminCommands ของเรา:
return AdminCommands.Run
รหัสให้ดำเนินการตามคำสั่งของคุณเองและฟังก์ชันช่วยเหลือที่จำเป็นใดๆ
เพื่อผูกฟังก์ชันกับไลบรารีใช้ฟังก์ชัน BindCommand ของ AdminCommands .เมื่อผูกคำสั่งคุณจะต้องระบุตารางคำหลักที่เมื่อพูดจะกระตุ้นคำสั่ง ฟังก์ชันที่จะถูกกระตุ้น ระดับความสำคัญ และตัวเลือกที่อาจเป็นคำอธิบายของคำสั่งหากคุณไม่ระบุระดับสิทธิ์จะเริ่มต้นที่ 0ระดับลําดับความสําคัญเป็นตัวเลขที่ใช้โดยไลบรารี AdminCommands เพื่อกําหนดลําดับการอนุญาตระหว่างผู้ใช้ที่มีระดับสิทธิ์ที่เทียบเท่ากันเมื่อดำเนินการตามคำสั่ง ผู้พูดจะต้องมีระดับสิทธิ์ที่สูงกว่าหรือเท่ากับคำสั่ง ไลบรารีสิทธิ์การอนุญาต
AdminCommands:BindCommand({"keyword1", "keyword2"}, commandName, 1, "Optional description")
เพื่อยกเลิกการผูกคุณจะใช้ UnbindCommand และระบุคีย์เพื่อยกเลิก
AdminCommands:UnbindCommand({"keyword1"})
โดยรวมแล้ว กำลังติดตาม:
local AdminCommands = require(1163352238)
local Utilities = AdminCommands.Utilities
function commandFunction(commandData)
-- รหัสคอมมานด์ที่นี่
-- ส่งคืนจริงหากสําเร็จและปลอมหากไม่สําเร็จ
end
AdminCommands:BindCommand({"keyword1", "keyword2"}, commandFunction, 1, "Optional description")
return AdminCommands.Run
คุณอาจสังเกตเห็นว่าฟังก์ชันตัวอย่างใช้พารามิเตอร์ชื่อ commandDataพารามิเตอร์นี้เป็นอาร์กิวเมนต์ตารางที่ส่งไปยังฟังก์ชันคำสั่งผู้ดูแลระบบทั้งหมดเมื่อดำเนินการโดยไลบรารีตารางมีข้อมูลที่มีประโยชน์เกี่ยวกับคำสั่งที่พูดและผู้ใช้ที่พูดมันมันมีฟิลด์ต่อไปนี้:
- ลำโพง: ChatSpeaker
- ข้อความ: string
- ชื่อช่อง: string
- คําสั่ง: string
เป็นสิ่งสำคัญที่ต้องคาดหวังเสมอ commandData เป็นพารามิเตอร์ของฟังก์ชันคำสั่งตัวอย่างเช่น หากคุณมีคำสั่งที่ชื่อว่า "explode" ซึ่งต้องการให้มีพารามิเตอร์ Player เพื่อระบุ ฟังก์ชันจะมีลักษณะเช่น explode(commandData, user)
| ฟังก์ชัน | พารามิเตอร์ | การคืน | | --------------- | ------------------------------------------------------------------------------------------------ | ------ | | คําสั่ง: | table functionIDs, function functionToExecute, number minimumPermissionLevel, string description | bool | | UnbindCommand() | table functionIDs | bool | | GetCommands() | table |
ความสามารถ
ห้องสมุดมีฟังก์ชันช่วยเหลือที่ติดตั้งไว้แล้วไม่กี่ฟังก์ชันที่เรียกว่า Utilities ที่คุณสามารถใช้ได้บันทึกคำสั่งผู้ดูแลระบบ.Utilities ในตัวแปรหรืออ้างอิงโดยตรง
local Utilities = AdminCommands.Utilities
ฟังก์ชันความสามารถปัจจุบันคือ:
| ฟังก์ชัน | พารามิเตอร์ | กลับ | | -------------------------- | -------------------------------------------------- | ------ | | ข้อความหน้าต่างแชท: | | | | SendSystemMessage() | table commandData, string content, table extraData | bool | | SendSystemSuccessMessage() | table commandData, string content | bool | | SendSystemWarningMessage() | table commandData, string content | bool | | เฮนเดอร์ข้อผิดพลาด: | | | | NoPlayerSpecified() | table commandData | bool | | IncorrectValueType() | table commandData, string given, string expected | | | การแปลงข้อมูล: | | | | ToTupple(parameter) | string parameter | array | | ToBoolean() | string parameter | bool | | ValidateData() | string expectedType, ... | ก้อน |
คําสั่งตัวอย่าง
คำสั่งที่มีประโยชน์ที่จะมีคือคำสั่งที่พิมพ์รายการของคำสั่งทั้งหมดที่ผู้ใช้มีอยู่คำสั่งนี้จะออกคำสั่งที่ผูกกับไลบรารีและคุณสมบัติไม่กี่ของมัน
-- พิมพ์รายการของคำสั่งทั้งหมดที่ผูกไว้
function listCommand(commandData)
Utilities:SendSystemMessage(commandData, "The following commands are available:")
-- ทำซ้ำผ่านทุกคำสั่งและพิมพ์ออก
for id, command in PublicAPI:GetCommands() do
Utilities:SendSystemMessage(commandData, string.format("%* requires permission %*.", id, command.Permission))
end
return true
end
AdminCommands:BindCommand({"list"}, listCommand, 0, "Prints a list of commands.")
คำสั่งที่มีประโยชน์อีกคือสามารถให้ผู้ใช้ส่องแสงกับตัวเองได้คำสั่งนี้ต้องการพารามิเตอร์หนึ่งเมื่อพูด - ชื่อผู้ใช้เป้าหมายหากผู้ใช้มีอยู่ คำสั่งจะสร้างวัตถุ Sparkles ใน HumanoidRootPart ของผู้ใช้นั้น
-- ให้ประกายตัวของผู้เล่นที่กำหนดไว้
function sparklesCommand(commandData)
-- ข้อผิดพลาดถ้าไม่มีพารามิเตอร์ที่ให้/พูดคุย
if #commandData.Parameters == 0 then
return Utilities:NoPlayerSpecified(commandData)
end
-- ผ่านพารามิเตอร์ (ดำเนินการตามชื่อผู้เล่นที่กำหนดให้ทุกคน)
for index = 1, #commandData.Parameters do
local parameter = commandData.Parameters[index]
if (parameter == "me" or parameter == "") then parameter = commandData.Speaker.Name end -- หากพารามิเตอร์เป็นฉันแล้วผู้ใช้ต้องอ้างถึงตัวเอง
-- ใช้ฟังก์ชันช่วยเหลือเพื่อค้นหาตัวละครของผู้เล่นและเพิ่มประกาย
local character = Utilities:GetCharacter(parameter)
if character then
local sparkles = Instance.new("Sparkles")
sparkles.Parent = character:FindFirstChild("HumanoidRootPart")
Utilities:SendSystemSuccessMessage(commandData, string.format(commandData.Speaker.Name .. "added sparkles to " .. parameter))
else
Utilities:SendSystemErrorMessage(commandData, string.format("%* is not a valid player.", parameter))
return false
end
end
return true
end
AdminCommands:BindCommand({"sparkles"}, sparklesCommand, 1, "Gives the specified player sparkles")
คุณยังสามารถรวมคำสั่งระเบิดจากบทแนะนำการสร้างคอมมานด์ผู้ดูแลระบบ คำสั่งนี้ยังใช้ชื่อผู้ใช้เป็นพารามิเตอร์
-- ตรวจสอบว่าโมเดลที่กำหนดเป็นตัวละครและเพิ่มการระเบิดให้กับส่วนรากมนุษย์ของมัน
local function makeExplosion(character)
if character and character:FindFirstChild("HumanoidRootPart") then
local explosion = Instance.new("Explosion")
explosion.Position = character.HumanoidRootPart.Position
explosion.Parent = character.HumanoidRootPart
return true
end
return false
end
-- ทำให้ตัวละครของผู้เล่นที่กำหนดระเบิด
function explodeCommand(commandData)
-- ข้อผิดพลาดถ้าไม่มีพารามิเตอร์ที่ให้/พูดคุย
if #commandData.Parameters == 0 then
return Utilities:NoPlayerSpecified(commandData)
end
for index = 1, #commandData.Parameters do
local parameter = tostring(commandData.Parameters[index])
if (parameter == "me" or parameter == "") then parameter = commandData.Speaker.Name end -- หากพารามิเตอร์เป็นฉันแล้วผู้ใช้ต้องอ้างถึงตัวเอง
-- ใช้ฟังก์ชันช่วยค้นหาตัวละครของผู้เล่นและเพิ่มการระเบิด
local character = Utilities:GetCharacter(parameter)
local success = makeExplosion(character)
if success then
Utilities:sendSystemSuccessMessage(commandData, string.format(commandData.Speaker.Name .. " made" .. parameter .. " explode."))
else
Utilities:SendSystemErrorMessage(commandData, string.format("%* is not a valid player.", parameter))
return false
end
end
return true
end
AdminCommands:BindCommand({"explode"}, explodeCommand, 1, "Makes the specified player explode.")
ห้องสมุดสิทธิ์
หากผู้ใช้ที่ไม่ใช่ผู้ดูแลระบบพยายามพูดคำสั่งเช่นนี้ซึ่งมีระดับสิทธิ์สูงกว่า 0 จะไม่ถูกกระตุ้นระบบคำสั่งใช้ห้องสมุดสิทธิ์แยกต่างหากซึ่งผู้สร้างประสบการณ์จะได้รับสิทธิ์ระดับคณิตศาสตร์ที่สำคัญอัตโนมัติผู้ดูแลระบบสามารถเพิ่มได้โดยใช้ฟังก์ชันต่อไปนี้บนวัตถุโมดูล AdminCommands:
SetUserPermission(number requesterUserId, number targetUserId, permissionLevel) -> boolSetGroupRankPermission(number requesterUserId, number targetGroupId, number targetRankId, permissionLevel) -> bool
| ฟังก์ชัน | พารามิเตอร์ | การคืน | | ---------------------------- | ---------------------------------------------------------------------------------- | ------ | | สิทธิ์ | | | | GetAdmins() | | ตาราง | | SetUserPermission() | number requesterUserId, number targetUserId, permissionLevel | bool | | GetUserPermission() | number userId | number | | GetGroups() | | ตาราง | | SetGroupRankPermission() | number requesterUserId, number targetGroupId, number targetRankId, permissionLevel | bool | | GetGroupRankPermission() | targetGroupId, targetRankId | int |
โมดูลเริ่มต้นอย่างรวดเร็ว
สำหรับการติดตั้งที่ง่ายขึ้นคุณสามารถใช้สิ่งนี้ เริ่มต้นอย่างรวดเร็ว ซึ่งเป็นโมดูลที่มีการใช้งานไลบรารีคำสั่งผู้ดูแลแล้วโมเดลเป็นโมดูลที่มีรูปแบบเดียวกับที่อธิบายไว้ข้างต้นนอกจากนี้โมดูลมีคำสั่งไม่กี่คำสั่งที่รวมอยู่แล้วเพื่อให้คุณไม่ต้องทำซ้ำ
| คําสั่ง/การผูก | พารามิเตอร์ที่พูด | | -------------------------------- | -------------------------------- | | "list", "commands" | ชื่อผู้ใช้ | | "sparkles" | ชื่อผู้ใช้ | | "sparkles" | ชื่อผู้ใช้ | | "unforcefield", "unff" | ชื่อผู้ใช้ | | "explode" | ชื่อผู้ใช้ | | "part" | เส้นทาง (เช่นประสบการณ์.Workspace) | | "freeze" | ชื่อผู้ใช้ | | "unfreeze" | ชื่อผู้ใช้ | | "เพิ่ม" | ชื่อผู้ใช้ | | "ลบ" | ชื่อผู้ใช้ | | "ไล่ออก" | ชื่อผู้ใช้ | | "setuserpermission", "sup" | userId, permission | | "setgrouprankpermission", "sgrp" | groupid, rankId, permission |