Skip to content

Commit

Permalink
Fixed: Ghost synchronization with Deploy and Holster
Browse files Browse the repository at this point in the history
Fixed: Ghosts not being ignored by the duplication
  • Loading branch information
dvdvideo1234 committed Jul 8, 2024
1 parent 9975802 commit d405a75
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
41 changes: 21 additions & 20 deletions lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","8.796")
asmlib.SetOpVar("TOOL_VERSION","8.797")

------------ CONFIGURE GLOBAL INIT OPVARS ------------

Expand Down Expand Up @@ -592,21 +592,21 @@ if(CLIENT) then

asmlib.SetAction("BIND_PRESS", -- Must have the same parameters as the hook
function(oPly,sBind,bPress) local sLog = "*BIND_PRESS"
local oPly, actSwep, actTool = asmlib.GetHookInfo()
local oPly, acSw, acTo = asmlib.GetHookInfo()
if(not asmlib.IsPlayer(oPly)) then
asmlib.LogInstance("Hook mismatch",sLog); return nil end
if(((sBind == "invnext") or (sBind == "invprev")) and bPress) then
-- Switch functionality of the mouse wheel only for TA
if(not inputIsKeyDown(KEY_LALT)) then
asmlib.LogInstance("Active key missing",sLog); return nil end
if(not actTool:GetScrollMouse()) then
if(not acTo:GetScrollMouse()) then
asmlib.LogInstance("(SCROLL) Scrolling disabled",sLog); return nil end
local nDir = ((sBind == "invnext") and -1) or ((sBind == "invprev") and 1) or 0
actTool:SwitchPoint(nDir,inputIsKeyDown(KEY_LSHIFT))
acTo:SwitchPoint(nDir,inputIsKeyDown(KEY_LSHIFT))
asmlib.LogInstance("("..sBind..") Processed",sLog); return true
elseif((sBind == "+zoom") and bPress) then -- Work mode radial menu selection
if(inputIsMouseDown(MOUSE_MIDDLE)) then -- Reserve the mouse middle for radial menu
if(not actTool:GetRadialMenu()) then -- Zoom is bind on the middle mouse button
if(not acTo:GetRadialMenu()) then -- Zoom is bind on the middle mouse button
asmlib.LogInstance("("..sBind..") Menu disabled",sLog); return nil end
asmlib.LogInstance("("..sBind..") Processed",sLog); return true
end; return nil -- Need to disable the zoom when bind on the mouse middle
Expand All @@ -616,10 +616,10 @@ if(CLIENT) then

asmlib.SetAction("DRAW_RADMENU", -- Must have the same parameters as the hook
function() local sLog = "*DRAW_RADMENU"
local oPly, actSwep, actTool = asmlib.GetHookInfo()
local oPly, acSw, acTo = asmlib.GetHookInfo()
if(not asmlib.IsPlayer(oPly)) then
asmlib.LogInstance("Hook mismatch",sLog) return nil end
if(not actTool:GetRadialMenu()) then
if(not acTo:GetRadialMenu()) then
asmlib.LogInstance("Menu disabled",sLog); return nil end
if(inputIsMouseDown(MOUSE_MIDDLE)) then guiEnableScreenClicker(true) else
guiEnableScreenClicker(false); asmlib.LogInstance("Release",sLog); return nil
Expand All @@ -629,8 +629,8 @@ if(CLIENT) then
if(not actMonitor) then asmlib.LogInstance("Screen invalid",sLog); return nil end
local nMd = asmlib.GetOpVar("MAX_ROTATION")
local nDr, sM = asmlib.GetOpVar("DEG_RAD"), asmlib.GetOpVar("MISS_NOAV")
local nBr = (actTool:GetRadialAngle() * nDr)
local nK, nN = actTool:GetRadialSegm(), conWorkMode:GetSize()
local nBr = (acTo:GetRadialAngle() * nDr)
local nK, nN = acTo:GetRadialSegm(), conWorkMode:GetSize()
local nR = (mathMin(scrW, scrH) / (2 * gnRatio))
local mXY = asmlib.NewXY(guiMouseX(), guiMouseY())
local vCn = asmlib.NewXY(mathFloor(scrW/2), mathFloor(scrH/2))
Expand Down Expand Up @@ -674,19 +674,20 @@ if(CLIENT) then

asmlib.SetAction("DRAW_GHOSTS", -- Must have the same parameters as the hook
function() local sLog = "*DRAW_GHOSTS"
local oPly, actSwep, actTool = asmlib.GetHookInfo()
local oPly, acSw, acTo = asmlib.GetHookInfo()
if(not asmlib.IsPlayer(oPly)) then
asmlib.LogInstance("Hook mismatch",sLog); return nil end
local model = actTool:GetModel()
local ghcnt = actTool:GetGhostsDepth()
local model = acTo:GetModel()
if(not asmlib.IsModel(model)) then return nil end
local ghcnt = acTo:GetGhostsDepth()
local atGho = asmlib.GetOpVar("ARRAY_GHOST")
if(asmlib.IsModel(model)) then
if(not (asmlib.HasGhosts() and ghcnt == atGho.Size and atGho.Slot == model)) then
if(not asmlib.NewGhosts(ghcnt, model)) then
asmlib.LogInstance("Ghosting fail",sLog); return nil end
actTool:ElevateGhost(atGho[1], oPly) -- Elevate the properly created ghost
end; actTool:UpdateGhost(oPly) -- Update ghosts stack for the local player
end
if(not oPly:GetNWBool(gsToolPrefL.."enghost", false)) then
asmlib.ClearGhosts(); return nil end
if(not (asmlib.HasGhosts() and ghcnt == atGho.Size and atGho.Slot == model)) then
if(not asmlib.NewGhosts(ghcnt, model)) then
asmlib.LogInstance("Ghosting fail",sLog); return nil end
acTo:ElevateGhost(atGho[1], oPly) -- Elevate the properly created ghost
end; acTo:UpdateGhost(oPly) -- Update ghosts stack for the local player
end) -- Read client configuration

asmlib.SetAction("OPEN_EXTERNDB", -- Must have the same parameters as the hook
Expand Down Expand Up @@ -1205,7 +1206,7 @@ if(CLIENT) then
asmlib.LogInstance("Extension disabled",sLog); return nil end
if(not asmlib.GetAsmConvar("adviser", "BUL")) then
asmlib.LogInstance("Adviser disabled",sLog); return nil end
local oPly, actSwep = asmlib.GetHookInfo("weapon_physgun")
local oPly, acSw = asmlib.GetHookInfo("weapon_physgun")
if(not oPly) then asmlib.LogInstance("Hook mismatch",sLog); return nil end
local hasghost = asmlib.HasGhosts(); asmlib.FadeGhosts(true)
if(not inputIsMouseDown(MOUSE_LEFT)) then
Expand Down
39 changes: 23 additions & 16 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3020,9 +3020,9 @@ end
function CacheBoxLayout(oEnt,nCamX,nCamZ)
if(not (oEnt and oEnt:IsValid())) then
LogInstance("Entity invalid "..GetReport(oEnt)); return nil end
local sMod = oEnt:GetModel() -- Extract the entity model
local oRec = CacheQueryPiece(sMod); if(not IsHere(oRec)) then
LogInstance("Record invalid "..GetReport(sMod)); return nil end
local sMo = oEnt:GetModel() -- Extract the entity model
local oRec = CacheQueryPiece(sMo); if(not IsHere(oRec)) then
LogInstance("Record invalid "..GetReport(sMo)); return nil end
local stBox = oRec.Layout; if(not IsHere(stBox)) then
oRec.Layout = {}; stBox = oRec.Layout -- Allocated chance layout
stBox.Cen, stBox.Ang = oEnt:OBBCenter(), Angle() -- Layout position and angle
Expand Down Expand Up @@ -4943,13 +4943,13 @@ function FadeGhosts(bNoD, nMrF)
local nMar = mathClamp((tonumber(nMrF) or 0), 0, 1)
local tGho = GetOpVar("ARRAY_GHOST")
local cPal = GetContainer("COLORS_LIST")
local sMis, sMod = GetOpVar("MISS_NOMD"), tGho.Slot
local sMis, sMo = GetOpVar("MISS_NOMD"), tGho.Slot
for iD = 1, tGho.Size do local eGho = tGho[iD]
if(eGho and eGho:IsValid()) then
if(nMrF) then eGho.marginRender = nMar end
eGho:SetNoDraw(bNoD); eGho:DrawShadow(false)
eGho:SetColor(cPal:Select("gh"))
if(sMod and sMod ~= sMis and sMod ~= eGho:GetModel()) then
if(sMo and sMo ~= sMis and sMo ~= eGho:GetModel()) then
eGho:SetModel(tGho.Slot) end
end
end; return true
Expand Down Expand Up @@ -4977,13 +4977,14 @@ end
* Helper function to handle models that do not support
* color alpha channel have draw override. This is run
* for all the ghosted props to draw all of them correctly
* There is a very logical explanation for all this.
]]
function BlendGhost(self)
local mar = self.marginRender
local num = renderGetBlend()
local cur = renderGetBlend()
renderSetBlend(mar)
self:DrawModel()
renderSetBlend(num)
renderSetBlend(cur)
end

--[[
Expand All @@ -5002,6 +5003,7 @@ function NewEntityGhost(sModel, vPos, aAng)
local vPos = Vector(vPos or GetOpVar("VEC_ZERO"))
local aAng = Angle(aAng or GetOpVar("ANG_ZERO"))
eGho.marginRender = 1
eGho.DoNotDuplicate = true -- Disable duping
eGho.RenderOverride = BlendGhost
eGho:SetModel(sModel)
eGho:SetPos(vPos)
Expand Down Expand Up @@ -5047,23 +5049,28 @@ function NewGhosts(nCnt, sModel) -- Only he's not a shadow, he's a green ghost!
end; tGho.Size, tGho.Slot = nCnt, sModel; return true
end

--[[
* Retrieves hook information player and swep
* sW > Swep class when different than the current tool is needed
* Returns player the swep object and the tool object when available
]]
function GetHookInfo(sW)
if(SERVER) then return nil end
local sMod = GetOpVar("TOOL_DEFMODE")
local sWep = tostring(sW or sMod)
local sDe = GetOpVar("TOOL_DEFMODE")
local sWe = tostring(sW or sDe)
local oPly = LocalPlayer(); if(not IsPlayer(oPly)) then
LogInstance("Player invalid"); return nil end
local actSwep = oPly:GetActiveWeapon(); if(not IsValid(actSwep)) then
local acSw = oPly:GetActiveWeapon(); if(not IsValid(acSw)) then
LogInstance("Swep invalid"); return nil end
if(actSwep:GetClass() ~= sWep) then
LogInstance("("..sWep..") Swep other"); return nil end
if(sWep ~= sMod) then return oPly, actSwep end
if(actSwep:GetMode() ~= GetOpVar("TOOLNAME_NL")) then
if(acSw:GetClass() ~= sWe) then
LogInstance("Swep other "..GetReport(sWe)); return nil end
if(sWe ~= sMo) then return oPly, acSw end
if(acSw:GetMode() ~= GetOpVar("TOOLNAME_NL")) then
LogInstance("Tool different"); return nil end
-- Here player is holding the track assembly tool
local actTool = actSwep:GetToolObject(); if(not actTool) then
local acTo = acSw:GetToolObject(); if(not acTo) then
LogInstance("Tool invalid"); return nil end
return oPly, actSwep, actTool
return oPly, acSw, acTo
end

--[[
Expand Down
12 changes: 11 additions & 1 deletion lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,18 @@ end

function TOOL:Holster()
if(CLIENT) then return end
local user = self:GetOwner()
if(not asmlib.IsPlayer(user)) then return end
user:SetNWBool(gsToolPrefL.."enghost", false)
netStart(gsLibName.."SendDeleteGhosts")
netSend(self:GetOwner())
netSend(user)
end

function TOOL:Deploy()
if(CLIENT) then return end
local user = self:GetOwner()
if(not asmlib.IsPlayer(user)) then return end
user:SetNWBool(gsToolPrefL.."enghost", true)
end

function TOOL:UpdateGhostFlipOver(stTrace, sPos, sAng)
Expand Down

0 comments on commit d405a75

Please sign in to comment.