duplicator.RegisterConstraint
Description
Register a function used for creating a duplicator-supported constraint.
Arguments
1 string name
The unique name of the new constraint. It will be used to identify which constraint to apply on duplicator load.
2 function callback
Function to be called when this constraint is created.
It is a good idea to check constraint.CanConstrain before doing anything else.
You must also call constraint.AddConstraintTable if creating custom constraint entities.
- This is what stores the constraint for duplicator to save and load, as well as for constraint.GetTable.
- The constraint entity must have
Typekey on it. This means that a single entity can only represent one constraint.
Optionally, the callback can return up to 4 entities, which are considered the "constraint" entities.
- Each of those is added to
"ropeconstraints"or"constraints"cleanup list based on entity's classname (Player:AddCleanup) - The first entity is added to the player's entity count (Player:AddCount) in Sandbox.
- None of these entities should be the 2 entities being constraint (i.e. a
prop_physics), but it can be one one of them if you know what you are doing.
3 vararg customData
Arguments to be passed to the callback function when the constraint is created via duplicator.CreateConstraintFromTable.
The data would be taken the constraint entity table added via constraint.AddConstraintTable. All constraint library constraints call it on the appropriate entity for you. (Typically its the first entity returned by the callback)
Example
Example of how to define a custom constraint. You apply the constraint via the custom constraint_MyCustomConstraint function, and it will automatically support duplicator.
Garry's Mod
Rust
Steamworks
Wiki Help