|
| 16 Sep 2012 04:05 PM |
| So like in Person299 admin commands where you can say like ff/pl to put a forcefield into player. How do I make the script find the players name shortened? I am making an admin commands and it breaks when I don't type the players name in full. Please help! |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Sep 2012 04:12 PM |
| bump will post the erroring script if needed. |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 04:13 PM |
Here's the script:
local admins = {"thedeathmaster01", "Player"}
game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) for i = 1, #admins do if player.Name == admins[i] then
function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end
--Start commands
-- kick command if msg:sub(1,2) == "k/" then kp = findPlayer(msg:sub(3)) if game.Players[kp] ~= nil then game.Players[kp]:Destroy() end end --end kick command
--forcefield add command if msg:sub(1,3) == "ff/" then victim = findPlayer(msg:sub(4)) if game.Players[victim] ~= nil then Instance.new("ForceField", Workspace[victim]) end end --end forcefield add command
--start remove forcefield command if msg:sub(1,5) == "unff/" then unvictim = findPlayer(msg:sub(6)) if game.Players[unvictim] ~= nil then for _,v in pairs(Workspace[victim]:GetChildren()) do if v:IsA("ForceField") then v:Destroy() end end end end --end remove forcefield command
--Default end marks end end end) end) |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 04:17 PM |
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|
|
| Report Abuse |
|
|
| |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 16 Sep 2012 04:22 PM |
function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end
You can change this line: if player.Name:lower() == name:lower() then
To: if player.Name:lower():find(name:lower()) then
That trys to see if the name you typed is _any part_ of a player's name, rather than just equal to it. Which will make stuff like "loc" match the player "blockguy". |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 04:23 PM |
@stravant, thanks, I'll try that. I got the findPlayer function from
http://wiki.roblox.com/index.php/How_To:_Admin_Commands |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 04:26 PM |
Did that, but I am still getting the same error:
Workspace.Script:40: bad argument #2 to '?' (string expected, got userdata) |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 04:27 PM |
Current script:
local admins = {"thedeathmaster01", "TechnologyKing"}
game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) for i = 1, #admins do if player.Name == admins[i] then
function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower():find(name:lower()) then -- CHANGED THIS! return player end end end
--Start commands
-- kick command if msg:sub(1,2) == "k/" then kp = findPlayer(msg:sub(3)) if game.Players[kp] ~= nil then game.Players[kp]:Destroy() end end --end kick command
--forcefield add command if msg:sub(1,3) == "ff/" then victim = findPlayer(msg:sub(4)) if game.Players[victim] ~= nil then Instance.new("ForceField", Workspace[victim]) end end --end forcefield add command
--start remove forcefield command if msg:sub(1,5) == "unff/" then unvictim = findPlayer(msg:sub(6)) if game.Players[unvictim] ~= nil then for _,v in pairs(Workspace[victim]:GetChildren()) do if v:IsA("ForceField") then v:Destroy() end end end end --end remove forcefield command
--Default end marks end end end) end) |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Sep 2012 04:37 PM |
instead of game.Players[victim], just use victim
¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests! |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 04:43 PM |
| but victim is just the players name |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 04:43 PM |
but it's not...
¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests! |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 04:46 PM |
| Can you fix the script for me? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
|
| 16 Sep 2012 05:32 PM |
| If I don't get a reply within 5 minutes, I'll make a new thread and f5 this one. |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 16 Sep 2012 05:37 PM |
| You have already been given your solution. If you don't want to try it that's your problem. |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 05:51 PM |
| I don't understand what they said to do. |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 16 Sep 2012 06:25 PM |
It's just like DoomBringer said:
The way you have it working right now, `victim` _is_ the player, not the player's name. Replace what you have right now with `victim` for the player and `victim.Character` for their character. |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 06:39 PM |
don't call me DoomBringer
i'm not MrDoomBringer, i'm doombringer42 ;-;
¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests! |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 06:41 PM |
umg i'm loling so hard at what doombringer42 said in reply to stravant. WAY TO SHOW ADMINS WE DISLIKE THEM! :D
-> Siggy pooped by the power of Ponies <- |
|
|
| Report Abuse |
|
|