Garry's Mod Wiki

server_spawn

Description

Called when joining a Server or when a Server spawned

This is only available in the Menu state because this is called before the Client or Server State has even started.

Members

string hostname
The hostname of the Server.
string address
The Server address. Will be loopback in hosted games.
number ip
The IP of the Server. Will be 0 in hosted games. Use the address instead of this.
number port
The port of the Server. Will be 0 in hosted games.
string game
The Game the Server is hosting. Will be garrysmod
string mapname
The mapname the Server is currently on.
number maxplayers
The amount of slots the server has.
string os
The OS of the Server. W(WIN32), L(LINUX) or O(OSX)
boolean dedicated
true if it's a dedicated server.
boolean password
true if the Server is password protected.

Examples

Example

This is a basic template with the purpose of including all arguments / table variables to make it easily known which values can be accessed. This Binary Module has been used.

require("gameevent") -- using a Binary Module because the Menu State doesn't has gameevent.Listen gameevent.Listen( "server_spawn" ) hook.Add( "server_spawn", "server_spawn_example", function( data ) local hostname = data.hostname // The hostname of the Server. local address = data.address // The Server address. local ip = data.ip // The Server IP. Use the address instead! local port = data.port // The Server Port. local game = data.game // The Game the Server is hosting. Should always be garrysmod. local mapname = data.mapname // The Mapname the Server is currently on. local maxplayers = data.maxplayers // The amount of slots the Server has. local os = data.os // The os the Server is running on. local dedicated = data.dedicated // true if the Server is a dedicated Server. local password = data.password // true if the Server is password protected. // Called while connecting to the Server. end )