player_manager.RunClass

From Garry's Mod
Jump to: navigation, search
 player_manager.RunClass( )

Contents

Description

Execute a named function within the player's set class

Arguments

Player ply

Player to execute function on.

Arguments

string funcName

Name of function.

Arguments

vararg arguments

Optional arguments. Can be of any type.

Returns

vararg

The values returned by the called function.

Examples

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

Examples

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 !
Personal tools
Navigation