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

How to detect which player ran the command in an Adonis plugin?

Asked by 3 years ago

Hi. I'm making a game with a custom adonis command that needs to know which player eecuted the command.. It is a setrank command, and here is the script:

server = nil -- Mutes warnings about unknown globals
service = nil
return function()
    server.Commands.ExampleCommand = {
        Prefix = '!';
        Commands = {"setrank", "setgroup"};
        Args = {"arg1"};
        Description = "Set group tag.";
        Hidden = false;
        Fun = false;
        AdminLevel = "Players";
        Function = function(plr,args)
            -- Find Player here
        end
    }
end

1 answer

Log in to vote
0
Answered by 3 years ago

It gives the player with function(plr,args), heres an example of how to use it:

server = nil -- Mutes warnings about unknown globals
service = nil
return function()
    server.Commands.ExampleCommand = {
        Prefix = '!';
        Commands = {"setrank", "setgroup"};
        Args = {"arg1"};
        Description = "Set group tag.";
        Hidden = false;
        Fun = false;
        AdminLevel = "Players";
        Function = function(plr,args)
            print(plr.Name .. ' executed the command: !setrank')
        end
    }
end

Also, if you are going to also ask about how to get the player specified it would be args[1], for example:

server = nil -- Mutes warnings about unknown globals
service = nil
return function()
    server.Commands.ExampleCommand = {
        Prefix = '!';
        Commands = {"setrank", "setgroup"};
        Args = {"arg1"};
        Description = "Set group tag.";
        Hidden = false;
        Fun = false;
        AdminLevel = "Players";
        Function = function(plr,args)
            print(plr.Name .. ' executed the command: !setrank on ' .. tostring(args[1]))
        end
    }
end
Ad

Answer this question