Garry's Mod Wiki


The undo library allows you to add custom entities to the undo list, allowing users to "undo" their creation with their undo (default: z) key.


undo.AddEntity( Entity ent )
Adds an entity to the current undo block
undo.AddFunction( function func, vararg arguments )
Adds a function to call when the current undo block is undone. Note that if an undo has a function, the player will always be notified when this undo is performed, even if the entity it is meant to undo no longer exists.
undo.Create( string name )
Begins a new undo entry
number undo.Do_Undo( table tab )
Processes an undo block (in table form). This is used internally by the undo manager when a player presses Z. You should use gm_undo or gm_undonum *num* console commands instead of calling this function directly.
undo.Finish( string NiceText )
Completes an undo entry, and registers it with the player's client
table undo.GetTable()
Serverside, returns a table containing all undo blocks of all players. Clientside, returns a table of the local player's undo blocks. Serverside, this table's keys use Player:UniqueID to store a player's undo blocks.
This is used internally - although you're able to use it you probably shouldn't. Makes the UI dirty - it will re-create the controls the next time it is viewed.
boolean undo.ReplaceEntity( Entity from, Entity to )
Replaces any instance of the "from" reference with the "to" reference, in any existing undo block. Returns true if something was replaced
undo.SetCustomUndoText( string customText )
Sets a custom undo text for the current undo block
undo.SetPlayer( Player ply )
Sets the player which the current undo block belongs to
This is used internally - although you're able to use it you probably shouldn't. Adds a hook (CPanelPaint) to the control panel paint function so we can determine when it is being drawn.