diff --git a/lua/entities/gmod_wire_ranger.lua b/lua/entities/gmod_wire_ranger.lua index 3a5d33f507..105e03dde9 100644 --- a/lua/entities/gmod_wire_ranger.lua +++ b/lua/entities/gmod_wire_ranger.lua @@ -1,128 +1,124 @@ AddCSLuaFile() -DEFINE_BASECLASS( "base_wire_entity" ) -ENT.PrintName = "Wire Ranger" + +DEFINE_BASECLASS("base_wire_entity") +ENT.PrintName = "Wire Ranger" +ENT.WireDebugName = "Ranger" ENT.WantsTranslucency = true -ENT.WireDebugName = "Ranger" function ENT:SetupDataTables() - self:NetworkVar( "Float", 0, "BeamLength" ) - self:NetworkVar( "Bool", 0, "ShowBeam" ) - self:NetworkVar( "Float", 1, "SkewX" ) - self:NetworkVar( "Float", 2, "SkewY" ) - self:NetworkVar( "Vector", 0, "Target" ) + self:NetworkVar("Float", 0, "BeamLength") + self:NetworkVar("Bool", 0, "ShowBeam") + self:NetworkVar("Vector", 0, "Target") + self:NetworkVar("Bool", 1, "TraceWater") + self:NetworkVar("Float", 1, "SkewX") + self:NetworkVar("Float", 2, "SkewY") end -if CLIENT then return end -- No more client +if CLIENT then return end function ENT:Initialize() - self:PhysicsInit( SOLID_VPHYSICS ) - self:SetMoveType( MOVETYPE_VPHYSICS ) - self:SetSolid( SOLID_VPHYSICS ) - self:StartMotionController() - - self.Inputs = WireLib.CreateInputs(self, { - "X", "Y", "SelectValue", "Length", - "Target [VECTOR]", - "Ignore (Adds all specified entities to the ranger's filter.\nKeep in mind that this filtering is not synced to the client and is therefore not visible in the ranger's beam.) [ARRAY]" - }) - self.Outputs = WireLib.CreateOutputs(self, { "Dist" }) + self:PhysicsInit(SOLID_VPHYSICS) + WireLib.CreateInputs(self, { "X", "Y", "SelectValue", "Length", "Target [VECTOR]", "Ignore (Adds all specified entities to the ranger's filter.\nKeep in mind that this filtering is not synced to the client and is therefore not visible in the ranger's beam.) [ARRAY]" }) + WireLib.CreateOutputs(self, { "Dist" }) self.hires = false end -function ENT:Setup( range, default_zero, show_beam, ignore_world, trace_water, out_dist, out_pos, out_vel, out_ang, out_col, out_val, out_sid, out_uid, out_eid, out_hnrm, hiRes ) - --for duplication - self.default_zero = default_zero - self.show_beam = show_beam - self.ignore_world = ignore_world - self.trace_water = trace_water - self.out_dist = out_dist - self.out_pos = out_pos - self.out_vel = out_vel - self.out_ang = out_ang - self.out_col = out_col - self.out_val = out_val - self.out_sid = out_sid - self.out_uid = out_uid - self.out_eid = out_eid - self.out_hnrm = out_hnrm - self.hires = hiRes - - self.PrevOutput = nil - - if range then self:SetBeamLength(math.min(range, 64000)) end - if show_beam ~= nil then self:SetShowBeam(show_beam) end - - self:SetNWBool("TraceWater", trace_water) +function ENT:Setup(range, default_zero, show_beam, ignore_world, trace_water, out_dist, out_pos, out_vel, out_ang, out_col, out_val, out_sid, out_uid, out_eid, out_hnrm, hires) + -- For dupe support + local tab = self:GetTable() + tab.default_zero = default_zero + tab.show_beam = show_beam + tab.ignore_world = ignore_world + tab.trace_water = trace_water + tab.out_dist = out_dist + tab.out_pos = out_pos + tab.out_vel = out_vel + tab.out_ang = out_ang + tab.out_col = out_col + tab.out_val = out_val + tab.out_sid = out_sid + tab.out_uid = out_uid + tab.out_eid = out_eid + tab.out_hnrm = out_hnrm + tab.hires = hires + + if range then tab.SetBeamLength(self, math.min(range, 65536)) end + if show_beam ~= nil then tab.SetShowBeam(self, show_beam) end + if trace_water ~= nil then tab.SetTraceWater(self, trace_water) end local onames, otypes = {}, {} - local function add(...) - local args = {...} - for i=1,#args,2 do - onames[#onames+1] = args[i] - otypes[#otypes+1] = args[i+1] + local args = { ... } + + for i = 1, #args, 2 do + table.insert(onames, args[i]) + table.insert(otypes, args[i + 1]) end end + if out_dist then + add("Dist", "NORMAL") + end - if (out_dist) then add("Dist","NORMAL") end - if (out_pos) then - add("Pos", "VECTOR", - "Pos X", "NORMAL", - "Pos Y", "NORMAL", - "Pos Z", "NORMAL") + if out_pos then + add("Pos", "VECTOR", "Pos X", "NORMAL", "Pos Y", "NORMAL", "Pos Z", "NORMAL") end - if (out_vel) then - add("Vel","VECTOR", - "Vel X","NORMAL", - "Vel Y","NORMAL", - "Vel Z","NORMAL") + + if out_vel then + add("Vel", "VECTOR", "Vel X","NORMAL", "Vel Y", "NORMAL", "Vel Z", "NORMAL") end - if (out_ang) then - add("Ang","ANGLE", - "Ang Pitch","NORMAL", - "Ang Yaw","NORMAL", - "Ang Roll","NORMAL") + + if out_ang then + add("Ang", "ANGLE", "Ang Pitch", "NORMAL", "Ang Yaw", "NORMAL", "Ang Roll", "NORMAL") end - if (out_col) then - add("Col RGB","VECTOR", - "Col R","NORMAL", - "Col G","NORMAL", - "Col B","NORMAL", - "Col A","NORMAL") + + if out_col then + add("Col RGB", "VECTOR", "Col R","NORMAL", "Col G", "NORMAL", "Col B", "NORMAL", "Col A", "NORMAL") end - if (out_val) then add("Val","NORMAL","ValSize","NORMAL") end - if (out_sid) then add( "SteamID", "STRING" ) end - if (out_uid) then add( "UniqueID","NORMAL" ) end - if (out_eid) then add( "EntID", "NORMAL", "Entity", "ENTITY" ) end - if (out_hnrm) then - add("HitNormal","VECTOR", - "HitNormal X","NORMAL", - "HitNormal Y","NORMAL", - "HitNormal Z","NORMAL") + + if out_val then + add("Val", "NORMAL", "ValSize", "NORMAL") end - add( "RangerData", "RANGER" ) + + if out_sid then + add("SteamID", "STRING") + end + + if out_uid then + add("UniqueID", "NORMAL") + end + + if out_eid then + add("EntID", "NORMAL", "Entity", "ENTITY") + end + + if out_hnrm then + add("HitNormal", "VECTOR", "HitNormal X", "NORMAL", "HitNormal Y", "NORMAL", "HitNormal Z", "NORMAL") + end + + add("RangerData", "RANGER") WireLib.AdjustSpecialOutputs(self, onames, otypes) - self:TriggerOutput(0, Vector(0, 0, 0), Vector(0, 0, 0), Angle(0, 0, 0), Color(255, 255, 255, 255),nil,"",0,NULL, Vector(0, 0, 0),nil) - self:ShowOutput(0, Vector(0, 0, 0), Vector(0, 0, 0), Angle(0, 0, 0), Color(255, 255, 255, 255),nil,"",0,NULL, Vector(0, 0, 0),nil) + tab.TriggerOutput(self, 0, Vector(0, 0, 0), Vector(0, 0, 0), Angle(0, 0, 0), Color(255, 255, 255), nil, "", 0, NULL, Vector(0, 0, 0), nil, tab) end -function ENT:TriggerInput(iname, value) - if (iname == "X") then +function ENT:TriggerInput(name, value) + if name == "X" then self:SetSkewX(value) - elseif (iname == "Y") then + elseif name == "Y" then self:SetSkewY(value) - elseif (iname == "Length") then + elseif name == "Length" then self:SetBeamLength(math.min(value, 64000)) - elseif (iname == "Target") then + elseif name == "Target" then self:SetTarget(value) - elseif (iname == "Ignore") then - self.ignore = { self } - for k,v in ipairs(value) do - if IsEntity(v) and IsValid(v) then - self.ignore[#self.ignore+1] = v + elseif name == "Ignore" then + local ignore = { self } + self.ignore = ignore + + for _, ent in ipairs(value) do + if isentity(ent) and ent:IsValid() then + table.insert(ignore, ent) end end end @@ -131,140 +127,190 @@ end function ENT:Think() BaseClass.Think(self) + local tab = self:GetTable() + local trace_output = tab.TraceOutput + + if not trace_output then + trace_output = {} + tab.TraceOutput = trace_output + end + local tracedata = {} - tracedata.start = self:GetPos() - if self.Inputs.Target.Value ~= vector_origin then - tracedata.endpos = self:GetPos()+(self:GetTarget()-self:GetPos()):GetNormalized()*self:GetBeamLength() - if tracedata.endpos[1] ~= tracedata.endpos[1] then tracedata.endpos = self:GetPos()+Vector(self:GetBeamLength(), 0, 0) end - elseif (self.Inputs.X.Value == 0 and self.Inputs.Y.Value == 0) then - tracedata.endpos = tracedata.start + self:GetUp() * self:GetBeamLength() + tracedata.output = tab.TraceOutput + + local selfpos = self:GetPos() + tracedata.start = selfpos + + local inputs = tab.Inputs + local beamlength = tab.GetBeamLength(self) + + if inputs.Target.Value ~= vector_origin then + local endpos = self:GetTarget() + endpos:Sub(selfpos) + endpos:Normalize() + endpos:Mul(beamlength) + endpos:Add(selfpos) + tracedata.endpos = endpos + elseif inputs.X.Value == 0 and inputs.Y.Value == 0 then + local endpos = self:GetUp() + endpos:Mul(beamlength) + endpos:Add(selfpos) + tracedata.endpos = endpos else - local skew = Vector(self.Inputs.X.Value, self.Inputs.Y.Value, 1) - skew = skew*(self:GetBeamLength()/skew:Length()) - local beam_x = self:GetRight()*skew.x - local beam_y = self:GetForward()*skew.y - local beam_z = self:GetUp()*skew.z - tracedata.endpos = tracedata.start + beam_x + beam_y + beam_z + local skew = Vector(inputs.X.Value, inputs.Y.Value, 1) + skew:Mul(beamlength / skew:Length()) + + local x, y, z = skew:Unpack() + + local beam_x = self:GetRight() + beam_x:Mul(x) + + local beam_y = self:GetForward() + beam_y:Mul(y) + + local beam_z = self:GetUp() + beam_z:Mul(z) + + beam_x:Add(beam_y) + beam_x:Add(beam_z) + beam_x:Add(selfpos) + + tracedata.endpos = beam_x end - tracedata.filter = self.ignore or { self } - if (self.trace_water) then tracedata.mask = -1 end + + tracedata.filter = tab.ignore or { self } + if tab.trace_water then tracedata.mask = -1 end + local trace = util.TraceLine(tracedata) trace.RealStartPos = tracedata.start - local dist = 0 - local pos = Vector(0, 0, 0) - local vel = Vector(0, 0, 0) - local ang = Angle(0, 0, 0) - local col = Color(255, 255, 255, 255) - local ent = NULL - local sid = "" - local uid = 0 - local val = {} - local hnrm = Vector(0,0,0) - - if (trace.Hit) then - dist = trace.Fraction * self:GetBeamLength() + local dist, pos, vel, ang, col, ent, sid, uid, val, hnrm + + if trace.Hit then + dist = trace.Fraction * beamlength pos = trace.HitPos hnrm = trace.HitNormal ent = trace.Entity - if (ent:IsValid()) then - + if ent:IsValid() then vel = ent:GetVelocity() ang = ent:GetAngles() col = ent:GetColor() - if (self.out_sid or self.out_uid) and (ent:IsPlayer()) then - sid = ent:SteamID() or "" - uid = tonumber(ent:UniqueID()) or -1 + if (tab.out_sid or tab.out_uid) and ent:IsPlayer() then + sid = ent:SteamID() + uid = ent:UniqueID() end - if (self.out_val and ent.Outputs) then + if tab.out_val and tab.Outputs then local i = 1 - for k,v in pairs(ent.Outputs) do - if (v.Value ~= nil and type(v.Value) == "number") then - val[i] = v.Value + val = {} + + for _, output in pairs(tab.Outputs) do + if output.Value ~= nil and isnumber(output.Value) then + val[i] = output.Value i = i + 1 end end end - - elseif(self.ignore_world) then - if (trace.HitWorld) then - if (self.default_zero) then - dist = 0 - else - dist = self:GetBeamLength() - end - pos = Vector(0,0,0) + elseif tab.ignore_world and trace.HitWorld then + if tab.default_zero then + dist = 0 + else + dist = beamlength end end - else - if (not self.default_zero) then - dist = self:GetBeamLength() + if tab.default_zero then + dist = 0 + else + dist = beamlength end end - self:TriggerOutput(dist, pos, vel, ang, col, val, sid, uid, ent, hnrm, trace) - self:ShowOutput(dist, pos, vel, ang, col, val, sid, uid, ent, hnrm, trace) + tab.TriggerOutput(self, dist, pos, vel, ang, col, val, sid, uid, ent, hnrm, trace, tab) + + if tab.OverlayDataRequired then + if not pos then pos = Vector(0, 0, 0) end + if not vel then vel = Vector(0, 0, 0) end + if not ang then ang = Angle(0, 0, 0) end + if not col then col = Color(255, 255, 255) end + if not hnrm then hnrm = Vector(0, 0, 0) end + + local txt = "Max Range: " .. beamlength + if tab.out_dist then txt = txt .. "\nRange = " .. math.Round(dist, 3) end + if tab.out_pos then txt = txt .. string.format("\nPosition = %s, %s, %s", math.Round(pos.x, 3), math.Round(pos.y, 3), math.Round(pos.z, 3)) end + if tab.out_vel then txt = txt .. string.format("\nVelocity = %s, %s, %s", math.Round(vel.x, 3), math.Round(vel.y, 3), math.Round(vel.z, 3)) end + if tab.out_ang then txt = txt .. string.format("\nAngles = %s, %s, %s", math.Round(ang.pitch, 3), math.Round(ang.yaw, 3), math.Round(ang.roll, 3)) end + if tab.out_col then txt = txt .. string.format("\nColor = %s, %s, %s, %s", math.Round(col.r), math.Round(col.g), math.Round(col.b), math.Round(col.a)) end + if tab.out_val then txt = txt .. string.format("\nValue = %s ValSize = %s", math.Round(tab.Outputs["Val"].Value or 0, 3), val and #val or 0) end + if tab.out_sid then txt = txt .. "\nSteamID = " .. (sid or "") end + if tab.out_uid then txt = txt .. "\nUniqueID = " .. (uid or 0) end + if tab.out_eid then txt = txt .. "\nEntID = " .. (ent and ent:EntIndex() or 0) end + if tab.out_hnrm then txt = txt .. string.format("\nHitNormal = %s, %s, %s", math.Round(hnrm.x, 3), math.Round(hnrm.y, 3), math.Round(hnrm.z, 3)) end + tab.OverlayDataRequired = nil + tab.SetOverlayText(self, txt) + end - if (self.hires) then + if tab.hires then self:NextThink(CurTime()) else - self:NextThink(CurTime()+0.04) + self:NextThink(CurTime() + 0.04) end return true end -local round = math.Round - -function ENT:ShowOutput(dist, pos, vel, ang, col, val, sid, uid, ent, hnrm, trace) - local txt = "Max Range: " .. self:GetBeamLength() - - if (self.out_dist) then txt = txt .. "\nRange = " .. round(dist,3) end - if (self.out_pos) then txt = txt .. string.format("\nPosition = %s, %s, %s", round(pos.x,3), round(pos.y,3), round(pos.z,3)) end - if (self.out_vel) then txt = txt .. string.format("\nVelocity = %s, %s, %s", round(vel.x,3), round(vel.y,3), round(vel.z,3)) end - if (self.out_ang) then txt = txt .. string.format("\nAngles = %s, %s, %s", round(ang.pitch,3), round(ang.yaw,3), round(ang.roll,3)) end - if (self.out_col) then txt = txt .. string.format("\nColor = %s, %s, %s, %s", round(col.r), round(col.g), round(col.b), round(col.a)) end - if (self.out_val) then txt = txt .. string.format("\nValue = %s ValSize = %s", round(self.Outputs["Val"].Value or 0,3), #(val or {}) ) end - if (self.out_sid) then txt = txt .. "\nSteamID = " .. (sid or "") end - if (self.out_uid) then txt = txt .. "\nUniqueID = " .. (uid or 0) end - if (self.out_eid) then txt = txt .. "\nEntID = " .. ent:EntIndex() end - if (self.out_hnrm) then txt = txt .. string.format("\nHitNormal = %s, %s, %s", round(hnrm.x,3), round(hnrm.y,3), round(hnrm.z,3)) end - - self:SetOverlayText(txt) +function ENT:PrepareOverlayData() + self.OverlayDataRequired = true end -function ENT:TriggerOutput(dist, pos, vel, ang, col, val, sid, uid, ent, hnrm, trace) - - if (self.out_dist) then +function ENT:TriggerOutput(dist, pos, vel, ang, col, val, sid, uid, ent, hnrm, trace, tab) + if tab.out_dist then WireLib.TriggerOutput(self, "Dist", dist) end - if (self.out_pos) then + if tab.out_pos then + if not pos then + pos = Vector(0, 0, 0) + end + + local x, y, z = pos:Unpack() WireLib.TriggerOutput(self, "Pos", pos) - WireLib.TriggerOutput(self, "Pos X", pos.x) - WireLib.TriggerOutput(self, "Pos Y", pos.y) - WireLib.TriggerOutput(self, "Pos Z", pos.z) + WireLib.TriggerOutput(self, "Pos X", x) + WireLib.TriggerOutput(self, "Pos Y", y) + WireLib.TriggerOutput(self, "Pos Z", z) end - if (self.out_vel) then + if tab.out_vel then + if not vel then + vel = Vector(0, 0, 0) + end + + local x, y, z = vel:Unpack() WireLib.TriggerOutput(self, "Vel", vel) - WireLib.TriggerOutput(self, "Vel X", vel.x) - WireLib.TriggerOutput(self, "Vel Y", vel.y) - WireLib.TriggerOutput(self, "Vel Z", vel.z) + WireLib.TriggerOutput(self, "Vel X", x) + WireLib.TriggerOutput(self, "Vel Y", y) + WireLib.TriggerOutput(self, "Vel Z", z) end - if (self.out_ang) then + if tab.out_ang then + if not ang then + ang = Angle(0, 0, 0) + end + + local p, y, r = ang:Unpack() WireLib.TriggerOutput(self, "Ang", ang) - WireLib.TriggerOutput(self, "Ang Pitch", ang.p) - WireLib.TriggerOutput(self, "Ang Yaw", ang.y) - WireLib.TriggerOutput(self, "Ang Roll", ang.r) + WireLib.TriggerOutput(self, "Ang Pitch", p) + WireLib.TriggerOutput(self, "Ang Yaw", y) + WireLib.TriggerOutput(self, "Ang Roll", r) end - if (self.out_col) then + if tab.out_col then + if not col then + col = Color(255, 255, 255) + end + WireLib.TriggerOutput(self, "Col RGB", Vector(col.r, col.g, col.b)) WireLib.TriggerOutput(self, "Col R", col.r) WireLib.TriggerOutput(self, "Col G", col.g) @@ -272,35 +318,52 @@ function ENT:TriggerOutput(dist, pos, vel, ang, col, val, sid, uid, ent, hnrm, t WireLib.TriggerOutput(self, "Col A", col.a) end - if (self.out_sid) then + if tab.out_sid then + if not sid then + sid = "" + end + WireLib.TriggerOutput(self, "SteamID", sid) end - if (self.out_uid) then + if tab.out_uid then + if not uid then + uid = 0 + end + WireLib.TriggerOutput(self, "UniqueID", uid) end - if (self.out_eid) then + if tab.out_eid then + if not ent then + ent = NULL + end + WireLib.TriggerOutput(self, "EntID", ent:EntIndex()) WireLib.TriggerOutput(self, "Entity", ent) end - if (self.out_hnrm and hnrm) then + if tab.out_hnrm then + if not hnrm then + hnrm = Vector(0, 0, 0) + end + + local x, y, z = hnrm:Unpack() WireLib.TriggerOutput(self, "HitNormal", hnrm) - WireLib.TriggerOutput(self, "HitNormal X", hnrm.x) - WireLib.TriggerOutput(self, "HitNormal Y", hnrm.y) - WireLib.TriggerOutput(self, "HitNormal Z", hnrm.z) + WireLib.TriggerOutput(self, "HitNormal X", x) + WireLib.TriggerOutput(self, "HitNormal Y", y) + WireLib.TriggerOutput(self, "HitNormal Z", z) end - if (val ~= nil and #val > 0 and self.Inputs.SelectValue.Value <= #val) then - WireLib.TriggerOutput(self, "Val", val[self.Inputs.SelectValue.Value]) + if val and #val > 0 and tab.Inputs.SelectValue.Value <= #val then + WireLib.TriggerOutput(self, "Val", val[tab.Inputs.SelectValue.Value]) WireLib.TriggerOutput(self, "ValSize", #val) else WireLib.TriggerOutput(self, "Val", 0) WireLib.TriggerOutput(self, "ValSize", 0) end - WireLib.TriggerOutput(self, "RangerData", trace) + WireLib.TriggerOutput(self, "RangerData", trace) end duplicator.RegisterEntityClass("gmod_wire_ranger", WireLib.MakeWireEnt, "Data", "range", "default_zero", "show_beam", "ignore_world", "trace_water", "out_dist", "out_pos", "out_vel", "out_ang", "out_col", "out_val", "out_sid", "out_uid", "out_eid", "out_hnrm", "hires") diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 733fc30a23..7e45c32961 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -204,7 +204,7 @@ function Wire_DrawTracerBeam( ent, beam_num, hilight, beam_length ) trace.start = pos trace.filter = { ent } - if ent:GetNWBool("TraceWater") then trace.mask = MASK_ALL end + if entsTbl.GetTraceWater and entsTbl.GetTraceWater(ent) then trace.mask = MASK_ALL end trace = util.TraceLine(trace) --Update render bounds ent.ExtraRBoxPoints = ent.ExtraRBoxPoints or {} diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index 6485daeb63..bc54fb0b12 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -20,7 +20,7 @@ local tostring = tostring local Vector = Vector local Color = Color -local isvector, isnumber, istable, isstring, isangle, IsEntity, IsColor = isvector, isnumber, istable, isstring, isangle, IsEntity, IsColor +local isvector, isnumber, istable, isstring, isangle, isentity, IsColor = isvector, isnumber, istable, isstring, isangle, isentity, IsColor local HasPorts = WireLib.HasPorts -- Very important for checks! local entIsValid = FindMetaTable("Entity").IsValid @@ -146,7 +146,7 @@ WireLib.DT = { Zero = function() return NULL end, - Validator = IsEntity + Validator = isentity }, STRING = { Zero = function() diff --git a/lua/wire/wireshared.lua b/lua/wire/wireshared.lua index 0ff0c377f7..474298bc54 100644 --- a/lua/wire/wireshared.lua +++ b/lua/wire/wireshared.lua @@ -570,22 +570,42 @@ end -- Checks if the entity has wire ports. -- Works for every entity that has wire in-/output. -- Very important and useful for checks! -function WireLib.HasPorts(ent) - local entTbl = ent:GetTable() - if entTbl.IsWire then return true end - if entTbl.Base == "base_wire_entity" then return true end +local EntityMeta = FindMetaTable("Entity") +local entGetTable = EntityMeta.GetTable - -- Checks if the entity is in the list, it checks if the entity has self.in-/outputs too. - local In, Out = WireLib.GetPorts(ent) - if In and (entTbl.Inputs or CLIENT) then return true end - if Out and (entTbl.Outputs or CLIENT) then return true end +if SERVER then + function WireLib.HasPorts(ent) + local entTbl = entGetTable(ent) + if entTbl.IsWire then return true end + if entTbl.Base == "base_wire_entity" then return true end + + -- Checks if the entity is in the list, it checks if the entity has self.in-/outputs too. + local In, Out = WireLib.GetPorts(ent) + if In and entTbl.Inputs then return true end + if Out and entTbl.Outputs then return true end + + return false + end +else + function WireLib.HasPorts(ent) + local entTbl = entGetTable(ent) + if entTbl.IsWire then return true end + if entTbl.Base == "base_wire_entity" then return true end - return false + -- Checks if the entity is in the list, it checks if the entity has self.in-/outputs too. + local In, Out = WireLib.GetPorts(ent) + if In then return true end + if Out then return true end + + return false + end end local WirePortQueue = WireLib.NetQueue("wire_ports") local CMD_DELETE,CMD_PORT,CMD_LINK = 0,1,2 local PORT_TYPE_INPUT,PORT_TYPE_OUTPUT = 0,1 +local entEntIndex = EntityMeta.EntIndex + if SERVER then local ents_with_inputs = {} @@ -599,12 +619,12 @@ if SERVER then end) function WireLib.GetPorts(ent) - local eid = ent:EntIndex() + local eid = entEntIndex(ent) return ents_with_inputs[eid], ents_with_outputs[eid] end function WireLib.RemoveOutPort(ent, name) - local outputs = ents_with_outputs[ent:EntIndex()] + local outputs = ents_with_outputs[entEntIndex(ent)] if outputs then for k, v in ipairs(outputs) do if v[1] == name then @@ -662,7 +682,7 @@ if SERVER then end function WireLib._SetInputs(ent) - local eid = ent:EntIndex() + local eid = entEntIndex(ent) local inputs = ent.Inputs local ent_input_array = {} @@ -677,7 +697,7 @@ if SERVER then end function WireLib._SetOutputs(ent) - local eid = ent:EntIndex() + local eid = entEntIndex(ent) local outputs = ent.Outputs local ent_output_array = {} @@ -692,7 +712,7 @@ if SERVER then end function WireLib._SetLink(input) - SendLinkInfo(WirePortQueue, input.Entity:EntIndex(), input.Num, input.SrcId and true or false) + SendLinkInfo(WirePortQueue, entEntIndex(input.Entity), input.Num, input.SrcId and true or false) end hook.Add("PlayerInitialSpawn", "wire_ports", function(ply) @@ -714,7 +734,7 @@ if SERVER then if ent:IsPlayer() then WirePortQueue:cleanup(ent) else - WireLib._RemoveWire(ent:EntIndex()) + WireLib._RemoveWire(entEntIndex(ent)) end end) @@ -761,7 +781,7 @@ elseif CLIENT then end function WireLib.GetPorts(ent) - local eid = ent:EntIndex() + local eid = entEntIndex(ent) return ents_with_inputs[eid], ents_with_outputs[eid] end @@ -1280,8 +1300,6 @@ hook.Add("PlayerDisconnected", "WireLib_PlayerDisconnect", function(ply) end end) - -local EntityMeta = FindMetaTable("Entity") -- direct references are faster local GetPos = EntityMeta.GetPos local GetAngles = EntityMeta.GetAngles