undo.AddFunction

From GMod Wiki

Jump to: navigation, search
Function
Syntax undo.AddFunction( Function func, ... )
Where is this used?
Description:
Adds a function to call to the existing undo block.
Returns: nil
Part of Library: Undo
Realm: NewerServer.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Undo.AddFunction]Undo.AddFunction [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionSpawns a wooden box, and displays a what is passed to the function when the spawn is undone.
Used onNewerServer.png
Code
prop = ents.Create("prop_physics")
prop:SetModel("models/props_junk/wood_crate001a.mdl")
prop:Spawn()
undo.Create("prop")
    undo.AddEntity(prop)
    undo.AddFunction( PrintTable )
    undo.SetPlayer(Player)
undo.Finish()
Output
Owner	=	Player [1][Lexi]
Entities:
		1	=	Entity [58][prop_physics]
Name	=	prop
Functions:
		1:
				1	=	function: 02840A80
				2:
						n	=	0
DescriptionSlightly more advanced, uses the structure found by looking at the previous example and puts it to use
Used onNewerServer.png
Code
prop = ents.Create("prop_physics")
prop:SetModel("models/props_junk/wood_crate001a.mdl")
prop:Spawn()
undo.Create("prop")
    undo.AddEntity(prop)
    undo.AddFunction(function(undo)
		Msg(undo.Owner:GetName().." removed prop "..undo.Entities[1]:GetModel()..".\n")
	end)
    undo.SetPlayer(Player)
undo.Finish()
OutputLexi removed prop models/props_junk/wood_crate001a.mdl.


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox