Garry's Mod Wiki

player_manager.RunClass

  vararg player_manager.RunClass( Player ply, string funcName, ... )

Description

Execute a named function within the player's set class

Arguments

1 Player ply
Player to execute function on.
2 string funcName
Name of function.
3 vararg arguments
Optional arguments. Can be of any type.

Returns

1 vararg
The values returned by the called function.

Example

Run the player's class 'Loadout' function when PlayerLoadout is called

function GM:PlayerLoadout( ply ) player_manager.RunClass( ply, "Loadout" ) end
Output: The player's class 'Loadout' function is executed

Example

Call a greeting function within the playerclass system.

local PLAYER = {} PLAYER.DisplayName = "Hooman" PLAYER.WalkSpeed = 200 PLAYER.greet = function( tbl ) // create a function named 'greet' // the first argument passed is the source table // which includes the classID, the player entity, and the function itself local ply = tbl.Player // here we extract the player entity from the table ply:ChatPrint("Hello "..ply:Nick().." !") // tell the player end // link it to the spawn hook, so each time a player (re-)spawns, he will be greeted with a hello hook.Add("PlayerSpawn","greet",function(ply) player_manager.RunClass( ply, "greet" ) end)
Output: Hello Flowx !