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

Arguments from onChatted possible?

Asked by 9 years ago

I'm not sure if this is possible but I really want to know.

Can you get args from onChatted?

For example, is there any way to make a command like !promote InsertAPI 1-255?

Could you please supply some links to get me started please if it's possible? :)

Thanks! Nathan.

PS: I have some starting code here, it's just that I don't know how to finish it off.

game.Players.PlayerAdded:connect(function(Player)
    Player.Chatted:connect(function(msg)
        if Player:GetRankInGroup(1240173) >= 12 then
            if msg == "!promote" then
                print("wut")
            end
        end
    end)
end)

1 answer

Log in to vote
1
Answered by
yumtaste 476 Moderation Voter
9 years ago

Here is the link for string manipulation. Use string.sub and string.find to find what certain parts of the string are. For example, you could use string.sub to find what's after the 6th character in the command "!kill " to see who to kill. You could use string.find to find certain text in the string. Like if you wanted to compare a name prefix to an actual player name (doing "!kill boba" instead of "!kill bobafett3544") by doing something like this (may not work, this is just an idea):

for i, player in pairs(game.Players:GetPlayers()) do
if string.find(player.Name, message) ~= nil then
print(player.Name)
end
end

And even though the above example may not work, I have to type the following because it might work better.

for i, player in pairs(game.Players:GetPlayers()) do
if string.match(player.Name, message.."%w+") == player.Name then
print(player.Name)
end
end

Ok. I've given you two examples. I'm going to create a function to find a player's name based on a prefix, and once I create that function, I will include it in this answer.

Note: There's no function to promote a player in their group if you are in-game. Just thought I'd let you know.

1
Ah fantastic, can't wait for the function. Also, yeah. I know that there is no in-game promotion, I created it using HTTP Service. :) WelpNathan 307 — 9y
1
Awesome! If your method works, please share it with the community. It could really help people out! And, if I answered your question, please mark the answer as accepted. We both get a reputation point. yumtaste 476 — 9y
1
Oops, yeah. Forgot, haha. Thanks again! WelpNathan 307 — 9y
Ad

Answer this question