cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 23 Jun 2013 04:30 PM |
I made a script that adds players to a table and then kills them how would i make it so that it removes the certain player(s) that die from the table? Also is there a way that could make the script below more efficient? here's part of my script: the table is _G.peoplehit
local e = Workspace:GetChildren() for i = 1,#_G.peoplehit do if (_G.peoplehit[i] ~= nil) then local face = (_G.peoplehit[i].Head:findFirstChild("face")) if face ~= nil then face.Texture = "http://www.roblox.com/asset/?id=111916219" while _G.peoplehit[i].Humanoid.Health>0 do wait() _G.peoplehit[i].Head.Mesh.Scale = _G.peoplehit[i].Head.Mesh.Scale +Vector3.new(0.01,0.01,0.01) _G.peoplehit[i].Humanoid.Health = _G.peoplehit[i].Humanoid.Health - 1 end end end end
Thanks |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2013 04:32 PM |
| table.remove(tablename, KEY) |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 23 Jun 2013 04:33 PM |
that kind of helps, but how would i make it apply to certain players that die? ._. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2013 04:37 PM |
for _,Person in next,_G.peoplehit do if Person and Person:FindFirstchild[[Head]] then local Face = Person.Head:FindFirstChild[[face]] if Face then Face.Texture= "http://www.roblox.com/asset/?id=111916219" local Alive = true Spawn(function() while Alive do wait() Person.Head.Mesh.Scale = Person.Head.Mesh.Scale +Vector3.new(0.01,0.01,0.01) Person.Humanoid.Health = _Person.Humanoid.Health - 1 end end) Person.Humanoid.Died:connect(function() Alive = false table.remove(_G.peoplehit,_) end) end end end |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 23 Jun 2013 04:46 PM |
| do i have to define _,Person in next? and if i do how? ._. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2013 04:58 PM |
"notsopwnedg
Joined: 07 Nov 2010 Total Posts: 2362 LuaLearners Re: How to remove certain things from a table? Posted: 06-23-2013 02:37 PM for _,Person in next,_G.peoplehit do if Person and Person:FindFirstchild[[Head]] then local Face = Person.Head:FindFirstChild[[face]] if Face then Face.Texture= "http://www.roblox.com/asset/?id=111916219" local Alive = true Spawn(function() while Alive do wait() Person.Head.Mesh.Scale = Person.Head.Mesh.Scale +Vector3.new(0.01,0.01,0.01) Person.Humanoid.Health = _Person.Humanoid.Health - 1 end end) Person.Humanoid.Died:connect(function() Alive = false table.remove(_G.peoplehit,_) end) end end end"
That is one of the worst scripts I have ever seen. LL would be ashamed at that coding style. |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 23 Jun 2013 05:10 PM |
| Agent, Can u fix it for me :)? |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|
|
| 23 Jun 2013 05:14 PM |
I would change the way you add people to the table.
function RemovePlayerOnDeath(Table, Player) ypcall(function() Player.Character.Humanoid.Died:wait() Table[Player] = false end) end
function Add(Table, Player) Table[Player] = true RemovePlayerOnDeath(Table, Player) end
function PlayerIsAlive(Table, Player) for _, v in pairs(Table) do if _ == Player then return v end end return false end |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 23 Jun 2013 05:26 PM |
Thanks! :D I don't get the Table[Player] = true part tho Would I use it like this?:
function touch(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then add(_G.peoplehit,hit.Parent) end end
or how? |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2013 05:31 PM |
AFF Any chance you can tell me why it is so horrible so I don't do that again...
Dx |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2013 05:42 PM |
"Thanks! :D I don't get the Table[Player] = true part tho Would I use it like this?:
function touch(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then add(_G.peoplehit,hit.Parent) end end
or how?"
function touch(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then if game.Players:GetPlayerFromCharacter(hit.Parent) then Add(_G.peoplehit,game.Players:GetPlayerFromCharacter(hit.Parent)) end end
Then use the PlayerIsAlive function to see if they are in the table.
"AFF Any chance you can tell me why it is so horrible so I don't do that again...
Dx"
The pairs function exists so you don't have to type 'in next, Table.' Using pairs makes it much cleaner. Using [[ ]] as your string delimiters is terrible, plus the fact that you omitted the parenthesis to your method calls. Those combined are even worse. Using table.remove from a numerical loop is bad because it would skip the next index IIRC. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2013 05:43 PM |
"function touch(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then if game.Players:GetPlayerFromCharacter(hit.Parent) then Add(_G.peoplehit,game.Players:GetPlayerFromCharacter(hit.Parent)) end end"
Forgot an end. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2013 06:03 PM |
| Yes I guess you are right...But for some reason I still like using 'next'. |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 24 Jun 2013 02:28 PM |
| Sorry to bother you again but how would i use the function PlayerIsAlive(Table, Player) function? Isn't that only possible to do in a local script because player.Character is only available in local script right? ._. |
|
|
| Report Abuse |
|
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|
cxcharlie
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
| |
|