mirror of
https://github.com/wiremod/wire.git
synced 2025-03-04 03:03:04 -05:00

In our entities, we do: DEFINE_BASECLASS("base_wire_entity") ...which is replaced by Garry's Mod by: local BaseClass = baseclass.Get("base_wire_entity") It also indirectly ends up setting `self.BaseClass` on the entity to its parent. Throughout our code we ignore the mysterious `local BaseClass` and instead use `self.BaseClass`. This works okay, until somebody uses one of *our* classes as a base: imagine, for example, somebody extended `gmod_wire_colorer`, which contains: function ENT:Think() self.BaseClass.Think(self) -- ... end In the extended entity, `self.BaseClass` points to `gmod_wire_colorer`, not to `base_wire_entity`, so this will be an infinite recursion. The solution is just to use the file-local `BaseClass` variable that's magically created for us.
45 lines
1.0 KiB
Lua
45 lines
1.0 KiB
Lua
AddCSLuaFile()
|
|
DEFINE_BASECLASS( "base_wire_entity" )
|
|
ENT.PrintName = "Wire Weight"
|
|
ENT.WireDebugName = "Weight"
|
|
|
|
if CLIENT then return end -- No more client
|
|
|
|
local MODEL = Model("models/props_interiors/pot01a.mdl")
|
|
|
|
function ENT:Initialize()
|
|
self:PhysicsInit( SOLID_VPHYSICS )
|
|
self:SetMoveType( MOVETYPE_VPHYSICS )
|
|
self:SetSolid( SOLID_VPHYSICS )
|
|
self.Inputs = Wire_CreateInputs(self,{"Weight"})
|
|
self.Outputs = Wire_CreateOutputs(self,{"Weight"})
|
|
self:ShowOutput(self:GetPhysicsObject():GetMass())
|
|
end
|
|
|
|
function ENT:TriggerInput(iname,value)
|
|
if(value>0)then
|
|
value = math.Clamp(value, 0.001, 50000)
|
|
local phys = self:GetPhysicsObject()
|
|
if ( phys:IsValid() ) then
|
|
phys:SetMass(value)
|
|
phys:Wake()
|
|
self:ShowOutput(value)
|
|
Wire_TriggerOutput(self,"Weight",value)
|
|
end
|
|
end
|
|
return true
|
|
end
|
|
|
|
function ENT:Think()
|
|
BaseClass.Think(self)
|
|
end
|
|
|
|
function ENT:Setup()
|
|
end
|
|
|
|
function ENT:ShowOutput(value)
|
|
self:SetOverlayText( "Weight: "..tostring(value) )
|
|
end
|
|
|
|
duplicator.RegisterEntityClass("gmod_wire_weight", WireLib.MakeWireEnt, "Data")
|