• Last Runner standing sound (DeathRun)
    20 replies, posted
Hello I currently have this script for all that end round stuff: [lua] hook.Add( "OnRoundSet", "Round Set Example", function( round, winner ) if round == ROUND_ENDING then if winner == TEAM_RUNNER then BroadcastLua('surface.PlaySound("runnerswin.mp3")') elseif winner == TEAM_DEATH then BroadcastLua('surface.PlaySound("deathwins.mp3")') elseif winner == 123 then -- If the winner is the timelimit, it will be the number 123. BroadcastLua('surface.PlaySound("sugar_dropit.wav")') end end end ) [/lua] But I was wondering if there was a way to make a script that would not mess up the code above, but play a song when there is only "ONE" runner left. (It would make it more action packed for teh Runners vs. Death final battle crap). and possibly broadcast text in the middle of all the players screens saying "The last Runner" or something like that. Thanks for your time.
Never messed with DeathRun, but if TEAM_RUNNER is the team's ID, then this will play an alternate clip if runners win and there's only 1 left, and the normal clip if there's more than 1. [lua]hook.Add( "OnRoundSet", "Round Set Example", function( round, winner ) if round == ROUND_ENDING then if winner == TEAM_RUNNER then if (table.Count(team.GetPlayers(TEAM_RUNNER)) == 1) then BroadcastLua('surface.PlaySound("thereseemstobeonlyonerunnerleft.mp3")') else BroadcastLua('surface.PlaySound("runnerswin.mp3")') end elseif winner == TEAM_DEATH then BroadcastLua('surface.PlaySound("deathwins.mp3")') elseif winner == 123 then -- If the winner is the timelimit, it will be the number 123. BroadcastLua('surface.PlaySound("sugar_dropit.wav")') end end end ) [/lua] Untested
[QUOTE=KingofBeast;41345244]Never messed with DeathRun, but if TEAM_RUNNER is the team's ID, then this will play an alternate clip if runners win and there's only 1 left, and the normal clip if there's more than 1. [lua]hook.Add( "OnRoundSet", "Round Set Example", function( round, winner ) if round == ROUND_ENDING then if winner == TEAM_RUNNER then if (table.Count(team.GetPlayers(TEAM_RUNNER)) == 1) then BroadcastLua('surface.PlaySound("thereseemstobeonlyonerunnerleft.mp3")') else BroadcastLua('surface.PlaySound("runnerswin.mp3")') end elseif winner == TEAM_DEATH then BroadcastLua('surface.PlaySound("deathwins.mp3")') elseif winner == 123 then -- If the winner is the timelimit, it will be the number 123. BroadcastLua('surface.PlaySound("sugar_dropit.wav")') end end end ) [/lua] Untested[/QUOTE] Okay, thanks. Ill test this as soon as I get home.
[lua]function LastRunner() if ( team.GetNumPlayers(TEAM_RUNNER) <= 1 ) then BroadcastLua('surface.PlaySound("your/sound/here.mp3")') end end hook.Add( "PlayerDeath", "LastrunnerSound", LastRunner ); hook.Add( "OnRoundSet", "Round Set Example", function( round, winner ) if round == ROUND_ENDING then if winner == TEAM_RUNNER then BroadcastLua('surface.PlaySound("runnerswin.mp3")') elseif winner == TEAM_DEATH then BroadcastLua('surface.PlaySound("deathwins.mp3")') elseif winner == 123 then -- If the winner is the timelimit, it will be the number 123. BroadcastLua('surface.PlaySound("sugar_dropit.wav")') end end end ) [/lua] Untested but KingofBeast's piece seems like it won't play because if the round is ending then, well the round is over
As said above the code won't work because the round is over and that's not what you want. This should work as you want although it may not be the most efficient possible. [code] hook.Add( "PlayerDeath", "playerDeathTest", function( victim, weapon, killer) if victim:Team() == TEAM_RUNNER then if (table.Count(team.GetPlayers(TEAM_RUNNER)) == 1) then for k, v in pairs(player.GetAll()) do if v:Alive() then if v:Team() == TEAM_RUNNER then last_runner = v BroadcastLua('surface.PlaySound("thereseemstobeonlyonerunnerleft.mp3")') for k, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, last_runner:Nick().."is the last runner!") end else last_runner = "" end end end end end end) [/code]
Why do you people use BroadcastLua? It's such a terrible thing to do. Also, 6 (should actually be 7) levels of identation? Really?
[QUOTE=EvacX;41350995]Why do you people use BroadcastLua? It's such a terrible thing to do. Also, 6 (should actually be 7) levels of identation? Really?[/QUOTE] I only used BroadcastLua because it was used previously; I'm not used to playing sounds. Also, I like to keep it neat and readable for me. If you care so much remove the indentation.
[code] hook.Add("PlayerDeath","iamtheoneandonly",function() local tab = team.GetPlayers(TEAM_RUNNER) local i = 0 for k,v in pairs(tab) do if v:Alive() then i = i + 1 end end if i == 1 then BroadcastLua("surface.PlaySound([[...]])") end end) [/code]
[QUOTE=Jarva;41351105]I only used BroadcastLua because it was used previously; I'm not used to playing sounds. Also, I like to keep it neat and readable for me. If you care so much remove the indentation.[/QUOTE] It's just unnecessary looping through the players that many times when this does the same exact thing [lua]hook.Add( "PlayerDeath", "playerDeathTest", function( victim, weapon, killer) if ( team.GetNumPlayers( TEAM_RUNNER ) >= 2 ) then return; end for k, v in pairs( player.GetAll() ) do if ( v:Alive() && v:Team() == TEAM_RUNNER ) then last_runner = v; break; end end BroadcastLua('surface.PlaySound("your/sound/here.mp3")') if ( !last_runner ) then return; end PrintMessage( HUD_PRINTTALK, last_runner:Name() .. " is the last runner!" ); end )[/lua]
[QUOTE=Co2;41351180][code] hook.Add("PlayerDeath","iamtheoneandonly",function() local tab = team.GetPlayers(TEAM_RUNNER) local i = 0 for k,v in pairs(tab) do if v:Alive() then i = i + 1 end end if i == 1 then BroadcastLua("surface.PlaySound([[...]])") end end) [/code][/QUOTE] This looks like a good way to do it. Didn't think mine was very efficient. [QUOTE=Annoyed Tree;41351254]It's just unnecessary looping through the players that many times when this does the same exact thing [lua]hook.Add( "PlayerDeath", "playerDeathTest", function( victim, weapon, killer) if ( team.GetNumPlayers( TEAM_RUNNER ) >= 2 ) then return; end for k, v in pairs( player.GetAll() ) do if ( v:Alive() && v:Team() == TEAM_RUNNER ) then last_runner = v; break; end end BroadcastLua('surface.PlaySound("your/sound/here.mp3")') if ( !last_runner ) then return; end PrintMessage( HUD_PRINTTALK, last_runner:Name() .. " is the last runner!" ); end )[/lua][/QUOTE] I'm still learning LUA so I don't know all the shortcuts. Did say it's probably not efficient.
[QUOTE=Jarva;41351261]This looks like a good way to do it. Didn't think mine was very efficient. I'm still learning LUA so I don't know all the shortcuts. Did say it's probably not efficient.[/QUOTE] Just food for thought. Not trying to insult you
IIRC team.GetNumPlayers returns a count of all players, not only alive ones.
So ill try this one 1st I guess: [lua] hook.Add( "PlayerDeath", "playerDeathTest", function( victim, weapon, killer) if victim:Team() == TEAM_RUNNER then if (table.Count(team.GetPlayers(TEAM_RUNNER)) == 1) then for k, v in pairs(player.GetAll()) do if v:Alive() then if v:Team() == TEAM_RUNNER then last_runner = v BroadcastLua('surface.PlaySound("thereseemstobeonlyonerunnerleft.mp3")') for k, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, last_runner:Nick().."is the last runner!") end else last_runner = "" end end end end end end) [/lua]
[QUOTE=Sgt. Sicknezz;41351639]So ill try this one 1st I guess: *code*[/QUOTE] It probably won't work as intended.
[QUOTE=Co2;41351770]It probably won't work as intended.[/QUOTE] True. Time to try the other codes....
This is really stupid. But I don't work with this type of Gamemode. Where would I put this? in round?
My apologies, I thought you just wanted an alternate sound to play at the end of the round if there's only one survivor. Not during the round. Untested [lua]function team.GetNumAlivePlayers(tm) local tab = team.GetPlayers(tm) or {} local alive = 0 local alivetab = {} for k, v in pairs(tab) do if (v:Alive()) then alive = alive + 1 table.insert(alivetab, v) end end return alive, alivetab end hook.Add("PlayerDeath", "LastRunnerStanding", function(p) if (p:Team() == TEAM_RUNNER) then local alive, alivetab = team.GetNumAlivePlayers(TEAM_RUNNER) if (alive == 1) then BroadcastLua('surface.PlaySound("thereseemstobeonlyonerunnerleft.mp3")') for k, v in pairs(player.GetAll()) do v:PrintMessage(HUD_PRINTCENTER, alivetab[1]:Name() .. "is the runners' last hope!") end end end end)[/lua]
Sorry once again where do I put this scrpit? ^-^"
[QUOTE=SatoshiAaron;41380227]Sorry once again where do I put this scrpit? ^-^"[/QUOTE] lua/autorun/server
[QUOTE=Sgt. Sicknezz;41380683]lua/autorun/server[/QUOTE] I though it would have had to go in the gamemode somewhere... Thanks <3
[QUOTE=SatoshiAaron;41382301]I though it would have had to go in the gamemode somewhere... Thanks <3[/QUOTE] No problem. :smile:
Sorry, you need to Log In to post a reply to this thread.