gbs
|
  |
| Joined: 10 Apr 2008 |
| Total Posts: 16823 |
|
|
| 22 Oct 2012 09:07 PM |
| Not quite as bad as it sounds ;) Just one section that I can't quite get to work. Basically, this section checks a table to see if a player who chatted is in said table, then removes that player from the table. |
|
|
| Report Abuse |
|
|
Xlaive
|
  |
| Joined: 25 Aug 2012 |
| Total Posts: 97 |
|
| |
|
|
| 22 Oct 2012 09:10 PM |
| Post it. I have an idea of how if might work. |
|
|
| Report Abuse |
|
|
adjotur
|
  |
| Joined: 10 Oct 2011 |
| Total Posts: 892 |
|
|
| 22 Oct 2012 09:16 PM |
Is it neat?
if so 150 lines is nothing. You should see this Java game I'm writing. One of my classes is over 400 lines and brutally disorganized. Its very painful to troubleshoot o.o |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 09:18 PM |
"You should see this Java game I'm writing. One of my classes is over 400 lines and brutally disorganized. Its very painful to troubleshoot o.o"
My Battleship Java game has over 1.7k lines. Very hard to follow. And it's commented .... |
|
|
| Report Abuse |
|
|
gbs
|
  |
| Joined: 10 Apr 2008 |
| Total Posts: 16823 |
|
|
| 22 Oct 2012 09:20 PM |
I have a feeling I could leave some stuff out....but just in case:
admins = {"gbs","Player1"} banned = {}
function playerBanned(name) for i,v in pairs(banned) do if name:lower() == v:lower() then return true end end end
function isAdmin(name) for i,v in pairs(admins) do if name:lower() == v:lower() then return true end end end
function chatted(msg, rec, spoken) if string.sub(msg, 1,5):lower() == "kill/" then local player = getPlayer(string.sub(msg,6)) for i,v in pairs(player) do local player = v if player.Character then player.Character.Humanoid.Health = 0 end end elseif string.sub(msg, 1,5):lower() == "kick/" then local player = getPlayer(string.sub(msg,6)) for i,v in pairs(player) do local player = v player:remove() end elseif string.sub(msg, 1,4):lower() == "ban/" then local player = getPlayer(string.sub(msg,5)) for i,v in pairs(player) do local player = v player:remove() table.insert(banned, v.Name) end elseif string.sub(msg, 1,8):lower() == "explode/" then local player = getPlayer(string.sub(msg,9)) for i,v in pairs(player) do local player = v if player.Character:FindFirstChild("Torso") then local e = Instance.new("Explosion") e.Position = player.Character.Torso.Position e.Parent = Workspace end end elseif string.sub(msg, 1,4):lower() == "sit/" then local player = getPlayer(string.sub(msg,5)) for i,v in pairs(player) do local player = v if player.Character:findFirstChild("Humanoid") then player.Character.Humanoid.Sit = true end end elseif string.sub(msg, 1,10):lower() == "walkspeed/" then local player = nil local slash = nil for i = 11,msg:len() do if string.sub(msg, i,i) == "/" then slash = i player = getPlayer(string.sub(msg,11,i-1)) break end end for i,v in pairs(player) do local player = v local walkspeed = tonumber(string.sub(msg,slash+1)) if walkspeed then local humanoid = player.Character:FindFirstChild("Humanoid") if humanoid then humanoid.WalkSpeed = walkspeed end end end elseif string.sub(msg, 1,7):lower() == "health/" then local player = nil local slash = nil for i = 8,msg:len() do if string.sub(msg, i,i) == "/" then slash = i player = getPlayer(string.sub(msg,8,i-1)) break end end for i,v in pairs(player) do local player = v local health = (string.sub(msg,slash+1):lower() == "math.huge" and math.huge) or tonumber(string.sub(msg,slash+1)) if health then local humanoid = player.Character:FindFirstChild("Humanoid") if humanoid then humanoid.MaxHealth = health humanoid.Health = health end end end end end
function getPlayer(name,spoken) local returned = {} if name:lower() == "all" then returned = game.Players:GetPlayers() elseif name:lower() == "others" then local players = game.Players:GetPlayers() for i,v in pairs(players) do if v == spoken then table.remove(players,i) end end returned = players elseif name:lower() == "admins" then local players = game.Players:GetPlayers() for i,v in pairs(players) do if isAdmin(v.Name) then table.insert(returned,v) end end elseif name:lower() == "nonadmins" then local players = game.Players:GetPlayers() for i,v in pairs(players) do if isAdmin(v.Name) then table.remove(players, i) end end returned = players else for i,v in pairs(game.Players:GetPlayers()) do if v.Name:sub(1, name:len()):lower() == name:lower() then table.insert(returned, v) end end end return returned end
function adminCommand(playernew) if playerBanned(playernew.Name) then playernew:remove() elseif isAdmin(playernew.Name) then playernew.Chatted:connect(function(msg,rec) chatted(msg,rec,playernew) end) end end
game.Players.PlayerAdded:connect(adminCommand)
You see the "other" elseif statement under the getPlayer function? That's what I'm trying to get to work. The chatted function contains all of the commands, and is probably not important. isAdmin checks if player is an admin; playerBanned checks if player is banned. |
|
|
| Report Abuse |
|
|
adjotur
|
  |
| Joined: 10 Oct 2011 |
| Total Posts: 892 |
|
|
| 22 Oct 2012 09:22 PM |
| Yeah, I've only started commenting recently. I know 400 lines really isnt that bad. Infact it too is nothing, but its still way worse then 150 lines of neat code. I was just smart to utilize poly to its fullest ability, which means most classes are like 100 lines long, instead of like three 3000 line classes |
|
|
| Report Abuse |
|
|
Xlaive
|
  |
| Joined: 25 Aug 2012 |
| Total Posts: 97 |
|
|
| 22 Oct 2012 09:22 PM |
| three 3000s? Thats like . . . 9000... :O |
|
|
| Report Abuse |
|
|
adjotur
|
  |
| Joined: 10 Oct 2011 |
| Total Posts: 892 |
|
|
| 22 Oct 2012 09:23 PM |
Also, on topic here.
I think it should be string.lower([Variable name here]) == "others"
Maybe roblox has recently added a different way to do this, but thats how I do it. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 09:24 PM |
three 3000s?
That's like ...
OVAR 9000!!!!!
Oh, wait .... |
|
|
| Report Abuse |
|
|
adjotur
|
  |
| Joined: 10 Oct 2011 |
| Total Posts: 892 |
|
|
| 22 Oct 2012 09:24 PM |
@Xlaive
Infinatly generating 2D adventure game's need a lot of code. I plan to have about 20 different "Biomes" each will take up about 50 lines of code each. it adds up. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 09:24 PM |
@adj
String values are actually objects with a metatable that leads to the string class. ;P
print( ("Lol"):sub(1, 2) ) --> Lo |
|
|
| Report Abuse |
|
|
adjotur
|
  |
| Joined: 10 Oct 2011 |
| Total Posts: 892 |
|
|
| 22 Oct 2012 09:28 PM |
Huh.
You learn something new every day. |
|
|
| Report Abuse |
|
|
gbs
|
  |
| Joined: 10 Apr 2008 |
| Total Posts: 16823 |
|
|
| 22 Oct 2012 09:29 PM |
| adj, but what you are talking about works elsewhere... |
|
|
| Report Abuse |
|
|
gbs
|
  |
| Joined: 10 Apr 2008 |
| Total Posts: 16823 |
|
|
| 22 Oct 2012 09:31 PM |
| I personally think there is a problem with the argument spoken in getPlayer...but...yea... |
|
|
| Report Abuse |
|
|
gbs
|
  |
| Joined: 10 Apr 2008 |
| Total Posts: 16823 |
|
|
| 22 Oct 2012 09:42 PM |
| Any clues? I still can't figure it out. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 22 Oct 2012 09:43 PM |
| i suggestt adding a return false over the last end of getadmin/etc |
|
|
| Report Abuse |
|
|
gbs
|
  |
| Joined: 10 Apr 2008 |
| Total Posts: 16823 |
|
|
| 22 Oct 2012 09:55 PM |
Still nope. :/
I'll ask around, see if I can find the answer. Good night. |
|
|
| Report Abuse |
|
|