Revision Difference
duplicator.RegisterConstraint#561499
<function name="RegisterConstraint" parent="duplicator" type="libraryfunc">
<description>Register a function used for creating a duplicated constraint.</description>
<realm>Shared</realm>
<file line="367-L374">lua/includes/modules/duplicator.lua</file>
<args>
<arg name="name" type="string">The unique name of new constraint</arg>
<arg name="callback" type="function">Function to be called when this constraint is created</arg>
<arg name="customData" type="vararg">Arguments passed to the callback function</arg>
</args>
</function>
<example>
<description>Example of how to define a custom constraint. You apply the constraint via the custom `constraint_MyCustomConstraint` function, and it will automatically support duplicator.</description>
<code>
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" )
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" )
</code>
</example>