Zenuvius
|
  |
| Joined: 26 Aug 2014 |
| Total Posts: 551 |
|
|
| 08 Jul 2015 02:54 PM |
game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) processCommand(player, message) end) end)
function processCommand(speaker, message) if message == ":kill" --target player targetplayer.Character.Humanoid.Health = 0 end end
How do I do something like ":kill Ze" and it will kill Zenuvius ?
This is a public chat command btw, I was wondering how to get the player from the message, been tinkering around with this for hours D: |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2015 02:55 PM |
for each player, if we find "Ze" inside of the player, add it to a list. Once done iteration, if there is more than 1 index to the table, error. More people have Ze in the name: It is unclear who to do the command to.
|
|
|
| Report Abuse |
|
|
Zenuvius
|
  |
| Joined: 26 Aug 2014 |
| Total Posts: 551 |
|
|
| 08 Jul 2015 03:05 PM |
function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end function onChatted(message, player) if message:sub(1, 6) == "murder" then local victim = findPlayer(message:sub(8)) if victim and victim.Character then victim.Character:BreakJoints() end end if message == ":break" then script.Disabled = true end end game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end)
=============
I came up with this, but problem is murder Zen doesn't work, it only works if I say murder Zenuvius :/ |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2015 03:08 PM |
if player.Name:lower() == name:lower() then
should be
if player.Name:lower():find(name:lower()) then
Plus... as i said... you should be popping the found value into a table or adding 1 to an integer variable to tell if there is more than 1 player with Zen or whatever.
Poor
Zenephobe
will die over
Zenfphobe |
|
|
| Report Abuse |
|
|
Zenuvius
|
  |
| Joined: 26 Aug 2014 |
| Total Posts: 551 |
|
|
| 08 Jul 2015 03:12 PM |
I just started using Chat Commands today and I just learnt Tables a couple days ago so I'm trying to take it slowly D:
I'll get there eventually, one question though, like you said earlier, the game would be confused if there's two Zens in the game, but does that mean it will pick a random Zen or would it just break the script ? |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2015 03:14 PM |
Neither.
Like I said... it will kill the first Zen it finds in your case. |
|
|
| Report Abuse |
|
|
OneShot17
|
  |
| Joined: 06 Apr 2014 |
| Total Posts: 809 |
|
|
| 08 Jul 2015 03:16 PM |
| What I would do is take a free modeled admin script and look at how it works. Try to figure it out that way. |
|
|
| Report Abuse |
|
|
Zenuvius
|
  |
| Joined: 26 Aug 2014 |
| Total Posts: 551 |
|
|
| 08 Jul 2015 03:23 PM |
Nvm, I got it, I made it return a ScreenGui that tells the player to specify which zen if there is more than 1 :D
Thanks mate ~ |
|
|
| Report Abuse |
|
|