Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to create a simple admin command?

Asked by 5 years ago

So I have a simple script that changes the FOV of the player using a simple property change.

workspace.Camera.FieldOfView = ""

But, I would prefer to do this through chat.

Ex. "fov 90" or "fov 100" etc etc I've researched some admin command type things but nothing really fits my needs. If you could contribute anything that would help! Thank you.

1 answer

Log in to vote
1
Answered by
crywink 419 Moderation Voter
5 years ago
Edited 5 years ago

Hey!

Admin command systems are pretty easy to make. The only real "challenging" part (for some people) is the string manipulation. While it isn't difficult, it's just hard for some to wrap their heads around. Once you have your head wrapped around it, it becomes quite easy and you can make your argument handler as advanced as you really want it to be. For example, if you wanted, you could make it so that you predefine your arguments and automatically parse them to a player, string, int, etc... It really just depends on your programming knowledge and use case. Below is an example from the command table in a command handler I made a few months ago.

Click to view

Lucky for you though, I actually helped somebody else out with getting started on their own little admin command system a few days ago and quickly wrote up a VERY simple framework to start working off of. Mind, this is a super simple system and I don't really recommend it for large scale use due to its simplicity.

local prefix = "!"
local Commands = {
    ["fov"] = function(args)
        workspace.CurrentCamera.FieldOfView = tonumber(args[1])
    end
}

game.Players.PlayerAdded:Connect (function(plr)
    plr.Chatted:Connect (function(msg)
        local args = string.split(msg, " ") -- this will separate the string into an array ("hey there" -> {"hey", "there"})
        local cmd = args[1] -- first argument is going to be the commnad

        if cmd:sub(1,#prefix) == prefix then -- check if the prefix is at the start of the command 
            cmd = cmd:sub(#prefix + 1, #cmd) -- remove the prefix from the command to make checks easier

            if Commands[cmd:lower()] then -- see if the command is present in the command table
                table.remove(args, 1) -- remove the first argument (command) because its useless now
                Commands[cmd:lower()](args) -- find the command in the commands table and call the function with arguments
            end
        end
    end)
end)

I hope this helped you out a bunch and if this did help you, please remember to upvote and accept the answer.

0
local prefix = "!" local Commands = { ["fov"] = function(args) workspace.CurrentCamera.FieldOfView = tonumber(args[1]) end } game.Players.PlayerAdded:Connect (function(plr) plr.Chatted:Connect (function(msg) local args = string.split(msg, " ") -- this will separate the string into an array ("hey there" -> {"hey", "there"}) local cmd = args[1] -- first argument User#30793 0 — 5y
0
Hi! Thank you for the response, but for my purpose I'm actually using it as an exploit through Synapse X. Was I supposed to change a value or anything? No errors are shown in console however it doesn't seem to be working. doublevisions 3 — 5y
0
Yep. If you’re trying to use this with something like Synapse, get rid of the PlayerAdded event and make a reference (a variable) to the client (game.Players.LocalPlayer) and call it “plr”. crywink 419 — 5y
0
ew text commands VitroxVox 884 — 5y
Ad

Answer this question