一個 管理指令 是一個用戶具有一定控制等級可以輸入聊天窗口以啟動行動作的關鍵字或短語。這個庫使用聊天模組,可以輕鬆在舊的聊天系統上執行管理指令。聊天模組在伺服器上聆聽收到的訊息,並可以根據所需的任何條件執行行動。
設定
每當 Roblox 位置載入時,它都會檢查聊天服務是否為空。如果找不到需要的組件,地方將插入最新版本的這些組件。這表示在體驗中覆蓋或更改這些組件會使它們無法被更新。
設定管理員指令庫的第一步是新增聊天服務中的新聊天模組。本教學中的圖書館處理聊天模組所進行的重型起吊工作,因此您只需要添加到聊天服務中的唯一對象是新的 ModuleScript 。您模組腳本的名稱可以是任何東西,但我建議使用類似於 AdminCommands 的直觀名稱。
實裝新指令
而不是實現聊天模組的大部分邏輯,您只需要執行大量工作並添加額外功能的圖書館模組。將圖書館添加到您的模組的最簡單的方法是在腳指令碼頂部要求其資產ID。
local AdminCommands = require(1163352238)
此模組返回一個功能表,其中 Run 功能是最重要的一個。圖書館有一個 Run 功能用於其聊天模組。重要的是,管理指令返回此 Run 功能給聊天服務。函數以其名稱進行索引, Run , 您可以將以下內容返回,如果 Run 是我們管理命令表代表的屬性:
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 作為指令功能的參數很重要。例如,如果您有一個名為「爆炸」的指令,需要指定 Player 參數,那麼該函數將看起來像 explode(指令資料,使用者)。
| 功能 | 參數 | 返回 | | --------------- | ------------------------------------------------------------------------------------------------ | ------ | | 指令: | | | | BindCommand() | table functionIDs, function functionToExecute, number minimumPermissionLevel, string description | bool | | UnbindCommand() | table functionIDs | bool | | 獲取命令() | | table |
工具
圖形庫已經有一些內置的幫助功能,稱為「工具」,您可以使用。在變量或直接參考中儲存管理員指令。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 | | 錯誤處理: | | | | 不指定玩家: | table commandData | bool | | 不指定類型: | table commandData, string given, string expected | | | 數據轉換: | | | | 數據轉換: | array | | ToTupple(參數) | string 參數 | array | | ToBoolean() | string 參數 | bool | | 發送數據: | bool |
範例指令
一個有用的指令將是列印使用者可用的所有可選指令的列表。此命令輸出每個指令綁定到圖書館以及其幾個特性。
-- 列印所有綁定的指令清單
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.")
另一個有用的指令讓使用者給自己閃光。這個指令在說出時需要一個參數,即目標使用者的名稱。如果使用者存在,指令將在該使用者的 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,它將不會被觸發。指令系統使用獨立的許可圖書館,經驗創作者會自動獲得 math.huge 許可等級。管理員可以使用管理員命令模組對象上的以下功能來新增:
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 | | GetGroupRankPermission() | targetGroupId, targetRankId | int | | GetGroupRankPermission() | targetGroupId, targetRankId | int |
快速啟動模組
為了更簡單的設置,您也可以使用此 快速開始,它是一個模組,已實裝管理指令庫。模型是與上述格式相同的模組。此外,模組已包含一些指令,因此您不需要重新實裝。
| 指令/綁定 | 說話參數 | | -------------------------------- | -------------------------------- | | "list", "commands" | 使用者名稱 | | "sparkles" | 使用者名稱 | | "sparkles" | 使用者名稱 | | "unforcefield", "unff" | 使用者名稱 | | "explod新增 加至" | 使用者名稱 | | "part" | 路徑 (即使用者名稱)經體驗。工作區) | | "凍結" | 使用者名稱 | | "解凍" | 使用者名稱 | | "添加" | 使用者名稱 | | "移除" | 使用者名稱 | | "踢出" | 使用者名稱 | | "設定使用者權限","sup" | userId, permission | | "設定群組權限","sgrp" | groupid, rankId, permission |