harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
|
| 29 Jan 2012 01:33 PM |
| Hey I was making a script for a MW3 Type survival game, and I got 50 waves set up than realized I need a way for the game to end when all the players are dead. What I have now is that they are teleported down to the map and when the game ends they die and get teleported back to spawn which isn't very good because there is no point to the game. Is there another way for the game to end when all players die? |
|
|
| Report Abuse |
|
|
| |
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
|
| 29 Jan 2012 01:35 PM |
Umm.. no that wouldn't do anything right? I started it with:
while true do
and ended with
end end |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 01:36 PM |
Yes.
First, get all the players. Insert them into a table. Then, when a player dies, remove them from the table. When the table has no values inside of it, the game ends.
Here's a list of things you'll need.
:GetPlayers() Table manipulation .Died
And that's about it. |
|
|
| Report Abuse |
|
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
|
| 29 Jan 2012 01:38 PM |
| Ok... do you know where I could go get information on tables? I just started the whole scripting thing :C |
|
|
| Report Abuse |
|
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
|
| 29 Jan 2012 01:42 PM |
would the wiki be any help?
|
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 01:46 PM |
| For something this complicated? Nah. I'll write something up for you real fast. |
|
|
| Report Abuse |
|
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
| |
|
|
| 29 Jan 2012 01:53 PM |
local Alive = {} local GameActive = false
function PlayerDied(Player) if Alive[Player.Name] then Alive[Player.Name] = false end end
function SetPlayersAlive() for _, v in pairs(game.Players:GetPlayers()) do if v.Character and v.Character:FindFirstChild("Humanoid") and not GameActive then Alive[v.Name] = true v.Character.Humanoid.Died:connect(function() PlayerDied(v) end) end end end
function AllPlayersDead() for _, v in pairs(Alive) do if v then return false end end return true end
game.Players.PlayerRemoving:connect(function(player) PlayerDied(player) end)
Basically, we have a function that runs when a player dies. This function sets the value at the player's name in the table to false. When you run the SetPlayersAlive function, you add all eligible players to the Alive table. The AllPlayersDead function checks to see if all the players have died. We use the PlayerRemoving event to determine that a player has died as well, in case they leave the game in the middle of the match.
Basic table manipulation is all that was really needed. |
|
|
| Report Abuse |
|
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
|
| 29 Jan 2012 01:56 PM |
| So this script will make it so when the game starts and all online players get teleported to the spawn location i set it will add all alive players? And once they all die the script will end? |
|
|
| Report Abuse |
|
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
|
| 29 Jan 2012 01:57 PM |
| Where in a script would i add this? And how would I set what it would end? |
|
|
| Report Abuse |
|
|
|
| 29 Jan 2012 01:58 PM |
Simply call the function SetPlayersAlive after you teleport them, then call the function AllPlayersDead function to see if all the players have died.
-- teleport players SetPlayersAlive() repeat wait() until AllPlayersDead() -- EXAMPLE CODE |
|
|
| Report Abuse |
|
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
|
| 29 Jan 2012 02:00 PM |
ok so the
repeat wait() until AllPlayersDead()
will constantly check to see if all the players are dead and start my whole script back up to the point where
while true do
started it? |
|
|
| Report Abuse |
|
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
| |
|
|
| 29 Jan 2012 02:04 PM |
If that's the end of the while loop, then yes. Basically, the script will pause at that point, then continue on after all the players die. |
|
|
| Report Abuse |
|
|
harbar565
|
  |
| Joined: 05 Nov 2010 |
| Total Posts: 67 |
|
| |
|
KC9KVU
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 821 |
|
|
| 29 Jan 2012 02:37 PM |
| I am working on a script that I need something very similar to this, but I need to end the game on all but one players dead. I was wondering if somebody could help me and show me the difference in the two scripts. |
|
|
| Report Abuse |
|
|
KC9KVU
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 821 |
|
|
| 29 Jan 2012 03:07 PM |
And I also would like it to be able to say who was the last one left. If anybody could do this that would be AMAZING.
Thanks, KC |
|
|
| Report Abuse |
|
|
KC9KVU
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 821 |
|
| |
|