Garry's Mod Wiki

duplicator

The duplicator library allows you to specify what should be saved when someone attempts to duplicate your custom entity with the duplicator tool. It can also be used by 3rd party duplicator tools to make use of the built in system.

Methods

duplicator.Allow( string classname )
Allow this entity to be duplicated
duplicator.ApplyBoneModifiers( Player ply, Entity ent )
Calls every function registered with duplicator.RegisterBoneModifier on each bone the ent has.
duplicator.ApplyEntityModifiers( Player ply, Entity ent )
Calls every function registered with duplicator.RegisterEntityModifier on the entity.
duplicator.ClearEntityModifier( Entity ent, any key )
Clears/removes the chosen entity modifier from the entity.
table duplicator.Copy( Entity ent, table tableToAdd = {} )
Copies the entity, and all of its constraints and entities, then returns them in a table.
table duplicator.CopyEnts( table ents )
Copies the passed table of entities to save for later.
table duplicator.CopyEntTable( Entity ent )
Returns a table with some entity data that can be used to create a new entity with duplicator.CreateEntityFromTable
Entity duplicator.CreateConstraintFromTable( table constraint, table entityList )
This is used internally - although you're able to use it you probably shouldn't. Creates a constraint from a saved/copied constraint table.
Entity duplicator.CreateEntityFromTable( Player ply, table entTable )
"Create an entity from a table." This creates an entity using the data in EntTable. If an entity factory has been registered for the entity's Class, it will be called. Otherwise, duplicator.GenericDuplicatorFunction will be called instead.
duplicator.DoBoneManipulator( Entity ent, table bones )
"Restores the bone's data." Loops through Bones and calls Entity:ManipulateBoneScale, Entity:ManipulateBoneAngles and Entity:ManipulateBonePosition on ent with the table keys and the subtable values s, a and p respectively.
duplicator.DoFlex( Entity ent, table flex, number scale = nil )
Restores the flex data using Entity:SetFlexWeight and Entity:SetFlexScale
duplicator.DoGeneric( Entity ent, table data )
"Applies generic every-day entity stuff for ent from table data." Depending on the values of Model, Angle, Pos, Skin, Flex, Bonemanip, ModelScale, ColGroup, Name, and BodyG (table of multiple values) in the data table, this calls Entity:SetModel, Entity:SetAngles, Entity:SetPos, Entity:SetSkin, duplicator.DoFlex, duplicator.DoBoneManipulator, Entity:SetModelScale, Entity:SetCollisionGroup, Entity:SetName, Entity:SetBodygroup on ent. If ent has a RestoreNetworkVars function, it is called with dat..
duplicator.DoGenericPhysics( Entity ent, Player ply = nil, table data )
"Applies bone data, generically." If data contains a PhysicsObjects table, it moves, re-angles and if relevent freezes all specified bones, first converting from local coordinates to world coordinates.
table duplicator.FindEntityClass( string name )
Returns the entity class factory registered with duplicator.RegisterEntityClass.
Entity duplicator.GenericDuplicatorFunction( Player ply, table data )
"Generic function for duplicating stuff" This is called when duplicator.CreateEntityFromTable can't find an entity factory to build with. It calls duplicator.DoGeneric and duplicator.DoGenericPhysics to apply standard duplicator stored things such as the model and position.
table, table duplicator.GetAllConstrainedEntitiesAndConstraints( Entity ent, table entStorageTable, table constraintStorageTable )
This is used internally - although you're able to use it you probably shouldn't. Fills entStorageTable with all of the entities in a group connected with constraints. Fills constraintStorageTable with all of the constrains constraining the group.
boolean duplicator.IsAllowed( string classname )
Returns whether the entity can be duplicated or not
table, table duplicator.Paste( Player Player, table EntityList, table ConstraintList )
"Given entity list and constraint list, create all entities and return their tables" Calls duplicator.CreateEntityFromTable on each sub-table of EntityList. If an entity is actually created, it calls ENTITY:OnDuplicated with the entity's duplicator data, then duplicator.ApplyEntityModifiers, duplicator.ApplyBoneModifiers and finally ENTITY:PostEntityPaste is called. The constraints are then created with duplicator.CreateConstraintFromTable.
duplicator.RegisterBoneModifier( any key, function boneModifier )
Registers a function to be called on each of an entity's bones when duplicator.ApplyBoneModifiers is called. This function is available to call on the client, but registered functions aren't used anywhere!
duplicator.RegisterConstraint( string name, function callback, any ... )
Register a function used for creating a duplicated constraint.
duplicator.RegisterEntityClass( string name, function function, vararg args )
This allows you to specify a specific function to be run when your SENT is pasted with the duplicator, instead of relying on the generic automatic functions. Automatically calls duplicator.Allow for the entity class.
duplicator.RegisterEntityModifier( string name, function func )
This allows you to register tweaks to entities. For instance, if you were making an "unbreakable" addon, you would use this to enable saving the "unbreakable" state of entities between duplications. This function registers a piece of generic code that is run on all entities with this modifier. In order to have it actually run, use duplicator.StoreEntityModifier. This function does nothing when run clientside.
duplicator.RemoveMapCreatedEntities()
Help to remove certain map created entities before creating the saved entities This is obviously so we don't get duplicate props everywhere. It should be called before calling Paste.
duplicator.SetLocalAng( Angle v )
"When a copy is copied it will be translated according to these. If you set them - make sure to set them back to 0 0 0!"
duplicator.SetLocalPos( Vector v )
"When a copy is copied it will be translated according to these. If you set them - make sure to set them back to 0 0 0!"
duplicator.StoreBoneModifier( Entity ent, number boneID, any key, table data )
Stores bone mod data for a registered bone modification function
duplicator.StoreEntityModifier( Entity entity, string name, table data )
Stores an entity modifier into an entity for saving
duplicator.WorkoutSize( table Ents )
"Work out the AABB size"

Page Links


Special Pages


Wikis

?

Render Time: 30ms

Session 0
DB GetPage 3
Generate Html 2
SaveChanges 11
Render Body 0
Render Sidebar 12