Garry's Mod Wiki

Map Lua

Maps can run Lua scripts via the lua_run entity.

Here's an example on gm_construct:

image.png

During the execution of the script, the following global variables are available:

-- The activator of the input (i.e. the player that pressed a button or walked into the trigger) print( ACTIVATOR ) -- The called or the input (i.e. button or the trigger that sent the input to this lua_run entity) print( CALLER ) -- Will be set to the ACTIVATOR, if it is a player. print( TRIGGER_PLAYER )

The code can be ran on entity spawn via a spawnflag, or via its RunCode input.

There's also the RunPassedCode input, which will run any code passed as the input value. Never use double-quotation marks in any Hammer Output, it will corrupt the map file. Try using Double Square brackets instead.