diff --git a/lua/autorun/laserlib.lua b/lua/autorun/laserlib.lua index 5763e75..6999ba8 100644 --- a/lua/autorun/laserlib.lua +++ b/lua/autorun/laserlib.lua @@ -1147,11 +1147,21 @@ function LaserLib.Configure(unit) unit.meOrderInfo = nil; gtUNITS[uas] = true -- Instance specific configuration if(SERVER) then -- Do server configuration finalizer - if(unit.WireRemove) then function unit:OnRemove() self:WireRemove() end end - if(unit.WireRestored) then function unit:OnRestore() self:WireRestored() end end - if(unit.WirePreEntityCopy) then function unit:PreEntityCopy() self:WirePreEntityCopy() end end - if(unit.WirePostEntityPaste) then function unit:PostEntityPaste(ply, ent, created) self:WirePreEntityCopy(ply, ent, created) end end - if(unit.WireApplyDupeInfo) then function unit:ApplyDupeInfo(ply, ent, info, fentid) self:WirePreEntityCopy(ply, ent, info, fentid) end end + if(unit.OverrideOnRemove) then + function unit:OnRemove() self:OverrideOnRemove() end + else function unit:OnRemove() self:WireRemove() end end + if(unit.OverrideOnRestore) then + function unit:OnRemove() self:OverrideOnRestore() end + else function unit:OnRestore() self:WireRestored() end end + if(unit.OverridePreEntityCopy) then + function unit:PreEntityCopy() self:OverridePreEntityCopy() end + else function unit:PreEntityCopy() self:WirePreEntityCopy() end end + if(unit.OverridePostEntityPaste) then + function unit:PostEntityPaste(ply, ent, cre) self:OverridePostEntityPaste(ply, ent, cre) end + else function unit:PostEntityPaste(ply, ent, cre) self:WirePostEntityPaste(ply, ent, cre) end end + if(unit.OverrideApplyDupeInfo) then + function unit:ApplyDupeInfo(ply, ent, info, feid) self:OverrideApplyDupeInfo(ply, ent, info, feid) end + else function unit:ApplyDupeInfo(ply, ent, info, feid) self:WireApplyDupeInfo(ply, ent, info, feid) end end else -- Do client configuration finalizer language.Add(uas, unit.Information) if(uas ~= cas) then -- Setup the same kill icon @@ -3907,10 +3917,17 @@ local gtACTORS = { local bdot, mdot = ent:GetHitPower(norm, beam, trace, bmln) if(trace and trace.Hit and beam and bdot) then beam.IsTrace = true -- Beam hits correct surface. Continue + local focu = ent:GetFocus() -- Apply custom focus local vdot = (ent:GetBeamDimmer() and mdot or 1) local node = beam:SetPowerRatio(vdot) -- May absorb beam.VrOrigin:Set(trace.HitPos) - beam.VrDirect:Set(trace.HitNormal); beam.VrDirect:Negate() + if(focu == 0) then + beam.VrDirect:Set(trace.HitNormal); beam.VrDirect:Negate() + else + local obb = ent:LocalToWorld(ent:OBBCenter()) + local odv = Vector(obb); odv:Sub(trace.HitPos) + odv:Mul(focu); beam.VrDirect:Add(odv) + end beam:SetActor(ent) -- Makes beam pass the dimmer end end, diff --git a/lua/entities/gmod_laser/init.lua b/lua/entities/gmod_laser/init.lua index b516741..7ffc45f 100644 --- a/lua/entities/gmod_laser/init.lua +++ b/lua/entities/gmod_laser/init.lua @@ -16,18 +16,6 @@ local cvMXBMLENG = LaserLib.GetData("MXBMLENG") local cvMXBMDAMG = LaserLib.GetData("MXBMDAMG") local cvMXBMFORC = LaserLib.GetData("MXBMFORC") -function ENT:PreEntityCopy() - self:WirePreEntityCopy() -end - -function ENT:PostEntityPaste(ply, ent, cre) - self:WirePostEntityPaste(ply, ent, cre) -end - -function ENT:ApplyDupeInfo(ply, ent, info, fentid) - self:WireApplyDupeInfo(ply, ent, info, fentid) -end - function ENT:Initialize() self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) diff --git a/lua/entities/gmod_laser/shared.lua b/lua/entities/gmod_laser/shared.lua index 6cb890c..79f8844 100644 --- a/lua/entities/gmod_laser/shared.lua +++ b/lua/entities/gmod_laser/shared.lua @@ -161,7 +161,7 @@ function ENT:GetBeamSafety() return safe else local safe = self:GetInBeamSafety() - return self:GetNWFloat("GetInBeamSafety", safe) + return self:GetNWBool("GetInBeamSafety", safe) end end diff --git a/lua/entities/gmod_laser_dimmer/shared.lua b/lua/entities/gmod_laser_dimmer/shared.lua index f7d5397..de94d91 100644 --- a/lua/entities/gmod_laser_dimmer/shared.lua +++ b/lua/entities/gmod_laser_dimmer/shared.lua @@ -48,7 +48,7 @@ function ENT:GetHitNormal() return normal else local normal = self:GetNormalLocal() - return self:GetNWFloat("GetNormalLocal", normal) + return self:GetNWVector("GetNormalLocal", normal) end end diff --git a/lua/entities/gmod_laser_divider/shared.lua b/lua/entities/gmod_laser_divider/shared.lua index 50b83ef..e207fee 100644 --- a/lua/entities/gmod_laser_divider/shared.lua +++ b/lua/entities/gmod_laser_divider/shared.lua @@ -67,7 +67,7 @@ function ENT:GetHitNormal() return normal else local normal = self:GetNormalLocal() - return self:GetNWFloat("GetNormalLocal", normal) + return self:GetNWVector("GetNormalLocal", normal) end end diff --git a/lua/entities/gmod_laser_filter/shared.lua b/lua/entities/gmod_laser_filter/shared.lua index 832fe5d..1f7d2e0 100644 --- a/lua/entities/gmod_laser_filter/shared.lua +++ b/lua/entities/gmod_laser_filter/shared.lua @@ -96,7 +96,7 @@ function ENT:GetHitNormal() return normal else local normal = self:GetNormalLocal() - return self:GetNWFloat("GetNormalLocal", normal) + return self:GetNWVector("GetNormalLocal", normal) end end diff --git a/lua/entities/gmod_laser_parallel/init.lua b/lua/entities/gmod_laser_parallel/init.lua index c9394f7..10aea96 100644 --- a/lua/entities/gmod_laser_parallel/init.lua +++ b/lua/entities/gmod_laser_parallel/init.lua @@ -10,12 +10,15 @@ function ENT:Initialize() self:SetMoveType(MOVETYPE_VPHYSICS) self:WireCreateInputs( - {"Normal", "VECTOR", "Parallel surface normal"} + {"Normal", "VECTOR", "Parallel surface normal"}, + {"Focus" , "NORMAL", "Parallel focus margin" } ):WireCreateOutputs( {"Normal", "VECTOR", "Parallel surface normal"}, + {"Focus" , "NORMAL", "Parallel focus margin" }, {"Entity", "ENTITY", "Parallel entity itself" } ) + self:SetFocusMargin(0) self:SetBeamDimmer(false) local phys = self:GetPhysicsObject() diff --git a/lua/entities/gmod_laser_parallel/shared.lua b/lua/entities/gmod_laser_parallel/shared.lua index c12eedb..0299b0e 100644 --- a/lua/entities/gmod_laser_parallel/shared.lua +++ b/lua/entities/gmod_laser_parallel/shared.lua @@ -27,7 +27,7 @@ function ENT:SetupDataTables() self:EditableSetVector("NormalLocal", "General") -- Used as forward self:EditableSetBool ("BeamDimmer" , "General") self:EditableSetBool ("LinearMapping", "General") - self:EditableSetBool ("InPowerOn" , "Internals") + self:EditableSetFloat ("FocusMargin" , "General", -1, 1) LaserLib.Configure(self) end @@ -49,13 +49,27 @@ function ENT:GetHitNormal() return normal else local normal = self:GetNormalLocal() - return self:GetNWFloat("GetNormalLocal", normal) + return self:GetNWVector("GetNormalLocal", normal) + end +end + +function ENT:GetFocus() + if(SERVER) then + local focus = self:WireRead("Focus", true) + if(not focus) then + focus = self:GetFocusMargin() + end -- Make sure length is one unit + self:SetNWFloat("GetFocusMargin", focus) + self:WireWrite("Focus", focus) + return focus + else + local focus = self:GetFocusMargin() + return self:GetNWFloat("GetFocusMargin", normal) end end function ENT:GetHitPower(normal, beam, trace, bmln) - local norm = Vector(normal) - norm:Rotate(self:GetAngles()) + local norm = Vector(normal); norm:Rotate(self:GetAngles()) local dotv = math.abs(norm:Dot(beam.VrDirect)) if(bmln) then dotv = 2 * math.asin(dotv) / math.pi end local dott = math.abs(norm:Dot(trace.HitNormal)) diff --git a/lua/entities/gmod_laser_portal/init.lua b/lua/entities/gmod_laser_portal/init.lua index bef5e54..1ac742e 100644 --- a/lua/entities/gmod_laser_portal/init.lua +++ b/lua/entities/gmod_laser_portal/init.lua @@ -4,20 +4,12 @@ include("shared.lua") resource.AddFile("materials/vgui/entities/gmod_laser_portal.vmt") -function ENT:PreEntityCopy() - self:WirePreEntityCopy() -end - -function ENT:PostEntityPaste(ply, ent, created) - self:WirePostEntityPaste(ply, ent, created) +function ENT:OverridePostEntityPaste(ply, ent, cre) + self:WirePostEntityPaste(ply, ent, cre) local idx = (tonumber(self:GetEntityExitID()) or 0) - local ent = created[idx]; self:SetEntityExitID(0) - if(not self:IsTrueExit(ent)) then return end - self:SetEntityExitID(tostring(ent:EntIndex())) -end - -function ENT:ApplyDupeInfo(ply, ent, info, fentid) - self:WireApplyDupeInfo(ply, ent, info, fentid) + local out = cre[idx]; self:SetEntityExitID(0) + if(not self:IsTrueExit(out)) then return end + self:SetEntityExitID(tostring(out:EntIndex())) end function ENT:Initialize() diff --git a/lua/entities/gmod_laser_rdivider/shared.lua b/lua/entities/gmod_laser_rdivider/shared.lua index 8592594..fd1b591 100644 --- a/lua/entities/gmod_laser_rdivider/shared.lua +++ b/lua/entities/gmod_laser_rdivider/shared.lua @@ -60,7 +60,7 @@ function ENT:GetHitNormal() return normal else local normal = self:GetNormalLocal() - return self:GetNWFloat("GetNormalLocal", normal) + return self:GetNWVector("GetNormalLocal", normal) end end diff --git a/lua/entities/gmod_laser_sensor/shared.lua b/lua/entities/gmod_laser_sensor/shared.lua index 8ab2de3..4184478 100644 --- a/lua/entities/gmod_laser_sensor/shared.lua +++ b/lua/entities/gmod_laser_sensor/shared.lua @@ -42,7 +42,7 @@ function ENT:GetUnitDirection() return norm else local norm = self:GetDirectLocal() - return self:GetNWFloat("GetDirectLocal", norm) + return self:GetNWVector("GetDirectLocal", norm) end end @@ -55,7 +55,7 @@ function ENT:GetUnitOrigin() return opos else local opos = self:GetOriginLocal() - return self:GetNWFloat("GetOriginLocal", opos) + return self:GetNWVector("GetOriginLocal", opos) end end diff --git a/lua/entities/gmod_laser_splitterm/shared.lua b/lua/entities/gmod_laser_splitterm/shared.lua index d1d6a2d..cdbd6a9 100644 --- a/lua/entities/gmod_laser_splitterm/shared.lua +++ b/lua/entities/gmod_laser_splitterm/shared.lua @@ -127,7 +127,7 @@ function ENT:GetHitNormal() return normal else local normal = self:GetNormalLocal() - return self:GetNWFloat("GetNormalLocal", normal) + return self:GetNWVector("GetNormalLocal", normal) end end diff --git a/lua/laseremitter/wire_wrapper.lua b/lua/laseremitter/wire_wrapper.lua index dfb67bf..29de721 100644 --- a/lua/laseremitter/wire_wrapper.lua +++ b/lua/laseremitter/wire_wrapper.lua @@ -156,16 +156,16 @@ end --[[ * Procedure. Applies duplicator needed wire information * Does not return anything. It is prcedure - * ply > Player to store the info for - * ent > Entity to store the info for - * info > Information table to apply - * fentid > Pointer to function retrieving entity by ID - * Usage: function ENT:ApplyDupeInfo(ply, ent, info, fentid) - self:WireApplyDupeInfo(ply, ent, info, fentid) end + * ply > Player to store the info for + * ent > Entity to store the info for + * info > Information table to apply + * feid > Pointer to function retrieving entity by ID + * Usage: function ENT:ApplyDupeInfo(ply, ent, info, feid) + self:WireApplyDupeInfo(ply, ent, info, feid) end ]] -function ENT:WireApplyDupeInfo(ply, ent, info, fentid) +function ENT:WireApplyDupeInfo(ply, ent, info, feid) if(not WireLib) then return self end - WireLib.ApplyDupeInfo(ply, ent, info, fentid) + WireLib.ApplyDupeInfo(ply, ent, info, feid) return self end @@ -185,8 +185,8 @@ end --[[ * Procedure. Must be run inside `ENT:PostEntityPaste` * Makes wire do the post-paste preparation for dupe info - * Usage: function ENT:PostEntityPaste(player, entity, created) - self:WirePostEntityPaste(player, entity, created) end + * Usage: function ENT:PostEntityPaste(ply, ent, cre) + self:WirePostEntityPaste(ply, ent, cre) end * ply > The player calling the routune * ent > The entity being post-pasted * cre > The created entities list after paste