Garry's Mod Wiki

duplicator.RegisterConstraint

  duplicator.RegisterConstraint( string name, function callback, ... )

Description

Register a function used for creating a duplicated constraint.

Arguments

1 string name
The unique name of new constraint
2 function callback
Function to be called when this constraint is created
3 vararg customData
Arguments passed to the callback function

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.

function constraint_MyCustomConstraint( Ent1, Ent2, MyCoolData ) if ( !IsValid( Ent1 ) ) then return end if ( !IsValid( Ent2 ) ) then return end -- Your custom constraint code here, you can use "MyCoolData" here, as well as any custom arguments -- Just make sure to save each custom argument in the Ent2 table below, -- and add them to duplicator.RegisterConstraint below as well constraint.AddConstraintTable( Ent1, Ent2, Ent2 ) Ent2:SetTable( { Type = "MyCustomConstraint", Ent1 = Ent1, Ent2 = Ent2, MyCoolData = MyCoolData } ) return Ent2 end duplicator.RegisterConstraint( "MyCustomConstraint", constraint_MyCustomConstraint, "Ent1", "Ent2", "MyCoolData" )