관리자 명령

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

관리 명령은 특정 수준의 제어를 가진 사용자가 채팅 창에 입력할 수 있는 키워드나 구문으로, 액션트리거합니다.이 라이브러리는 채팅 모듈을 사용하여 레거시 채팅 시스템 위에 쉽게 관리 명령을 구현할 수 있습니다.채팅 모듈은 서버에서 들어오는 메시지를 듣고 원하는 기준에 따라 작업을 실행할 수 있습니다.

설정

Roblox 장소가 로드될 때마다 채팅 서비스가 비어 있는지 확인합니다.필요한 구성 요소를 찾을 수 없으면 장소에 해당 구성 요소의 최신 버전이 삽입됩니다.즉, 경험에서 이러한 구성 요소를 덮어쓰거나 변경하면 업데이트되지 않습니다.

관리 명령 라이브러리를 설정하는 첫 번째 단계는 채팅 서비스에 새로운 채팅 모듈을 추가하는 것입니다.이 자습서의 라이브러리는 채팅 모듈에서 수행한 무거운 들기를 처리하므로 채팅 서비스에 추가해야 하는 유일한 개체는 새로운 ModuleScript입니다.모듈 스크립트의 이름은 무엇이든 될 수 있지만, AdminCommands와 같이 직관적인 것을 제안합니다.

새 명령 구현

채팅 모듈 논리의 대부분을 구현하는 대신 작업의 대부분을 수행하고 추가 기능을 추가하는 라이브러리 모듈만 요구하면 됩니다.모듈에 라이브러리를 추가하는 가장 간단한 방법은 스크립트 상단에서 자산ID로 라이브러리를 요구하는 것입니다.


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"})

AdminCommands 스크립트의 전체 콘텐츠는 팔로잉같이 보여야 합니다:


local AdminCommands = require(1163352238)
local Utilities = AdminCommands.Utilities
function commandFunction(commandData)
-- 여기에 명령 코드
-- 성공하면 참이고 그렇지 않으면 거짓을 반환합니다.
end
AdminCommands:BindCommand({"keyword1", "keyword2"}, commandFunction, 1, "Optional description")
return AdminCommands.Run

예제 함수가 commandData라는 매개변수를 사용한다는 것을 알 수 있습니다.이 매개 변수는 라이브러리에서 실행될 때 모든 바인딩된 관리 명령 함수에 전달되는 테이블 인수입니다.This parameter is a table argument passed along to all bound admin command functions when executed by the library.테이블에는 발화된 명령과 그 명령을 발화한 사용자에 대한 유용한 정보가 포함되어 있습니다.다음 필드가 있습니다:

  • 스피커: ChatSpeaker
  • 메시지: string
  • 채널 이름: string
  • 명령: string

명령 함수의 매개 변수로 commandData를 항상 기대해야 합니다.예를 들어, 명령에 "explode"라는 이름이 있고 해당 명령에는 Player 매개 변수가 지정되어야 하는 경우, 함수는 explode(commandData, user)처럼 보입니다.

| 함수 | 매개 변수 | 반환 | | --------------- | ------------------------------------------------------------------------------------------------ | ------ | | 명령: | | | | BindCommand() | table functionIDs, function functionToExecute, number minimumPermissionLevel, string description | bool | | UnbindCommand() | table functionIDs | bool | | GetCommands() | | 테이블 |

유틸리티

라이브러리에는 이미 사용할 수 있는 몇 가지 기본 도우미 함수, 즉 유틸리티가 있습니다.변수나 직접 참조하여 Store AdminCommand.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, ...| 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에 Sparkles 개체를 생성합니다.


-- 지정된 플레이어의 캐릭터에 반짝임을 줍니다
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")

또한 관리자 명령 생성 튜토리얼에서 폭발 명령을 포함할 수 있습니다. 이 명령도 사용자 이름을 매개 변수로 사용합니다.


-- 지정된 모델이 캐릭터임을 확인하고 HumanoidRootPart에 폭발을 추가합니다
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 권한 레벨을 부여하는 별도의 권한 라이브러리를 사용합니다.관리자는 다음 함수를 사용하여 AdminCommands 모듈 개체에 추가할 수 있습니다:


SetUserPermission(number requesterUserId, number targetUserId, permissionLevel) -> bool
SetGroupRankPermission(number requesterUserId, number targetGroupId, number targetRankId, permissionLevel) -> bool

| 함수 | 매개 변수 | 반환 | | ---------------------------- | ---------------------------------------------------------------------------------- | ------ | | 권한 | | | | GetAdmins() | | 테이블 | | SetUserPermission() | number requesterUserId, number targetUserId, permissionLevel | bool | | GetUserPermission() | number userId | number | | GetGroupRankPermission() | number requesterUserId, targetGroupId, targetRankId, permissionLevel | bool | | GetGroupRankPermission() | targetGroupId, targetRankId | int | | GetGroupRankPermission() | number userId | int |

빠른 시작 모듈

쉽게 설정하려면 Admin 명령 라이브러리를 이미 구현한 모듈인 빠른 시작을 사용할 수도 있습니다.모델은 위에 설명된 것과 동일한 형식의 모듈입니다.또한 모듈에는 이미 포함된 몇 가지 명령이 있어서 재구현할 필요가 없습니다.

| 명령/바인딩 | 음성 매개변수 | | -------------------------------- | -------------------------------- | | "list", "commands" | 사용자 이름 | | "sparkles" | 사용자 이름 | | "sparkles" | 사용자 이름 | | "unforcefield", "unff" | 사용자 이름 | | "explode" | 사용자 이름 | | "part" | 경로 (즉,경험.워크스페이스) | | "freeze" | 사용자 이름 | | "unfreeze" | 사용자 이름 | | "추가" | 사용자 이름 | | "제거" | 사용자 이름 | | "추방" | 사용자 이름 | | "setuserpermission", "sup" | userId, permission | | "setgrouprankpermission", "sgrp" | groupid, rankId, permission |