|
| 20 Jul 2017 07:58 PM |
| Hey, how do I make a sort of "admin command" style listener so that when i say a specific phrase it happens? |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 20 Jul 2017 08:00 PM |
| Player.Chatted:Connect(function(message) |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 08:08 PM |
| Alright, now how do I make it somewhat custom? Say for example a "/name" command, how would I be able to test for words that are typed after "/name"? |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
| |
|
|
| 20 Jul 2017 08:17 PM |
I've read the wiki on this a few times now, but I'm not entirely sure what form I would need for this, would I need string.byte, string.char, string.dump, string.find, string.format, string.len, string.lower, string.match, string.sub, string.gmatch, or string.gsub?
|
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 20 Jul 2017 08:27 PM |
Look at all the descriptions and tell me which ones you think you could use
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 08:35 PM |
I'm really thinking I could use string.match, maybe I could set a variable that is the phrase said after "/name"? here's the code I'm thinking
while true do wait(0.01) game.Player.Chatted:Connect(function(message) if message.string.match("/name") then local n = message.string.match("/name", "%W+") print(n) end end) end
This should print the phrase said after "/name" right? |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 20 Jul 2017 08:38 PM |
if msg:match('/name')then print('/name was found') end
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 08:40 PM |
| unknown global variable 'msg' |
|
|
| Report Abuse |
|
|
WXBZ
|
  |
| Joined: 10 Oct 2012 |
| Total Posts: 850 |
|
|
| 20 Jul 2017 08:40 PM |
@caca was that a joke? You should use string.sub to receive the command and to find the command argument if there is one.
for _, post in pairs(game.Players.WXBZ.Posts:GetChildren()) do post.Signature.Text = 'scripters.cf' end |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 08:44 PM |
So would this work?
game.Player.Chatted:Connect(function(message) print(message.string.sub("/name", 6)) end) |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 08:46 PM |
Wait, no, this looks better I think
game.Player.Chatted:Connect(function(message) print(string.sub(message, 6)) end) |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 20 Jul 2017 08:47 PM |
local function GetArgs(msg) local Args = {} for i in msg:gmatch("%S+") do Args[#Args + 1] = i:lower() end return Args end
That's an easy way to get the command arguments from the string |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 08:52 PM |
| Woah, shoot dude, slow down a little? I don't even know what "Args" are, wiki link? |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 20 Jul 2017 10:05 PM |
That would be a variable, just as 'msg' is also a variable in the example I provided.
If you don't know what a variable is, start here: http://wiki.roblox.com/index.php?title=Intro_to_Scripting
@WXBZ
Why would it be a joke?
string.match() works perfectly fine.
Example from output:
> local s = 'I like food' local find = 'food' print(s:match(find)) food > local s = 'I like ' local find = 'food' print(s:match(find)) nil
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 10:12 PM |
| Caca knows what he's talking about lol |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 10:24 PM |
@OP I've been working with ACs for years now, so I am confident in what I'm about to say:
When creating an admin commands script, you require the script to listen for when a player does chat. You use the `Chatted` evebt for this:
player.Chatted:Connect(func)
But that's only the nail on the head: If you wish, for example, for a message/hint command would appear with the player's name, then you would give the chat function the chat, and the speaker:
player.Chatted:Connect(function(message) func(message, player) end)
Now, onto commands: They aren't as easy as you think. They can be very, VERY complicated, depending on what you're trying to do. I've seen many ways, but I recommend using the `find` function to search for a keyword/split (A split is a space between the commands). This's how it would look:
local message = message:lower() -- Makes stuff easier. ;)
if message:sub(1, 9) == 'teleport ' then local chk = message:sub(10):find(' ') local playerz1 = func(msg:sub(9, chk-1)) local playerz2 = func(msg:sub(chk+1)) if playerz1 and playerz2 and playerz1.Character and playerz2.Character then playerz1.Character:MoveTo(playerz2.Character) end end -- See how complicated it can get?
The vital things between getting a player is to set up a function. Using a function really helps in the long run, because some like to rewrite the code to get the player. :|
function getplayer(message, player) local message = message:lower() local playerz = {} for i, v in next, PlayersService:GetPlayers() do if message == 'me' then table.insert(playerz, v) elseif message == 'all' and v.Name:lower():sub(1, 3) ~= 'all' and v.Name:lower():sub(4) == '' then table.insert(playerz, v) elseif v.Name:lower():sub(1, #message) == message then table.insert(playerz, v) break end end return playerz end -- Pretty nowadays function to get a player. Could be touched up more, but meh.
Now, onto the #1 vital thing about admin commands: Admins. You want admins. That's the point of the admin scripts: "Admin" Commands. You would check a player via brackets, or compare their userId to an Id from the/a table.
local AdminList = { [17514438] = true }
if AdminList[player.UserId] then -- commands end
And pretty much the gist of it all. :P Got any more questions about admin commands? Fire away, or PM me: Much faster that way. :)
I hope I helped you man. :) |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 20 Jul 2017 10:30 PM |
I don't like using string.sub() for commands.
I like to have my commands be non-constricted by exactness.
What I mean by that is:
'I would like to teleport myself to the player known as caca'
or 'teleport myself caca'
with string.sub(), it'd be rather tricky to make both of those work.
With string.match() or string.find() it'd be easier.
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 10:34 PM |
I made a mistake in the `getplayer` and condition codes:
1. The function to get the player. I meant to have it add the player, and not the person. I also added in a `break` by accident.
2. The condition statement. I meant to add a `+ 9` after the `find` function, because I forgot for what reason, but it requires it to properly get a split/the rest of the message. (Something like that.)
But just like before, don't be afraid to shoot me a PM if you have any questions on ACs. :) |
|
|
| Report Abuse |
|
|