Hi.
In my gamemode I have a round system and everything, but for the round system I need when the round begins I want everyone to respawn.
You'll see what I mean in a second.
My current code:
[lua]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )
function GM:PlayerInitialSpawn( ply )
ply:StripWeapons()
ply:SetTeam( 5 )
ply:ConCommand( "team_menu" )
end
function GM:PlayerDeathThink( ply )
end
function setSpec( ply )
ply:SetTeam( 5 )
ply:PrintMessage(HUD_PRINTCENTER, "You have died. You will respawn next round.")
end
hook.Add( "PlayerDeathThink", "roundDeath", setSpec )
function GM:PlayerSpawn( ply )
self.BaseClass:PlayerSpawn( ply )
local number = math.random(2)
ply:StripWeapons()
if number == 1 then
ply:Give("weapon_shotgun")
elseif number == 2 then
ply:Give("weapon_357")
end
ply:SetGravity(1)
ply:SetMaxHealth(100, true)
if ply:IsSuperAdmin() then
ply:SetArmor( 25 )
else
ply:SetArmor( 0 )
end
end
function GM:PlayerLoadout( ply )
ply:StripWeapons()
if ply:Team() == 1 then
ply:Give( "weapon_physcannon" )
elseif ply:Team() == 2 then
ply:Give( "weapon_physcannon" )
elseif ply:Team() == 3 then
ply:Give( "weapons_physcannon" )
elseif ply:Team() == 4 then
ply:Give( "weapons_physcannon" )
end
end
function team_1( ply )
ply:SetTeam( 1 )
ply:Spawn()
ply:PrintMessage(HUD_PRINTCENTER, "You have joined Team 1!")
end
function team_2( ply )
ply:SetTeam( 2 )
ply:Spawn()
ply:PrintMessage(HUD_PRINTCENTER, "You have joined Team 2!")
end
function team_3( ply )
ply:SetTeam( 3 )
ply:Spawn()
ply:PrintMessage(HUD_PRINTCENTER, "You have joined Team 3!")
end
function team_4( ply )
ply:SetTeam( 4 )
ply:Spawn()
ply:PrintMessage(HUD_PRINTCENTER, "You have joined Team 4!")
end
concommand.Add( "team_1", team_1 )
concommand.Add( "team_2", team_2 )
concommand.Add( "team_3", team_3 )
concommand.Add( "team_4", team_4 )
function dWeps( ply, cmd, args )
if args[1] == "shotgun" then
if ply:IsSuperAdmin() then
ply:Give("weapon_shotgun")
ply:ChatPrint("Enjoy your weaponary.")
else
ply:ChatPrint("You lack sufficient privileges.")
end
end
if args[1] == "pistol" then
if ply:IsSuperAdmin() then
ply:Give("weapon_357")
ply:ChatPrint("Enjoy your weaponary.")
else
ply:ChatPrint("You lack sufficient privileges.")
end
end
end
concommand.Add("d_wep", dWeps)
round = {}
round.Break = 15
round.Time = 180
round.TimeLeft = -1
round.Breaking = false
function round.Broadcast(Text)
for k, v in pairs(player.GetAll()) do
v:ConCommand("play buttons/button17.wav")
v:ChatPrint(Text)
end
end
function round.Begin()
round.Broadcast("Round starting! Round ends in " .. round.Time .. " seconds!")
round.TimeLeft = round.Time
end
function round.End()
round.Broadcast("The round has finished. Next round in " .. round.Break .. " seconds!")
round.TimeLeft = round.Break
end
function round.Handle()
if (round.TimeLeft == -1) then
round.Begin()
return
end
round.TimeLeft = round.TimeLeft - 1
if (round.TimeLeft == 0) then
if (round.Breaking) then
round.Begin()
round.Breaking = false
else
round.End()
round.Breaking = true
end
end
end
timer.Create("round.Handle", 1, 0, round.Handle)
concommand.Add("roundend", round.End)
concommand.Add("roundbegin", round.Begin)
[/lua]
So once again what I need is when the round begins, everybody that was dead will respawn.
I tried putting
[lua]
if round.Begin then
ply:Spawn
end
[/lua]
in
[lua]
function round.Begin()
round.Broadcast("Round starting! Round ends in " .. round.Time .. " seconds!")
round.TimeLeft = round.Time
end
[/lua]
but it did not work because there is no arguments for (ply) in the function round.Begin
When I tried adding the argument ply it just didn't work..
Help?
-snip, other post below-
[QUOTE=CrashLemon;38746036][lua]
roundTime = 200 -- Seconds
nextRoundTime = 20 -- Seconds
roundTimeLeft = roundTime
nextRoundTimeLeft = nextRound
function GM:Think()
if roundTimeLeft > 0 then
-- Countdown
roundTimeLife = roundTimeLeft - FrameTime()
-- Round is over
if roundTimeLeft <= 0 then nextRoundTimeLeft = nextRoundTime end
else
-- Countdown
nextRoundTimeLeft = nextRoundTimeLeft - FrameTime()
-- When the next round starts
if nextRoundTimeLeft <= 0 then
nextRoundFunction() -- Spawn players here
roundTimeLeft = roundTime
end
end
end[/lua]
Untested but should work. Put spawning stuff in nextRoundFunction()
[editline]8th December 2012[/editline]
Sry for indents, lua tags mess things up.[/QUOTE]
Wow i'm having an extremely hard time understanding this.
Do that instead
[lua]roundTime = 200 -- Lenght of a round (Seconds)
nextRoundTime = 20 -- Lenght between rounds (Seconds)
-- What happens when a round starts?
function RoundStart()
-- Put stuff here like spawning players.
-- Etc.
timer.Simple( roundTime, function() RoundEnd() end )
end
-- What happens when a round ends?
function RoundEnd()
-- Put stuff here like, I don't know.
-- This is "between rounds".
timer.Simple( nextRoundTime, function() RoundStart() end )
end[/lua]
[lua]
roundTime = 10 -- Lenght of a round (Seconds)
nextRoundTime = 20 -- Lenght between rounds (Seconds)
-- What happens when a round starts?
function RoundStart()
print("cunk")
-- Put stuff here like spawning players.
-- Etc.
timer.Simple( roundTime, function() RoundEnd() end )
end
-- What happens when a round ends?
function RoundEnd()
print("cunk")
-- Put stuff here like, I don't know.
-- This is "between rounds".
timer.Simple( nextRoundTime, function() RoundStart() end )
end
[/lua]
Why does this not work?
I'm probably just going to stick to buying scripts.
You have to call RoundStart() somewhere first, else it never starts.
Sorry, you need to Log In to post a reply to this thread.