-
Notifications
You must be signed in to change notification settings - Fork 5
Example: CTF
This example assumes that you can follow the Basic Deathmatch example. This is not a rigorous tutorial, more just showing some of the ways to use the Minigames functions and round system.
This is a perfect example to use the RoundStart hook. At the very start of the round, this hook is called, and this will allow the flag to be respawned.
-- Reset the flag at the start of a round
hook.Add('RoundStart', 'InitialSpawnFlag', function()
GAMEMODE:SpawnFlag()
end)
In this gamemode, winning is triggered manually by a given condition (in this case, scoring a goal) rather than waiting until the very end of the round.
By calling GAMEMODE:EndRound() with the team that wins, the gamemode will consider this as a round win for that given team. In this gamemode, we also add an additional special message for the player that scored the goal.
This is also a good example of awarding stat points to players!
-- Triggered when a goal is scored
function GM:ScoreGoal(team, entity)
if GetGlobalString('RoundState') != 'InRound' then return end
local message = nil
-- Bonus to the person who scores the capture
if IsValid(GAMEMODE.LastCarrier) then
GAMEMODE.LastCarrier:AddFrags(3)
GAMEMODE.LastCarrier:AddStatPoints('CTFCaptures', 1)
message = GAMEMODE.LastCarrier:Nick() .. ' scored the capture'
end
-- End the round, counting a win for the given team
GAMEMODE:EndRound(team, message)
end
Getting Started Pages:
| Server Hosting
| Mapping
| Lua Development
|