Garry's Mod Wiki

game

The game library provides functions to access various features in the game's engine, most of it's functions are related to controlling the map.

Methods

game.AddAmmoType( table ammoData )
Adds a new ammo type to the game. You can find a list of default ammo types here. This function must be called shared or you will have unexpected problems.This function must be called in GM:Initialize.There is a limit of 128 ammo types, including the default ones.
game.AddDecal( string decalName, string materialName )
Registers a new decal. There's a rather low limit of around 256 for decal materials that may be registered and they are not cleared on map load.
game.AddParticles( string particleFileName )
Loads a particle file. You will still need to call this function clientside regardless if you create the particle effects serverside.
table game.BuildAmmoTypes()
This is used internally - although you're able to use it you probably shouldn't. Consider using game.GetAmmoTypes and game.GetAmmoData instead. Called by the engine to retrieve the ammo types.
game.CleanUpMap( boolean dontSendToClients = false, table ExtraFilters = {} )
If called serverside it will remove ALL entities which were not created by the map(not players or weapons held by players). On the client it will remove decals, sounds, gibs, dead NPCs, and entities created via ents.CreateClientProp. This function calls GM:PreCleanupMap before cleaning up the map and GM:PostCleanupMap after cleaning up the map. Calling this in a ENTITY:StartTouch or ENTITY:Touch hook will crash the game.Calling this destroys all BASS streams.This can crash when removing _firesmoke entities.
game.ConsoleCommand( string stringCommand )
Runs a console command. Make sure to add a newline ("\n") at the end of the command. If you use data that were received from a client, you should avoid using this function because newline and semicolon (at least) allow the client to run arbitrary commands! For safety, you are urged to prefer using RunConsoleCommand in this case.
number game.GetAmmoDamageType( number id )
Returns the damage type of given ammo type.
table game.GetAmmoData( number id )
Returns the Structures/AmmoData for given ID.
number game.GetAmmoForce( number id )
Returns the ammo bullet force that is applied when an entity is hit by a bullet of given ammo type.
number game.GetAmmoID( string name )
Returns the ammo type ID for given ammo type name. See game.GetAmmoName for reverse.
number game.GetAmmoMax( number id )
Returns the real maximum amount of ammo of given ammo ID. Currently all ammo types have overridden maximum value of reserve ammo set to 9999.
string game.GetAmmoName( number id )
Returns the ammo name for given ammo type ID. See game.GetAmmoID for reverse.
number game.GetAmmoNPCDamage( number id )
Returns the damage given ammo type should do to NPCs.
number game.GetAmmoPlayerDamage( number id )
Returns the damage given ammo type should do to players.
table game.GetAmmoTypes()
Returns a list of all ammo types currently registered.
number game.GetGlobalCounter( string name )
Returns the counter of a Global State. See Global States for more information.
number game.GetGlobalState( string name )
Returns whether a Global State is off, active or dead ( inactive ) See Global States for more information.
string game.GetIPAddress()
Returns the public IP address and port of the current server. This will return the IP/port that you are connecting through when ran clientside. Returns "0.0.0.0:0" in singleplayer.Returns "0.0.0.0:port" on the server when called too early, including in GM:Initialize and GM:InitPostEntity. This bug seems to only happen the first time a server is launched, and will return the correct value after switching maps.
string game.GetMap()
Returns the name of the current map, without a file extension. On the menu state, returns "menu".
string game.GetMapNext()
Returns the next map that would be loaded according to the file that is set by the mapcyclefile convar.
number game.GetMapVersion()
Returns the VBSP version of the current map.
number game.GetSkillLevel()
Returns the difficulty level of the game. TIP: You can use this function in your scripted NPCs or Nextbots to make them harder, however, it is a good idea to lock powerful attacks behind the highest difficulty instead of just increasing the health. Internally this is tied to the gamerules entity, so you'll have to wait to wait until GM:InitPostEntity is called to return the skill level
number game.GetTimeScale()
Returns the time scale of the game
Entity game.GetWorld()
Returns the worldspawn entity.
boolean game.IsDedicated()
Returns true if the server is a dedicated server, false if it is a or a singleplayer game. This always returns false on the client.
game.KickID( string id, string reason = "No reason given" )
Kicks a player from the server. This can be ran before the player has spawned.
game.LoadNextMap()
Loads the next map according to the nextlevel convar, or from the current mapcycle file set by the respective convar.
string game.MapLoadType()
Returns the map load type of the current map. After changing the map with the console command changelevel, "newgame" is returned. With changelevel2 (single player only), "transition" is returned.
number game.MaxPlayers()
Returns the maximum amount of players (including bots) that the server can have.
boolean, table game.MountGMA( string path )
Mounts a GMA addon from the disk. Can be used with steamworks.DownloadUGC Any error models currently loaded that the mounted addon provides will be reloaded. Any error materials currently loaded that the mounted addon provides will NOT be reloaded. That means that this cannot be used to fix missing map materials, as the map materials are loaded before you are able to call this.
game.RemoveRagdolls()
Removes all the clientside ragdolls.
game.SetGlobalCounter( string name, number count )
Sets the counter of a Global State. See Global States for more information.
game.SetGlobalState( string name, number state )
Sets whether a Global State is off, active or dead ( inactive ) See Global States for more information.
game.SetSkillLevel( number level )
Sets the difficulty level of the game, can be retrieved with game.GetSkillLevel. This will automatically change whenever the "skill" convar is modified serverside. This function will not work if the skill convar doesn't match the targeted value. To work around this, you must use RunConsoleCommand("skill", num) alongside this function.
game.SetTimeScale( number timeScale )
Sets the time scale of the game. This function is supposed to remove the need of using the host_timescale convar, which is cheat protected. To slow down or speed up the movement of a specific player, use Player:SetLaggedMovementValue instead. Like host_timescale, this method does not affect sounds, if you wish to change that, look into GM:EntityEmitSound.
boolean game.SinglePlayer()
Returns whenever the current session is a single player game.
Vector game.StartSpot()
Returns position the player should start from, this is not the same thing as spawn points, it is used to properly transit the player between maps.

Page Links


Special Pages


Wikis

?

Render Time: 30ms

DB GetPage 3
Generate Html 4
SaveChanges (1) 8
Render Body 0
Render Sidebar 12