numpad/Register

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{Func |Name=Register |Parent=numpad |Description=Registers a numpad library action for use with numpad.OnDown and [[Libraries/numpad/OnUp| num...")
 
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{Func
 
{{Func
 +
|Description=Registers a numpad library action for use with {{LibraryFunction|numpad|OnDown}} and {{LibraryFunction|numpad|OnUp}}
 +
|Realm=Server
 +
|IsClass=No
 
|Name=Register
 
|Name=Register
 
|Parent=numpad
 
|Parent=numpad
|Description=Registers a numpad library action for use with [[Libraries/numpad/OnDown| numpad.OnDown]] and [[Libraries/numpad/OnUp| numpad.OnUp]].
 
|Realm=Server
 
|IsClass=No
 
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 15: Line 15:
 
|name=func
 
|name=func
 
|desc=The function to be executed.
 
|desc=The function to be executed.
}}
+
 
{{Example
+
Arguments are:<br>
| Description = Demonstrates the use of this function.
+
{{FuncArg|Player|ply|The player who pressed the button}}<br>
| Code = numpad.Register("my_action", function(ply, arg1) print(ply, arg1) end
+
{{FuncArg|vararg|...|The 4th and all subsequent arguments passed from {{LibraryFunction|numpad|OnDown}} and/or {{LibraryFunction|numpad|OnUp}}}}<br>
ents.FindByClass( "prop_physics" )[1].myAct = numpad.OnDown(player.GetByID(1), 38, "my_action", "arg1")
+
<br>
| Output = When player 1 presses his Numpad 1 key, something like this will be printed in console: "Player [1][Robot] arg1"
+
 
 +
Returning <b>false</b> in this function will remove the listener which triggered this function (example: return false if one of your varargs is an entity which is no longer valid)
 
}}
 
}}

Latest revision as of 06:45, 17 July 2016

 numpad.Register( )

Description

Registers a numpad library action for use with numpad.OnDown and numpad.OnUp

Arguments

string id

The unique id of your action.

Arguments

function func

The function to be executed.

Arguments are:
Player ply - The player who pressed the button
vararg ... - The 4th and all subsequent arguments passed from numpad.OnDown and/or numpad.OnUp

Returning false in this function will remove the listener which triggered this function (example: return false if one of your varargs is an entity which is no longer valid)
Personal tools
Navigation