-
Notifications
You must be signed in to change notification settings - Fork 5
Example: Basic Deathmatch
This page is a basic quick-start guide to writing a super simple gamemode that works with the Minigames system.
Garry's Mod requires gamemode folders to be in a certain specific structure. It's probably easiest to just copy and paste one of the basic gamemodes in this repository and use it as a base.
At the root of each gamemode folder, you'll need a [name].txt file which looks something like this:
"minigames"
{
"base" "fluffy_mg_base"
"title" "[Gamemode Name Here]"
"maps" "^prefix_"
}
Inside the folder you'll then need a gamemode/ folder which contains all the gamemode files. You must have cl_init.lua, init.lua, and shared.lua.
shared.lua is the best place to start with writing a gamemode, as this is where all the basic properties of the gamemode can be adjusted. The Minigames base has a surprising amount of round logic based in to cover a lot of cases, so unless you're making something with truly unique round structure you should be able to get by.
For our gamemode, we'll be going with a basic FFA deathmatch system. The player with the most points at the end of the round wins the round. This is a basic gamemode, so the main thing is to ensure that GM.Elimination is false.
DeriveGamemode('fluffy_mg_base')
GM.Name = 'Example Deathmatch'
GM.Author = 'FluffyXVI'
GM.HelpText = [[
Super simple example tutorial gamemode
]]
GM.TeamBased = true
GM.Elimination = false
GM.RoundNumber = 5
GM.RoundTime = 90
For a full list of properties that can be configured in this file, check out the Gamemode Properties page
Since we're not doing anything special with rendering, this file only needs to include shared.lua
include('shared.lua')
Make sure that all the files are sent to clients and that the shared file is included in this file.
AddCSLuaFile('cl_init.lua')
AddCSLuaFile('shared.lua')
include('shared.lua')
Since our gamemode is so simple, most of what we want is already handled in the base gamemode! By default, the base picks the player with the most kills to be the winner at the end of a round - this mimics what we want to do. All our gamemode really needs to do is give some weapons to the players!
function GM:PlayerLoadout( ply )
ply:Give('weapon_mg_knife')
ply:Give('weapon_mg_pistol')
ply:GiveAmmo(1000, 'Pistol')
end
Assuming that all the files are in the right spots, this should be all you need to create a gamemode! Obviously this is an incredibly simple gamemode, and creating gamemodes that are more nuanced than just a simple deathmatch will require a lot more overwriting - but this is the basics.
I strongly believe in learning by example - opening up some of the currently created gamemodes and seeing what they do is probably the best way to figure out what makes Minigames tick.
Getting Started Pages:
| Server Hosting
| Mapping
| Lua Development
|