Hello.
I am trying to make a simple deathmatch gamemode.
My question is, how do I make a team win and then start a new round, when a team gets x point?
Compare the points after each time they get changed ( you add or remove a point in code ) by calling a function that will compare if there's a winner, if there is, do stuff, otherwise bail with return.
if team.GetScore(teamid) > 50 then win end
teamid would be either ply:Team() or the number you pass to team.SetUp.
[QUOTE=siraggi;46068150]Hello.
I am trying to make a simple deathmatch gamemode.
My question is, how do I make a team win and then start a new round, when a team gets x point?[/QUOTE]
How do you have a round system set up yet? What's the code for it?
This is what I got so far:
[code]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
include("player.lua")
local round = {}
round.Break = 2
round.Time = 10
local teamOnePoints = 0
local teamTwoPoints = 0
local winningTeam = ""
function GM:PlayerConnect(name, ip)
print("Player: " .. name .. " has joined the game.")
end
function GM:PlayerInitialSpawn(ply)
print("Player: " .. ply:Nick() .. " has spawned")
ply:SetModel("models/player/group01/male_09.mdl")
end
function GM:PlayerSpawn(ply)
ply:SetupHands()
ply:GiveGamemodeWeapons()
ply:ChatPrint("You are on team " .. team.GetName(ply:Team()))
if team.NumPlayers(0) > team.NumPlayers(1) + 1 then
ply:SetGamemodeTeam(1)
else
ply:SetGamemodeTeam(0)
end
end
function GM:PlayerAuthed(ply, steamID, uniqueID)
print("Player: " .. ply:Nick() .. " has gotten authed")
end
function GM:PlayerDeath(ply)
if ply:Team() == 0 then
print("Team two gets a point")
teamTwoPoints = teamTwoPoints + 1
print("Team two now have " .. teamTwoPoints)
else
print("Team one gets a point")
teamOnePoints = teamOnePoints + 1
print("Team one now have " .. teamOnePoints)
end
end
function GM:PlayerShouldTakeDamage(victim, ply)
if ply:IsPlayer() then
if ply:Team() == victim:Team() then
return false
end
end
return true
end
function round.Broadcast(Text)
for k, v in pairs(player.GetAll()) do
v:ChatPrint(Text)
end
end
function round.Begin()
round.Broadcast("A new round is starting! The team with most points in " .. round.Time .. " seconds, win!")
timer.Simple(round.Time, function() round.End() end)
end
function round.End()
if teamOnePoints > teamTwoPoints then
winningTeam = team.GetName(0)
round.Broadcast("Rounder over! Team " .. winningTeam .. " won!")
elseif teamOnePoints < teamTwoPoints then
winningTeam = team.GetName(1)
round.Broadcast("Rounder over! Team " .. winningTeam .. " won!")
else
round.Broadcast("Rounder over! It is a draw!")
end
round.Broadcast("Next round in " .. round.Break .. " seconds!")
teamOnePoints = 0
teamTwoPoints = 0
game.CleanUpMap()
timer.Simple(round.Break, function() round.Begin() end)
end
round.Begin()
[/code]
What I need now, is a way to respawn all players after the round ends.
At the end of the round loop through all the players and then call the spawn function on them.
[url]http://wiki.garrysmod.com/page/player/GetAll[/url]
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8fea.html[/url]
[QUOTE=Jeezy;46074067]At the end of the round loop through all the players and then call the spawn function on them.
[url]http://wiki.garrysmod.com/page/player/GetAll[/url]
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8fea.html[/url][/QUOTE]
It works. Thank you :D
Sorry, you need to Log In to post a reply to this thread.