Garry's Mod Wiki

PropertyAdd

Description

Structure used for properties.Add.

Members

string Type
Can be set to "toggle" to make this property a toggle property.

Default: "simple"

string MenuLabel
Label to show on opened menu
string MenuIcon
Icon to show on opened menu for this item. Optional for simple properties and unused for toggle properties.
number StructureField (Order)
Where in the list should the property be positioned, relative to other properties.

For reference, here are the default properties and their Order values:

Property Order
Bone Manipulate 500
Bodygroups 600
Skin 601
Keep Upright 900
Ignite/Extinguish 999
Remove 1000
Gravity 1001
Drive 1100
Collision 1500
Statue 1501
NPC Biggify/Smallify 1799, 1800
Motion Control (Kinect) 2500
Edit Properties 90001
boolean PrependSpacer
Whether to add a spacer before this property. This should generally be true for the first property in a group of properties.

Default: false

function Filter
Used clientside to decide whether this property should be shown for an entity.

It's good practice to call GM:CanProperty in this hook via gamemode.Call or hook.Run.

Function argument(s):
1 table self - the property table
2 Entity ent - the entity the player clicked
3 LocalPlayer player - the localplayer
Function return value(s):
1 boolean check - Return true if the property should be shown for this entity.
function Checked
Required for toggle properties (clientside).
Function argument(s):
1 table self - the property table
2 Entity ent - the entity the player clicked
3 table tr - the player's eye trace
Function return value(s):
1 boolean check - Return true if the property should appear checked in the UI.
function Action
Called clientside when the property is clicked
Function argument(s):
1 table self - the property table
2 Entity ent - the entity the player clicked
3 table tr - the player's eye trace

When appropriate, within this function you can call self:MsgStart(), write data with the net.Write* functions, and finish with self:MsgEnd(). This will activate the Receive function on the server. In most cases, you will want to send the entity to the server, as it's not done by default.

function Receive
Called serverside if the client sends a message in the Action function (see above).
Function argument(s):
1 table self - the property table
2 number len - the net message length, although this includes the property identifier used internally (the name of the property)
3 Player ply - the player who clicked the property

You can read data received from the client with the net.Read* functions. It's good practice to check GM:CanProperty here via gamemode.Call or hook.Run.

function MenuOpen
Called clientside when the property option has been created in the right-click menu. This is not called for toggle properties!
Function argument(s):
1 table self - the property table
2 DMenuOption option - the menu option
3 Entity ent - the entity the player right-clicked
4 table tr - the player's eye trace
function OnCreate
Same as MenuOpen, but also called for toggle properties and has different arguments. This is called immediately after MenuOpen, but nothing happens in between so you should only ever use one or the other.
Function argument(s):
1 table self - the property table
2 DMenu menu - the property menu
3 DMenuOption option - the menu option