Custom entities, advanced duplicator 2, and wiremod.
1 replies, posted
So I've been working on some custom entities that have a few wire inputs/outputs. Unfortunately, when I save and spawn the contraption with Adv Dupe 2, the entity spawns in unwired. Does anyone have experience with this? I'm not sure where to even begin, so any help is appreciated.
I suggest looking at source code of some simple wiremod entity, like Wire User. These are the bits you should be paying attention to:
[code]
DEFINE_BASECLASS( "base_wire_entity" )
[/code]
[code]
duplicator.RegisterEntityClass("gmod_wire_user", WireLib.MakeWireEnt, "Data", "Range")
[/code]
There's another way with manually setting up all duplicator stuff without deriving from Wire Base but it's more complex. Something like this:
[code]
function ENT:BuildDupeInfo()
local info = WireLib.BuildDupeInfo(self) or {}
--Store your custom dupe info if needed
return info
end
function ENT:ApplyDupeInfo(ply, ent, info, GetEntByID)
-- Do something with info if needed
WireLib.ApplyDupeInfo(ply, ent, info, GetEntByID)
end
function ENT:PreEntityCopy()
local info = self:BuildDupeInfo()
if not info then return end
duplicator.StoreEntityModifier(self, "SomeName", info)
end
local function EntLookup(created)
return function(id, def)
local ent = created[id]
return (IsValid(ent) and ent or def)
end
end
function ENT:PostEntityPaste(ply, ent, created)
-- Notice "SomeName", it's the same as what you passed to StoreEntityModifier
if ent.EntityMods and ent.EntityMods.SomeName then
ent:ApplyDupeInfo(ply, ent, ent.EntityMods.SomeName, EntLookup(created))
end
end
[/code]
Sorry, you need to Log In to post a reply to this thread.