diff --git a/data/trackassembly/trackasmlib_slskip.txt b/data/trackassembly/trackasmlib_slskip.txt index cf5546ec..9ad93cb7 100644 --- a/data/trackassembly/trackasmlib_slskip.txt +++ b/data/trackassembly/trackasmlib_slskip.txt @@ -23,3 +23,5 @@ BIND_PRESS: Tool different BIND_PRESS: Active key missing IntersectRayRead IntersectRayClear +MakeScreen.GetDistance: Start out of border +MakeScreen.GetDistance: End out of border diff --git a/lua/autorun/trackassembly_init.lua b/lua/autorun/trackassembly_init.lua index e8628913..f94376e2 100644 --- a/lua/autorun/trackassembly_init.lua +++ b/lua/autorun/trackassembly_init.lua @@ -36,7 +36,7 @@ local asmlib = trackasmlib ------ CONFIGURE ASMLIB ------ asmlib.InitBase("track","assembly") -asmlib.SetOpVar("TOOL_VERSION","5.390") +asmlib.SetOpVar("TOOL_VERSION","5.391") asmlib.SetIndexes("V",1,2,3) asmlib.SetIndexes("A",1,2,3) asmlib.SetIndexes("S",4,5,6,7) @@ -64,7 +64,7 @@ asmlib.MakeAsmVar("maxlinear", "250" , {1}, gnServerControled, "Maximum linea asmlib.MakeAsmVar("maxforce" , "100000", {0}, gnServerControled, "Maximum force limit when creating welds") asmlib.MakeAsmVar("maxactrad", "150", {1,500}, gnServerControled, "Maximum active radius to search for a point ID") asmlib.MakeAsmVar("maxstcnt" , "200", {1,200}, gnServerControled, "Maximum pieces to spawn in stack mode") -asmlib.MakeAsmVar("enwiremod", "1" , {0, 1 }, gnServerControled, "Toggle the wire extension on/off server side") +asmlib.MakeAsmVar("enwiremod", "1" , {0, 1 }, gnServerControled, "Toggle the wire extension on/off on restart server side") if(SERVER) then asmlib.MakeAsmVar("bnderrmod", "LOG", nil , gnServerControled, "Unreasonable position error handling mode") @@ -107,12 +107,19 @@ if(SERVER) then utilAddNetworkString(gsLibName.."SendIntersectClear") utilAddNetworkString(gsLibName.."SendIntersectRelate") - + asmlib.SetAction("DUPE_PHYS_SETTINGS", function(oPly,oEnt,tData) -- Duplicator wrapper if(not asmlib.ApplyPhysicalSettings(oEnt,tData[1],tData[2],tData[3],tData[4])) then - return asmlib.StatusLog(false,"DUPE_PHYS_SETTINGS: Failed to apply physical settings on "..tostring(oEnt)) end - return asmlib.StatusLog(true,"DUPE_PHYS_SETTINGS: Success") + return asmlib.StatusLog(nil,"DUPE_PHYS_SETTINGS: Failed to apply physical settings on "..tostring(oEnt)) end + return asmlib.StatusLog(nil,"DUPE_PHYS_SETTINGS: Success") + end) + + asmlib.SetAction("PLAYER_QUIT", + function(oPly) -- Clear player cache when disconnects + if(not asmlib.CacheClearPly(oPly)) then + return asmlib.StatusLog(nil,"PLAYER_QUIT: Failed swiping stuff "..tostring(oPly)) end + return asmlib.StatusLog(nil,"PLAYER_QUIT: Success") end) asmlib.SetAction("PHYSGUN_DROP", @@ -170,7 +177,9 @@ end if(CLIENT) then asmlib.SetAction("NET_CLEAR_RELATION", - function(nLen,oPly) + function(nLen) + local oPly = netReadEntity() + asmlib.LogInstance("NET_CLEAR_RELATION: {"..tostring(nLen)..","..tostring(oPly).."}") if(not asmlib.IntersectRayClear(oPly, "ray_relate")) then return asmlib.StatusLog(nil,"NET_CLEAR_RELATION: Failed clearing ray") end RunConsoleCommand(gsToolPrefL.."drwrelate", 0) @@ -178,8 +187,9 @@ if(CLIENT) then end) -- Net receive intersect relation clear client-side asmlib.SetAction("NET_CREATE_RELATION", - function(nLen,oPly) - local oEnt, vHit = netReadEntity(), netReadVector() + function(nLen) + local oEnt, vHit, oPly = netReadEntity(), netReadVector(), netReadEntity() + asmlib.LogInstance("NET_CREATE_RELATION: {"..tostring(nLen)..","..tostring(oPly).."}") local stRay = asmlib.IntersectRayCreate(oPly, oEnt, vHit, "ray_relate") if(not stRay) then return asmlib.StatusLog(nil,"NET_CREATE_RELATION: Failed updating ray") end @@ -219,7 +229,7 @@ if(CLIENT) then asmlib.ConCommandPly(oPly,"nextyaw", "0") asmlib.ConCommandPly(oPly,"nextrol", "0") if(not devmode) then - return asmlib.StatusLog(true,"RESET_VARIABLES: Developer mode disabled") end + return asmlib.StatusLog(nil,"RESET_VARIABLES: Developer mode disabled") end asmlib.SetLogControl(asmlib.GetAsmVar("logsmax" , "INT"),asmlib.GetAsmVar("logfile" , "STR")) if(bgskids == "reset cvars") then -- Reset the limit also oPly:ConCommand("sbox_max"..asmlib.GetOpVar("CVAR_LIMITNAME").." 1500\n") @@ -237,7 +247,7 @@ if(CLIENT) then asmlib.ConCommandPly(oPly, "ydegsnp" , "45") asmlib.ConCommandPly(oPly, "pointid" , "1") asmlib.ConCommandPly(oPly, "pnextid" , "2") - asmlib.ConCommandPly(oPly, "mcspawn" , "0") + asmlib.ConCommandPly(oPly, "spawncn" , "0") asmlib.ConCommandPly(oPly, "bgskids" , "0/0") asmlib.ConCommandPly(oPly, "gravity" , "1") asmlib.ConCommandPly(oPly, "adviser" , "1") @@ -280,21 +290,22 @@ if(CLIENT) then asmlib.RemoveDSV("PHYSPROPERTIES", vPr) asmlib.LogInstance("RESET_VARIABLES: Match <"..vPr..">") end - else return asmlib.StatusLog(true,"RESET_VARIABLES: Command <"..bgskids.."> skipped") end - return asmlib.StatusLog(true,"RESET_VARIABLES: Success") + else return asmlib.StatusLog(nil,"RESET_VARIABLES: Command <"..bgskids.."> skipped") end + return asmlib.StatusLog(nil,"RESET_VARIABLES: Success") end) asmlib.SetAction("OPEN_FRAME", function(oPly,oCom,oArgs) local frUsed, nCount = asmlib.GetFrequentModels(oArgs[1]) if(not asmlib.IsExistent(frUsed)) then - return asmlib.StatusLog(false,"OPEN_FRAME: Retrieving most frequent models failed ["..tostring(oArgs[1]).."]") end + return asmlib.StatusLog(nil,"OPEN_FRAME: Retrieving most frequent models failed ["..tostring(oArgs[1]).."]") end local defTable = asmlib.GetOpVar("DEFTABLE_PIECES") - if(not defTable) then return StatusLog(false,"OPEN_FRAME: Missing definition for table PIECES") end + if(not defTable) then + return StatusLog(nil,"OPEN_FRAME: Missing definition for table PIECES") end local pnFrame = vguiCreate("DFrame") if(not IsValid(pnFrame)) then pnFrame:Remove() - return asmlib.StatusLog(false,"OPEN_FRAME: Failed to create base frame") + return asmlib.StatusLog(nil,"OPEN_FRAME: Failed to create base frame") end local pnElements = asmlib.MakeContainer("FREQ_VGUI") pnElements:Insert(1,{Label = { "DButton" ,languageGetPhrase("tool."..gsToolNameL..".pn_export_lb") , languageGetPhrase("tool."..gsToolNameL..".pn_export")}}) @@ -318,7 +329,7 @@ if(CLIENT) then iNdex = iNdex + 1 end pnFrame:Remove(); collectgarbage() - return StatusLog(false,"OPEN_FRAME: Invalid panel created. Frame removed") + return StatusLog(nil,"OPEN_FRAME: Invalid panel created. Frame removed") end vItem.Panel:SetName(vItem.Label[2]) vItem.Panel:SetTooltip(vItem.Label[3]) @@ -416,7 +427,7 @@ if(CLIENT) then if(pnSelf.bAnimated) then pnSelf:RunAnimation() end local uiBox = asmlib.CacheBoxLayout(oEnt,40) if(not asmlib.IsExistent(uiBox)) then - return asmlib.StatusLog(false,"OPEN_FRAME: pnModelPanel.LayoutEntity: Box invalid") end + return asmlib.StatusLog(nil,"OPEN_FRAME: pnModelPanel.LayoutEntity: Box invalid") end local stSpawn = asmlib.GetNormalSpawn(asmlib.GetOpVar("VEC_ZERO"),uiBox.Ang,oEnt:GetModel(),1) stSpawn.SPos:Set(uiBox.Cen) stSpawn.SPos:Rotate(stSpawn.SAng) @@ -443,7 +454,7 @@ if(CLIENT) then local sAbrev, sField = pnComboBox:GetSelected() sAbrev, sField = tostring(sAbrev or ""), tostring(sField or "") if(not asmlib.UpdateListView(pnListView,frUsed,nCount,sField,sPattr)) then - return asmlib.StatusLog(false,"OPEN_FRAME: TextEntry.OnEnter: Failed to update ListView {"..sAbrev.."#"..sField.."#"..sPattr.."}") + return asmlib.StatusLog(nil,"OPEN_FRAME: TextEntry.OnEnter: Failed to update ListView {"..sAbrev.."#"..sField.."#"..sPattr.."}") end end ------------ ListView -------------- @@ -480,7 +491,7 @@ if(CLIENT) then local uiEnt = pnModelPanel:GetEntity() local uiBox = asmlib.CacheBoxLayout(uiEnt,0,nRatio,nRatio-1) if(not asmlib.IsExistent(uiBox)) then - return asmlib.StatusLog(false,"OPEN_FRAME: ListView.OnRowSelected: Box invalid for <"..uiMod..">") end + return asmlib.StatusLog(nil,"OPEN_FRAME: ListView.OnRowSelected: Box invalid for <"..uiMod..">") end pnModelPanel:SetLookAt(uiBox.Eye); pnModelPanel:SetCamPos(uiBox.Cam) local pointid, pnextid = asmlib.GetAsmVar("pointid","INT"), asmlib.GetAsmVar("pnextid","INT") pointid, pnextid = asmlib.SnapReview(pointid, pnextid, uiAct) @@ -490,9 +501,9 @@ if(CLIENT) then end -- Copy the line model to the clipboard so it can be pasted with Ctrl+V pnListView.OnRowRightClick = function(pnSelf, nIndex, pnLine) SetClipboardText(pnLine:GetColumnText(5)) end if(not asmlib.UpdateListView(pnListView,frUsed,nCount)) then - asmlib.StatusLog(false,"OPEN_FRAME: ListView.OnRowSelected: Populate the list view failed") end + return asmlib.StatusLog(nil,"OPEN_FRAME: ListView.OnRowSelected: Populate the list view failed") end pnFrame:SetVisible(true); pnFrame:Center(); pnFrame:MakePopup(); collectgarbage() - return asmlib.StatusLog(true,"OPEN_FRAME: Success") -- Show the completed panel + return asmlib.StatusLog(nil,"OPEN_FRAME: Success") -- Show the completed panel end) asmlib.SetAction("PHYSGUN_DRAW", @@ -511,7 +522,7 @@ if(CLIENT) then return asmlib.StatusLog(nil,"PHYSGUN_DRAW: Swep not physgun") end if(not inputIsMouseDown(MOUSE_LEFT)) then return asmlib.StatusLog(nil,"PHYSGUN_DRAW: Physgun not hold") end - local actTr = asmlib.GetTracePly(oPly) + local actTr = asmlib.CacheTracePly(oPly) if(not actTr) then return asmlib.StatusLog(nil,"PHYSGUN_DRAW: Trace missing") end if(not actTr.Hit) then return asmlib.StatusLog(nil,"PHYSGUN_DRAW: Trace not hit") end if(actTr.HitWorld) then return asmlib.StatusLog(nil,"PHYSGUN_DRAW: Trace world") end @@ -2902,8 +2913,8 @@ if(CLIENT) then -- con >> control, def >> deafault, hd >> header, lb >> label asmlib.SetLocalify("en","tool."..gsToolNameL..".igntype_con" , "Ignore track type") asmlib.SetLocalify("en","tool."..gsToolNameL..".spnflat" , "The next piece will be spawned/snapped/stacked horizontally") asmlib.SetLocalify("en","tool."..gsToolNameL..".spnflat_con" , "Spawn horizontally") - asmlib.SetLocalify("en","tool."..gsToolNameL..".mcspawn" , "Spawns the piece at the mass-centre, else spawns relative to the active point chosen") - asmlib.SetLocalify("en","tool."..gsToolNameL..".mcspawn_con" , "Origin from mass-centre") + asmlib.SetLocalify("en","tool."..gsToolNameL..".spawncn" , "Spawns the piece at the centre, else spawns relative to the active point chosen") + asmlib.SetLocalify("en","tool."..gsToolNameL..".spawncn_con" , "Origin from centre") asmlib.SetLocalify("en","tool."..gsToolNameL..".surfsnap" , "Snaps the piece to the surface the player is pointing at") asmlib.SetLocalify("en","tool."..gsToolNameL..".surfsnap_con" , "Snap to trace surface") asmlib.SetLocalify("en","tool."..gsToolNameL..".appangfst" , "Apply the angular offsets only on the first piece") @@ -2997,8 +3008,8 @@ if(CLIENT) then -- con >> control, def >> deafault, hd >> header, lb >> label asmlib.SetLocalify("bg","tool."..gsToolNameL..".igntype_con" , "Пренебрегни типа на парчето") asmlib.SetLocalify("bg","tool."..gsToolNameL..".spnflat" , "Следващото парче ще бъде създадено/залепено/натрупано хоризонтално") asmlib.SetLocalify("bg","tool."..gsToolNameL..".spnflat_con" , "Създай хоризонтално") - asmlib.SetLocalify("bg","tool."..gsToolNameL..".mcspawn" , "Създава парчето в масовия център, иначе спрямо избраната активна точка") - asmlib.SetLocalify("bg","tool."..gsToolNameL..".mcspawn_con" , "Начало от масовия център") + asmlib.SetLocalify("bg","tool."..gsToolNameL..".spawncn" , "Създава парчето в центъра, иначе спрямо избраната активна точка") + asmlib.SetLocalify("bg","tool."..gsToolNameL..".spawncn_con" , "Начало спрямо центъра") asmlib.SetLocalify("bg","tool."..gsToolNameL..".surfsnap" , "Залепи парчето по повърхнината към която сочи потребителя") asmlib.SetLocalify("bg","tool."..gsToolNameL..".surfsnap_con" , "Залепи по повърхнината") asmlib.SetLocalify("bg","tool."..gsToolNameL..".appangfst" , "Приложи ъгловото отместване само върху първото парче за насочване") @@ -3092,8 +3103,8 @@ if(CLIENT) then -- con >> control, def >> deafault, hd >> header, lb >> label asmlib.SetLocalify("fr","tool."..gsToolNameL..".igntype_con" , "Ignorer le type de piste") asmlib.SetLocalify("fr","tool."..gsToolNameL..".spnflat" , "La prochaine pièce sera créée/alignée/empilé horizontalement") asmlib.SetLocalify("fr","tool."..gsToolNameL..".spnflat_con" , "Créer horizontalement") - asmlib.SetLocalify("fr","tool."..gsToolNameL..".mcspawn" , "Créer la pièce vers le barycentre, sinon, la créer relativement vers le point active choisi") - asmlib.SetLocalify("fr","tool."..gsToolNameL..".mcspawn_con" , "Partir du barycentre") + asmlib.SetLocalify("fr","tool."..gsToolNameL..".spawncn" , "Créer la pièce vers le centre, sinon, la créer relativement vers le point active choisi") + asmlib.SetLocalify("fr","tool."..gsToolNameL..".spawncn_con" , "Partir du centre") asmlib.SetLocalify("fr","tool."..gsToolNameL..".surfsnap" , "Aligne la pièce vers la surface auquel le joueur vise actuellement") asmlib.SetLocalify("fr","tool."..gsToolNameL..".surfsnap_con" , "Aligner vers la surface tracé") asmlib.SetLocalify("fr","tool."..gsToolNameL..".appangfst" , "Appliquer les décalages angulaires seulement sur la première pièce") @@ -3187,8 +3198,8 @@ if(CLIENT) then -- con >> control, def >> deafault, hd >> header, lb >> label asmlib.SetLocalify("ru","tool."..gsToolNameL..".igntype_con" , "Игнорировать тип кусков") asmlib.SetLocalify("ru","tool."..gsToolNameL..".spnflat" , "Следующий кусок будет создан/приклеен/накоплен по горизонтали") asmlib.SetLocalify("ru","tool."..gsToolNameL..".spnflat_con" , "Нагромождать по горизонтали") - asmlib.SetLocalify("ru","tool."..gsToolNameL..".mcspawn" , "Создание куска в центре тяжести иначе в выбранной активной точке") - asmlib.SetLocalify("ru","tool."..gsToolNameL..".mcspawn_con" , "Начало центра массы") + asmlib.SetLocalify("ru","tool."..gsToolNameL..".spawncn" , "Создание куска в центре иначе в выбранной активной точке") + asmlib.SetLocalify("ru","tool."..gsToolNameL..".spawncn_con" , "Происхождение из центра") asmlib.SetLocalify("ru","tool."..gsToolNameL..".surfsnap" , "Приклеить кусок к поверхности к которой ссылается пользователь") asmlib.SetLocalify("ru","tool."..gsToolNameL..".surfsnap_con" , "Приклеивать к поверхности") asmlib.SetLocalify("ru","tool."..gsToolNameL..".appangfst" , "Применять угловое смещение только на первой кусок") diff --git a/lua/entities/gmod_wire_expression2/core/custom/trackasmlib_wire.lua b/lua/entities/gmod_wire_expression2/core/custom/trackasmlib_wire.lua index 7ef9cb64..c72ae32f 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/trackasmlib_wire.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/trackasmlib_wire.lua @@ -12,9 +12,7 @@ local mathClamp = math and math.Clamp ----- Get extension enabled flag local maxColor = 255 local anyTrue, anyFalse = 1, 0 -local maxMass = asmlib.GetOpVar("MAX_MASS") local enFlag = asmlib.GetAsmVar("enwiremod","BUL") -local bndErr = asmlib.GetAsmVar("bnderrmod","STR") local cvX, cvY, cvZ = asmlib.GetIndexes("V") local caP, caY, caR = asmlib.GetIndexes("A") local csA, csB, csC, csD = asmlib.GetIndexes("S") @@ -54,7 +52,7 @@ e2function array entity:trackasmlibSnapEntity(vector trHitPos , string hdModel number nActRadius, number enFlatten, number enIgnTyp , vector ucsOffPos , vector ucsOffAng) if(not (this and this:IsValid() and enFlag)) then return {} end - local stSpawn = asmlib.GetEntitySpawn(this,trHitPos,hdModel,hdPointID, + local stSpawn = asmlib.GetEntitySpawn(self.player,this,trHitPos,hdModel,hdPointID, nActRadius,(enFlatten ~= 0),(enIgnTyp ~= 0), ucsPos[1],ucsPos[2],ucsPos[3],ucsAng[1],ucsAng[2],ucsAng[3]) if(not stSpawn) then return {} end @@ -65,7 +63,7 @@ __e2setcost(80) e2function array trackasmlibSnapNormal(vector ucsPos , angle ucsAng , string hdModel, number hdPointID, vector ucsOffPos, vector ucsOffAng) if(not enFlag) then return {} end - local stSpawn = asmlib.GetNormalSpawn(ucsPos,ucsAng,hdModel,hdPointID, + local stSpawn = asmlib.GetNormalSpawn(self.player,ucsPos,ucsAng,hdModel,hdPointID, ucsOffPos[1],ucsOffPos[2],ucsOffPos[3], ucsOffAng[1],ucsOffAng[2],ucsOffAng[3]) if(not stSpawn) then return {} end @@ -255,8 +253,8 @@ e2function entity trackasmlibMakePiece(string sModel, vector vPos, angle aAng, n if(not enFlag) then return nil end if(not asmlib.IsPlayer(self.player)) then return nil end return asmlib.MakePiece(self.player,sModel,Vector(vPos[1],vPos[2],vPos[3]),Angle(aAng[1],aAng[2],aAng[3]), - mathClamp(nMass,1,maxMass),sBgpID,Color(mathClamp(nR,0,maxColor),mathClamp(nG,0,maxColor), - mathClamp(nB,0,maxColor),mathClamp(nA,0,maxColor)),bndErr) + mathClamp(nMass,1,asmlib.GetAsmVar("maxmass","FLT")),sBgpID,Color(mathClamp(nR,0,maxColor),mathClamp(nG,0,maxColor), + mathClamp(nB,0,maxColor),mathClamp(nA,0,maxColor)),asmlib.GetAsmVar("bnderrmod","STR")) end __e2setcost(50) @@ -269,8 +267,8 @@ e2function entity entity:trackasmlibMakePiece(vector vPos, angle aAng) if(not stRecord) then return nil end local sBgpID = asmlib.GetPropBodyGroup(this).. asmlib.GetOpVar("OPSYM_DIRECTORY")..asmlib.GetPropSkin(this) - return asmlib.MakePiece(self.player,this:GetModel(),Vector(vPos[1],vPos[2],vPos[3]), - Angle (aAng[1],aAng[2],aAng[3]),phthis:GetMass(),sBgpID,this:GetColor(),bndErr) + return asmlib.MakePiece(self.player,this:GetModel(),Vector(vPos[1],vPos[2],vPos[3]),Angle(aAng[1],aAng[2],aAng[3]), + phthis:GetMass(),sBgpID,this:GetColor(),asmlib.GetAsmVar("bnderrmod","STR")) end __e2setcost(15) diff --git a/lua/trackassembly/trackasmlib.lua b/lua/trackassembly/trackasmlib.lua index 63a82f41..70646790 100644 --- a/lua/trackassembly/trackasmlib.lua +++ b/lua/trackassembly/trackasmlib.lua @@ -140,9 +140,10 @@ local constraintNoCollide = constraint and constraint.NoCollide local duplicatorStoreEntityModifier = duplicator and duplicator.StoreEntityModifier ---------------- CASHES SPACE -------------------- -local libCache = {} -- Used to cache stuff in a Pool +local libCache = {} -- Used to cache stuff in a pool local libAction = {} -- Used to attach external function to the lib -local libOpVars = {} -- Used to Store operational Variable Values +local libOpVars = {} -- Used to Store operational variable values +local libPlayer = {} -- Used to allcoate personal space for players module("trackasmlib") @@ -418,7 +419,7 @@ function InitBase(sName,sPurpose) SetOpVar("LOCALIFY_TABLE",{}) SetOpVar("LOCALIFY_AUTO","en") SetOpVar("TABLE_CATEGORIES", {}) - SetOpVar("STRUCT_SPAWN_KEYS",{ + SetOpVar("STRUCT_SPAWN",{ {"--- Origin ---", nil }, {"F" ,"VEC", "Forward direction"}, {"R" ,"VEC", "Right direction"}, @@ -446,7 +447,6 @@ function InitBase(sName,sPurpose) SetOpVar("MODELNAM_FUNC",function(x) return " "..x:sub(2,2):upper() end) SetOpVar("QUERY_STORE", {}) SetOpVar("TABLE_BORDERS",{}) - SetOpVar("TABLE_PLAYER",{}) SetOpVar("TABLE_FREQUENT_MODELS",{}) SetOpVar("OOP_DEFAULTKEY","(!@<#_$|%^|&>*)DEFKEY(*>&|^%|$_#<@!)") SetOpVar("CVAR_LIMITNAME","asm"..GetOpVar("NAME_INIT").."s") @@ -471,31 +471,6 @@ function InitBase(sName,sPurpose) SetOpVar("NAV_ADDITION",{}) SetOpVar("NAV_PROPERTY_NAMES",{}) SetOpVar("NAV_PROPERTY_TYPES",{}) - SetOpVar("STRUCT_SPAWN",{ - F = Vector(), - R = Vector(), - U = Vector(), - OPos = Vector(), - OAng = Angle (), - SPos = Vector(), - SAng = Angle (), - RLen = 0, - --- Holder --- - HRec = 0, - HID = 0, - HPnt = Vector(), -- P - HPos = Vector(), -- O - HAng = Angle (), -- A - --- Traced --- - TRec = 0, - TID = 0, - TPnt = Vector(), -- P - TPos = Vector(), -- O - TAng = Angle (), -- A - --- Offsets --- - ANxt = Angle (), - PNxt = Vector() - }) return StatusPrint(true,"InitBase: Success") end @@ -898,7 +873,7 @@ function GetActionCode(sKey) if(not (sKey and IsString(sKey))) then return StatusLog(nil,"GetActionCode: Key {"..type(sKey).."}<"..tostring(sKey).."> not string") end if(not (libAction and libAction[sKey])) then - return StatusLog(nil,"GetActionCode: Key not located") end + return StatusLog(nil,"GetActionCode: Key missing <"..sKey..">") end return libAction[sKey].Act end @@ -1070,14 +1045,11 @@ function RoundValue(nvExact, nFrac) return nFrac * (q + (f > 0.5 and 1 or 0)) end -function GetCenterMC(oEnt) +function GetCenter(oEnt) -- Set the ENT's Angles first! if(not (oEnt and oEnt:IsValid())) then - return StatusLog(Vector(0,0,0),"GetCenterMC: Entity Invalid") end - local Phys = oEnt:GetPhysicsObject() - if(not (Phys and Phys:IsValid())) then - return StatusLog(Vector(0,0,0),"GetCenterMC: Phys object Invalid") end - local vRez = Phys:GetMassCenter() + return StatusLog(Vector(0,0,0),"GetCenter: Entity Invalid") end + local vRez = oEnt:OBBCenter() vRez[cvX] = -vRez[cvX]; vRez[cvY] = -vRez[cvY]; vRez[cvZ] = 0 return vRez end @@ -1514,22 +1486,102 @@ function DefaultTable(anyTable) SettingsModelToName("CLR") end -function GetTracePly(pPly) +------------------------- PLAYER ----------------------------------- + +local function GetPlacePly(pPly) + if(not IsPlayer(pPly)) then + return StatusLog(nil,"GetPlacePly: Player <"..tostring(pPly)"> invalid") end + local plyPlace = libPlayer[pPly] + if(not IsExistent(plyPlace)) then + LogInstance("GetPlacePly: Cached <"..pPly:Nick()..">") + libPlayer[pPly] = {}; plyPlace = libPlayer[pPly] + end; return plyPlace +end + +function CacheSpawnPly(pPly) + local plyPlace = GetPlacePly(pPly) + if(not IsExistent(plyPlace)) then + return StatusLog(nil,"CacheSpawnPly: Place missing") end + local plyData = plyPlace["SPAWN"] + if(not IsExistent(plyData)) then + LogInstance("CacheSpawnPly: Malloc <"..pPly:Nick()..">") + plyPlace["SPAWN"] = {}; plyData = plyPlace["SPAWN"] + plyData.F = Vector() -- Origin forward vector + plyData.R = Vector() -- Origin right vector + plyData.U = Vector() -- Origin up vector + plyData.OPos = Vector() -- Origin position + plyData.OAng = Angle () -- Origin angle + plyData.SPos = Vector() -- Gear spawn position + plyData.SAng = Angle () -- Gear spawn angle + plyData.RLen = 0 -- Trace active radius + --- Holder --- + plyData.HRec = 0 -- Pointer to the hoder record + plyData.HID = 0 -- Point ID + plyData.HPnt = Vector() -- P + plyData.HPos = Vector() -- O + plyData.HAng = Angle () -- A + --- Traced --- + plyData.TRec = 0 -- Pointer to the trace record + plyData.TID = 0 + plyData.TPnt = Vector() -- P + plyData.TPos = Vector() -- O + plyData.TAng = Angle () -- A + --- Offsets --- + plyData.ANxt = Angle () -- Origin angle offsets + plyData.PNxt = Vector() -- Piece position offsets + end; return plyData +end + +function CacheClearPly(pPly) if(not IsPlayer(pPly)) then - return StatusLog(nil,"GetTracePly: Player <"..tostring(pPly)"> invalid") end - local plyTable = GetOpVar("TABLE_PLAYER") - local plyPlace, plyTime = plyTable[pPly], Time() + return StatusLog(false,"CacheClearPly: Player <"..tostring(pPly)"> invalid") end + local plyPlace = libPlayer[pPly] if(not IsExistent(plyPlace)) then - plyTable[pPly] = {}; plyPlace = plyTable[pPly] end - if(not plyPlace["TDM"]) then -- Define trace delta margin - plyPlace["TDM"] = 0.02 -- Trace delta time margin - plyPlace["NXT"] = plyTime + plyPlace["TDM"] -- Define next trace pending - plyPlace["DAT"] = utilTraceLine(utilGetPlayerTrace(pPly)) -- Make a trace + return StatusLog(true,"CacheClearPly: Clean") end + plyTable[pPly] = nil; collectgarbage(); return true +end + +function GetDistanceHitPly(pPly, vHit) + if(not IsPlayer(pPly)) then + return StatusLog(nil,"GetDistanceHitPly: Player <"..tostring(pPly)"> invalid") end + return (vHit - pPly:GetPos()):Length() +end + +function CacheRadiusPly(pPly, vHit, nSca) + local plyPlace = GetPlacePly(pPly) + if(not IsExistent(plyPlace)) then + return StatusLog(nil,"CacheRadiusPly: Place missing") end + local plyData = plyPlace["RADIUS"] + if(not IsExistent(plyData)) then + LogInstance("CacheRadiusPly: Malloc <"..pPly:Nick()..">") + plyPlace["RADIUS"] = {}; plyData = plyPlace["RADIUS"] + plyData["MAR"] = (GetOpVar("GOLDEN_RATIO") * 1000) + plyData["LIM"] = ((GetOpVar("GOLDEN_RATIO") - 1) * 100) + end + local nMul = (tonumber(nSca) or 1) -- Disable scaling on missing or outside + nMul = ((nMul <= 1 and nMul >= 0) and nMul or 1) + local nMar, nLim = plyData["MAR"], plyData["LIM"] + local nDst = GetDistanceHitPly(pPly, vHit) + local nRad = ((nDst ~= 0) and mathClamp((nMar / nDst) * nMul, 1, nLim) or 0) + return nRad, nDis +end + +function CacheTracePly(pPly) + local plyPlace = GetPlacePly(pPly) + if(not IsExistent(plyPlace)) then + return StatusLog(nil,"CacheTracePly: Place missing") end + local plyData, plyTime = plyPlace["TRACE"], Time() + if(not IsExistent(plyData)) then -- Define trace delta margin + LogInstance("CacheTracePly: Malloc <"..pPly:Nick()..">") + plyPlace["TRACE"] = {}; plyData = plyPlace["TRACE"] + plyData["TDM"] = 0.02 -- Trace delta time margin + plyData["NXT"] = plyTime + plyData["TDM"] -- Define next trace pending + plyData["DAT"] = utilTraceLine(utilGetPlayerTrace(pPly)) -- Make a trace end -- Check the trace time margin interval - if(plyTime >= plyPlace["NXT"]) then - plyPlace["NXT"] = plyTime + plyPlace["TDM"] -- Next trace margin - plyPlace["DAT"] = utilTraceLine(utilGetPlayerTrace(pPly)) - end; return plyPlace["DAT"] + if(plyTime >= plyData["NXT"]) then + plyData["NXT"] = plyTime + plyData["TDM"] -- Next trace margin + plyData["DAT"] = utilTraceLine(utilGetPlayerTrace(pPly)) + end; return plyData["DAT"] end function ConCommandPly(pPly,sCvar,snValue) @@ -1572,53 +1624,57 @@ function UndoFinishPly(pPly,anyMessage) end function CachePressPly(pPly) - if(not IsPlayer(pPly)) then - return StatusLog(false,"CachePressPly: Player invalid <"..tostring(pPly)..">") end - local plyTable = GetOpVar("TABLE_PLAYER") - local plyPlace = plyTable[pPly] - if(plyPlace["CMD"]) then return true end -- Already cached + local plyPlace = GetPlacePly(pPly) if(not IsExistent(plyPlace)) then - plyTable[pPly] = {}; plyPlace = plyTable[pPly] end - local ucmdPressed = pPly:GetCurrentCommand() - if(not IsExistent(ucmdPressed)) then - return StatusLog(false,"CachePressPly: Obtained incorrectly") end - plyPlace["CMD"] = ucmdPressed - return StatusLog(true,"CachePressPly: Cached <"..tostring(pPly)..">") + return StatusLog(false,"CachePressPly: Place missing") end + local plyData = plyPlace["PRESS"] + if(not IsExistent(plyData)) then -- Create predicate command + LogInstance("CachePressPly: Malloc <"..pPly:Nick()..">") + plyPlace["PRESS"] = {}; plyData = plyPlace["PRESS"] + plyData["CMD"] = pPly:GetCurrentCommand() + if(not IsExistent(plyData["CMD"])) then + return StatusLog(false,"CachePressPly: Command incorrect") end + end; return true end +-- https://wiki.garrysmod.com/page/CUserCmd/GetMouseWheel function GetMouseWheelPly(pPly) - if(not IsPlayer(pPly)) then --- https://wiki.garrysmod.com/page/CUserCmd/GetMouseWheel - return StatusLog(false,"DeltaMousePly: Player invalid <"..tostring(pPly)">") end - local plyPlace = GetOpVar("TABLE_PLAYER")[pPly] + local plyPlace = GetPlacePly(pPly) if(not IsExistent(plyPlace)) then - return StatusLog(false,"DeltaMousePly: Cache missing <"..pPly:Nick()..">") end - local ucmdPressed = plyPlace["CMD"] - return (ucmdPressed and ucmdPressed:GetMouseWheel() or 0) + return StatusLog(0,"GetMouseWheelPly: Place missing") end + local plyData = plyPlace["PRESS"] + if(not IsExistent(plyData)) then + return StatusLog(0,"GetMouseWheelPly: Data missing <"..pPly:Nick()..">") end + local cmdPress = plyData["CMD"] + if(not IsExistent(cmdPress)) then + return StatusLog(0,"GetMouseWheelPly: Command missing <"..pPly:Nick()..">") end + return (cmdPress and cmdPress:GetMouseWheel() or 0) end +-- https://wiki.garrysmod.com/page/CUserCmd/GetMouse(XY) function GetMouseVectorPly(pPly) - if(not IsPlayer(pPly)) then --- https://wiki.garrysmod.com/page/CUserCmd/GetMouse(XY) - return StatusLog(false,"GetMouseVectorPly: Player <"..tostring(pPly)"> not available") end - local plyPlace = GetOpVar("TABLE_PLAYER")[pPly] + local plyPlace = GetPlacePly(pPly) + if(not IsExistent(plyPlace)) then + return 0, StatusLog(0,"GetMouseVectorPly: Place missing") end + local plyData = plyPlace["PRESS"] + if(not IsExistent(plyData)) then + return 0, StatusLog(0,"GetMouseVectorPly: Data missing <"..pPly:Nick()..">") end + local cmdPress = plyData["CMD"] + if(not IsExistent(plyData)) then + return 0, StatusLog(0,"GetMouseVectorPly: Command missing <"..pPly:Nick()..">") end + return cmdPress:GetMouseX(), cmdPress:GetMouseY() +end + +-- https://wiki.garrysmod.com/page/Enums/IN +function CheckButtonPly(pPly, iInKey) + local plyPlace, iInKey = GetPlacePly(pPly), (tonumber(iInKey) or 0) if(not IsExistent(plyPlace)) then - return StatusLog(false,"GetMouseVectorPly: Cache missing <"..pPly:Nick()..">") end - local ucmdPressed = plyPlace["CMD"] - local ucmdX = (ucmdPressed and ucmdPressed:GetMouseX() or 0) - local ucmdY = (ucmdPressed and ucmdPressed:GetMouseY() or 0) - return ucmdX, ucmdY -end - -function CheckButtonPly(pPly, ivInKey) - if(not IsPlayer(pPly)) then --- https://wiki.garrysmod.com/page/Enums/IN - return StatusLog(false,"CheckButtonPly: Player invalid <"..tostring(pPly)">") end - local iInKey = tonumber(ivInKey) - if(not IsExistent(iInKey)) then - return StatusLog(false,"CheckButtonPly: Input key {"..type(ivInKey)"}<"..tostring(ivInKey).."> invalid") end - local plyPlace = GetOpVar("TABLE_PLAYER")[pPly] - if(CLIENT or (not IsExistent(plyPlace))) then return pPly:KeyDown(iInKey) end - local ucmdPressed = plyPlace["CMD"] - if(not IsExistent(ucmdPressed)) then return pPly:KeyDown(iInKey) end - return (bitBand(ucmdPressed:GetButtons(),iInKey) ~= 0) -- Read the cache + return StatusLog(false,"GetMouseVectorPly: Place missing") end + local plyData = plyPlace["PRESS"] + if(not IsExistent(plyData)) then return pPly:KeyDown(iInKey) end + local cmdPress = plyData["CMD"] + if(not IsExistent(cmdPress)) then return pPly:KeyDown(iInKey) end + return (bitBand(cmdPress:GetButtons(),iInKey) ~= 0) -- Read the cache end -------------------------- BUILDSQL ------------------------------ @@ -3069,7 +3125,7 @@ end * ucsPos(X,Y,Z) = Offset position * ucsAng(P,Y,R) = Offset angle ]]-- -function GetNormalSpawn(ucsPos,ucsAng,shdModel,ivhdPointID,ucsPosX,ucsPosY,ucsPosZ,ucsAngP,ucsAngY,ucsAngR) +function GetNormalSpawn(oPly,ucsPos,ucsAng,shdModel,ivhdPointID,ucsPosX,ucsPosY,ucsPosZ,ucsAngP,ucsAngY,ucsAngR) local hdRec = CacheQueryPiece(shdModel) if(not IsExistent(hdRec)) then return StatusLog(nil,"GetNormalSpawn: No record located for <"..shdModel..">") end @@ -3079,7 +3135,7 @@ function GetNormalSpawn(ucsPos,ucsAng,shdModel,ivhdPointID,ucsPosX,ucsPosY,ucsPo local hdPOA = LocatePOA(hdRec,ihdPointID) if(not IsExistent(hdPOA)) then return StatusLog(nil,"GetNormalSpawn: Holder point ID invalid #"..tostring(ihdPointID)) end - local stSpawn = GetOpVar("STRUCT_SPAWN"); stSpawn.HRec = hdRec + local stSpawn = CacheSpawnPly(oPly); stSpawn.HRec = hdRec if(ucsPos) then SetVector(stSpawn.OPos,ucsPos) end if(ucsAng) then SetAngle (stSpawn.OAng,ucsAng) end -- Initialize F, R, U Copy the UCS like that to support database POA @@ -3127,7 +3183,7 @@ end * ucsPos(X,Y,Z) = Offset position * ucsAng(P,Y,R) = Offset angle ]]-- -function GetEntitySpawn(trEnt,trHitPos,shdModel,ivhdPointID, +function GetEntitySpawn(oPly,trEnt,trHitPos,shdModel,ivhdPointID, nvActRadius,enFlatten,enIgnTyp,ucsPosX, ucsPosY,ucsPosZ,ucsAngP,ucsAngY,ucsAngR) if(not (trEnt and trHitPos and shdModel and ivhdPointID and nvActRadius)) then @@ -3162,7 +3218,7 @@ function GetEntitySpawn(trEnt,trHitPos,shdModel,ivhdPointID, if((not enIgnTyp) and (trRec.Type ~= hdRec.Type)) then return StatusLog(nil,"GetEntitySpawn: Types different <"..tostring(trRec.Type)..","..tostring(hdRec.Type)..">") end -- We have the next Piece Offset - local stSpawn, trPOA = GetOpVar("STRUCT_SPAWN") + local stSpawn, trPOA = CacheSpawnPly(oPly) stSpawn.TRec = trRec stSpawn.RLen = nActRadius stSpawn.HID = ihdPointID @@ -3194,7 +3250,7 @@ function GetEntitySpawn(trEnt,trHitPos,shdModel,ivhdPointID, stSpawn.OAng:Set(trEnt:LocalToWorldAngles(stSpawn.OAng)) -- Do the flatten flag right now Its important ! if(enFlatten) then stSpawn.OAng[caP] = 0; stSpawn.OAng[caR] = 0 end - return GetNormalSpawn(nil,nil,shdModel,ihdPointID,ucsPosX,ucsPosY,ucsPosZ,ucsAngP,ucsAngY,ucsAngR) + return GetNormalSpawn(oPly,nil,nil,shdModel,ihdPointID,ucsPosX,ucsPosY,ucsPosZ,ucsAngP,ucsAngY,ucsAngR) end --[[ @@ -3420,7 +3476,7 @@ function IntersectRayModel(sModel, nPntID, nNxtID) -- Attempts taking the mean vector when the rays are parallel for straight tracks if(not xx) then f1, f2, x1, x2, xx = IntersectRayParallel(vO1,vD1,vO2,vD2) end - return xx, x1, x2, vO1, vO2 + return xx, vO1, vO2 end function AttachAdditions(ePiece) diff --git a/lua/weapons/gmod_tool/stools/trackassembly.lua b/lua/weapons/gmod_tool/stools/trackassembly.lua index 1c4e7719..ef136b72 100644 --- a/lua/weapons/gmod_tool/stools/trackassembly.lua +++ b/lua/weapons/gmod_tool/stools/trackassembly.lua @@ -100,7 +100,7 @@ TOOL.ClientConVar = { [ "nextpic" ] = "0", [ "nextyaw" ] = "0", [ "nextrol" ] = "0", - [ "mcspawn" ] = "0", + [ "spawncn" ] = "0", [ "bgskids" ] = "", [ "gravity" ] = "1", [ "adviser" ] = "1", @@ -142,6 +142,7 @@ if(CLIENT) then end if(SERVER) then + hookAdd("PlayerDisconnected", gsToolPrefL.."player_quit", asmlib.GetActionCode("PLAYER_QUIT")) hookAdd("PhysgunDrop", gsToolPrefL.."physgun_drop_snap", asmlib.GetActionCode("PHYSGUN_DROP")) duplicatorRegisterEntityModifier(gsToolPrefL.."dupe_phys_set",asmlib.GetActionCode("DUPE_PHYS_SETTINGS")) end @@ -265,8 +266,8 @@ function TOOL:GetIgnorePhysgun() return ((self:GetClientNumber("ignphysgn") or 0) ~= 0) end -function TOOL:GetSpawnMC() - return ((self:GetClientNumber("mcspawn") or 0) ~= 0) +function TOOL:GetSpawnCenter() + return ((self:GetClientNumber("spawncn") or 0) ~= 0) end function TOOL:GetStackAttempts() @@ -307,18 +308,20 @@ function TOOL:SwitchPoint(nDir,bIsNext) return pointid, pnextid end -function TOOL:IntersectClear(bEnb) - local ntEnb = tobool(bEnb) - local oPly = self:GetOwner() +function TOOL:IntersectClear(bRel) + local bRel = tobool(bRel) + local oPly = self:GetOwner() local stRay = asmlib.IntersectRayRead(oPly, "ray_relate") if(SERVER) then - local ryEnt = stRay.Ent - if(stRay and ryEnt and ryEnt:IsValid()) then - ryEnt:SetColor(conPalette:Select("w")) end - if(ntEnb) then asmlib.PrintNotifyPly(oPly,"Intersection relation clear !","CLEANUP") end - netStart(gsLibName.."SendIntersectClear"); netSend(oPly) - end; asmlib.IntersectRayClear(oPly, "ray_relate") - return asmlib.StatusLog(true,"TOOL:IntersectClear("..tostring(ntEnb).."): Relation cleared") + if(stRay) then + local ryEnt = stRay.Ent + if(ryEnt and ryEnt:IsValid()) then ryEnt:SetColor(conPalette:Select("w")) end + if(bRel) then + asmlib.PrintNotifyPly(oPly,"Intersection relation clear !","CLEANUP") + netStart(gsLibName.."SendIntersectClear"); netWriteEntity(oPly); netSend(oPly) + end; asmlib.IntersectRayClear(oPly, "ray_relate") + end + end; return asmlib.StatusLog(true,"TOOL:IntersectClear("..tostring(bRel).."): Relation cleared") end function TOOL:IntersectRelate(oPly, oEnt, vHit) @@ -328,10 +331,10 @@ function TOOL:IntersectRelate(oPly, oEnt, vHit) return asmlib.StatusLog(false,"TOOL:IntersectRelate(): Update fail") end if(SERVER) then netStart(gsLibName.."SendIntersectRelate") - netWriteEntity(oEnt); netWriteVector(vHit); netSend(oPly) + netWriteEntity(oEnt); netWriteVector(vHit); netWriteEntity(oPly); netSend(oPly) local femod = stringToFileName(oEnt:GetModel()) asmlib.PrintNotifyPly(oPly,"Intersection relation: "..femod.." !","UNDO") - stRay.Ent:SetColor(conPalette:Select("ry")); asmlib.Print(tRay,"ActiveRay") + stRay.Ent:SetColor(conPalette:Select("ry")) end return true end @@ -347,7 +350,7 @@ function TOOL:IntersectSnap(trEnt, vHit, stSpawn, bLoop) return asmlib.StatusLog(nil, "TOOL:IntersectSnap(): Active ray mismatch") end end - local mx, m1, m2, o1, o2 = asmlib.IntersectRayModel(model, pointid, pnextid) + local mx, o1, o2 = asmlib.IntersectRayModel(model, pointid, pnextid) if(not mx) then if(bLoop) then return nil else return asmlib.StatusLog(nil, "TOOL:IntersectSnap(): Model ray mismatch") end @@ -465,7 +468,6 @@ function TOOL:GetStatus(stTrace,anyMessage,hdEnt) sDu = sDu..sSpace.." HD.Mass: <"..tostring(self:GetMass())..">"..sDelim sDu = sDu..sSpace.." HD.StackCNT: <"..tostring(self:GetCount())..">"..sDelim sDu = sDu..sSpace.." HD.Freeze: <"..tostring(self:GetFreeze())..">"..sDelim - sDu = sDu..sSpace.." HD.SpawnMC: <"..tostring(self:GetSpawnMC())..">"..sDelim sDu = sDu..sSpace.." HD.YawSnap: <"..tostring(self:GetYawSnap())..">"..sDelim sDu = sDu..sSpace.." HD.Gravity: <"..tostring(self:GetGravity())..">"..sDelim sDu = sDu..sSpace.." HD.Adviser: <"..tostring(self:GetAdviser())..">"..sDelim @@ -476,6 +478,7 @@ function TOOL:GetStatus(stTrace,anyMessage,hdEnt) sDu = sDu..sSpace.." HD.SpawnFlat: <"..tostring(self:GetSpawnFlat())..">"..sDelim sDu = sDu..sSpace.." HD.IgnoreType: <"..tostring(self:GetIgnoreType())..">"..sDelim sDu = sDu..sSpace.." HD.SurfSnap: <"..tostring(self:GetSurfaceSnap())..">"..sDelim + sDu = sDu..sSpace.." HD.SpawnCen: <"..tostring(self:GetSpawnCenter())..">"..sDelim sDu = sDu..sSpace.." HD.Workmode: ["..tostring(workmode or gsNoAV).."]<"..tostring(workname or gsNoAV)..">"..sDelim sDu = sDu..sSpace.." HD.AppAngular: <"..tostring(self:ApplyAngularFirst())..">"..sDelim sDu = sDu..sSpace.." HD.AppLinear: <"..tostring(self:ApplyLinearFirst())..">"..sDelim @@ -533,7 +536,6 @@ function TOOL:LeftClick(stTrace) local count = self:GetCount() local ply = self:GetOwner() local freeze = self:GetFreeze() - local mcspawn = self:GetSpawnMC() local ydegsnp = self:GetYawSnap() local gravity = self:GetGravity() local elevpnt = self:GetElevation() @@ -541,6 +543,7 @@ function TOOL:LeftClick(stTrace) local spnflat = self:GetSpawnFlat() local igntype = self:GetIgnoreType() local forcelim = self:GetForceLimit() + local spawncn = self:GetSpawnCenter() local surfsnap = self:GetSurfaceSnap() local workmode = self:GetWorkingMode() local physmater = self:GetPhysMeterial() @@ -557,15 +560,14 @@ function TOOL:LeftClick(stTrace) local nextx , nexty , nextz = self:GetPosOffsets() local nextpic, nextyaw, nextrol = self:GetAngOffsets() if(stTrace.HitWorld) then -- Switch the tool mode ( Spawn ) - local vPos = Vector() + local vPos = Vector(); vPos:Set(stTrace.HitPos) local aAng = asmlib.GetNormalAngle(ply,stTrace,surfsnap,ydegsnp) - if(mcspawn) then -- Spawn on mass centre + if(spawncn) then -- Spawn on mass centre aAng:RotateAroundAxis(aAng:Up() ,-nextyaw) aAng:RotateAroundAxis(aAng:Right() , nextpic) aAng:RotateAroundAxis(aAng:Forward(), nextrol) - vPos:Set(stTrace.HitPos) else - local stSpawn = asmlib.GetNormalSpawn(stTrace.HitPos + elevpnt * stTrace.HitNormal,aAng,model, + local stSpawn = asmlib.GetNormalSpawn(ply,stTrace.HitPos + elevpnt * stTrace.HitNormal,aAng,model, pointid,nextx,nexty,nextz,nextpic,nextyaw,nextrol) if(not stSpawn) then -- Make sure it persists to set it afterwards return asmlib.StatusLog(false,self:GetStatus(stTrace,"TOOL:LeftClick(World): Cannot obtain spawn data")) end @@ -573,10 +575,11 @@ function TOOL:LeftClick(stTrace) end local ePiece = asmlib.MakePiece(ply,model,vPos,aAng,mass,bgskids,conPalette:Select("w"),bnderrmod) if(ePiece) then - if(mcspawn) then -- Adjust the position when created correctly - asmlib.SetVectorXYZ(vPos,nextx,nexty,nextz) - vPos:Add(asmlib.GetCenterMC(ePiece)); vPos:Rotate(aAng); - vPos:Add(ePiece:GetPos()); ePiece:SetPos(vPos) + if(spawncn) then -- Adjust the position when created correctly + local vOBB = ePiece:OBBMins() + local vCen = asmlib.GetCenter(ePiece) + asmlib.AddVectorXYZ(vCen, nextx, -nexty, nextz-vOBB[cvZ]) + vCen:Rotate(aAng); vPos:Add(vCen); ePiece:SetPos(vPos) end if(not asmlib.ApplyPhysicalSettings(ePiece,ignphysgn,freeze,gravity,physmater)) then return asmlib.StatusLog(false,self:GetStatus(stTrace,"TOOL:LeftClick(World): Failed to apply physical settings",ePiece)) end @@ -603,7 +606,7 @@ function TOOL:LeftClick(stTrace) local hdRec = asmlib.CacheQueryPiece(model) if(not hdRec) then return asmlib.StatusLog(false,self:GetStatus(stTrace,"TOOL:LeftClick(Prop): Holder model not piece")) end - local stSpawn = asmlib.GetEntitySpawn(trEnt,stTrace.HitPos,model,pointid, + local stSpawn = asmlib.GetEntitySpawn(ply,trEnt,stTrace.HitPos,model,pointid, actrad,spnflat,igntype,nextx,nexty,nextz,nextpic,nextyaw,nextrol) if(not stSpawn) then -- Not aiming into an active point update settings/properties if(asmlib.CheckButtonPly(ply,IN_USE)) then -- Physical @@ -650,7 +653,7 @@ function TOOL:LeftClick(stTrace) asmlib.UndoAddEntityPly(ePieceN) if(appangfst) then nextpic,nextyaw,nextrol, appangfst = 0,0,0,false end if(applinfst) then nextx ,nexty ,nextz , applinfst = 0,0,0,false end - stSpawn = asmlib.GetEntitySpawn(ePieceN,vTemp,model,pointid, + stSpawn = asmlib.GetEntitySpawn(ply,ePieceN,vTemp,model,pointid, actrad,spnflat,igntype,nextx,nexty,nextz,nextpic,nextyaw,nextrol) if(not stSpawn) then -- Look both ways in a one way street :D asmlib.PrintNotifyPly(ply,"Cannot obtain spawn data!","ERROR") @@ -726,8 +729,10 @@ function TOOL:RightClick(stTrace) end function TOOL:Reload(stTrace) - if(CLIENT) then return asmlib.StatusLog(true,"TOOL:Reload(): Working on client") end - if(not stTrace) then return asmlib.StatusLog(false,"TOOL:Reload(): Invalid trace") end + if(CLIENT) then + return asmlib.StatusLog(true,"TOOL:Reload(): Working on client") end + if(not stTrace) then + return asmlib.StatusLog(false,"TOOL:Reload(): Invalid trace") end local ply = self:GetOwner() local trEnt = stTrace.Entity local workmode = self:GetWorkingMode() @@ -782,7 +787,7 @@ function TOOL:UpdateGhost(ePiece, oPly) ePiece:SetNoDraw(true) ePiece:DrawShadow(false) ePiece:SetColor(conPalette:Select("gh")) - local stTrace = asmlib.GetTracePly(oPly) + local stTrace = asmlib.CacheTracePly(oPly) if(not stTrace) then return end local trEnt = stTrace.Entity local model = self:GetModel() @@ -793,19 +798,18 @@ function TOOL:UpdateGhost(ePiece, oPly) if(stTrace.HitWorld) then local ydegsnp = self:GetYawSnap() local surfsnap = self:GetSurfaceSnap() - local aAng = asmlib.GetNormalAngle(oPly,stTrace,surfsnap,ydegsnp) - if(self:GetSpawnMC()) then - ePiece:SetAngles(aAng) - local vOBB = ePiece:OBBMins() - local vCen = asmlib.GetCenterMC(ePiece) - asmlib.AddVectorXYZ(vCen, nextx, nexty, nextz-vOBB[cvZ]) + local aAng = asmlib.GetNormalAngle(oPly,stTrace,surfsnap,ydegsnp) + if(self:GetSpawnCenter()) then aAng:RotateAroundAxis(aAng:Up() ,-nextyaw) aAng:RotateAroundAxis(aAng:Right() , nextpic) aAng:RotateAroundAxis(aAng:Forward(), nextrol) - vCen:Rotate(aAng); vCen:Add(stTrace.HitPos) - ePiece:SetPos(vCen); ePiece:SetAngles(aAng); ePiece:SetNoDraw(false) + local vOBB, vPos = ePiece:OBBMins(), Vector(); vPos:Set(stTrace.HitPos) + local vCen = asmlib.GetCenter(ePiece) + asmlib.AddVectorXYZ(vCen, nextx, -nexty, nextz-vOBB[cvZ]) + vCen:Rotate(aAng); vPos:Add(vCen) + ePiece:SetPos(vPos); ePiece:SetAngles(aAng); ePiece:SetNoDraw(false) else - local stSpawn = asmlib.GetNormalSpawn(stTrace.HitPos + self:GetElevation() * stTrace.HitNormal, + local stSpawn = asmlib.GetNormalSpawn(oPly,stTrace.HitPos + self:GetElevation() * stTrace.HitNormal, aAng,model,pointid,nextx,nexty,nextz,nextpic,nextyaw,nextrol) if(stSpawn) then ePiece:SetAngles(stSpawn.SAng); ePiece:SetPos(stSpawn.SPos); ePiece:SetNoDraw(false) @@ -818,7 +822,7 @@ function TOOL:UpdateGhost(ePiece, oPly) local spnflat = self:GetSpawnFlat() local igntype = self:GetIgnoreType() local actrad = self:GetActiveRadius() - local stSpawn = asmlib.GetEntitySpawn(trEnt,stTrace.HitPos,model,pointid, + local stSpawn = asmlib.GetEntitySpawn(oPly,trEnt,stTrace.HitPos,model,pointid, actrad,spnflat,igntype,nextx,nexty,nextz,nextpic,nextyaw,nextrol) if(stSpawn) then if(workmode == 2) then @@ -832,15 +836,15 @@ end function TOOL:ElevateGhost(oEnt, oPly) if(not (oPly and oPly:IsValid() and oPly:IsPlayer())) then return asmlib.StatusLog(nil, "TOOL:ElevateGhost: Player invalid <"..tostring(oPly)..">") end - local mcspawn, elevpnt = self:GetSpawnMC() + local spawncn, elevpnt = self:GetSpawnCenter() if(oEnt and oEnt:IsValid()) then - if(mcspawn) then -- Distance for the piece spawned on the ground + if(spawncn) then -- Distance for the piece spawned on the ground local vobdbox = oEnt:OBBMins(); elevpnt = -vobdbox[cvZ] else -- Refresh the variable when model changes to unload the network local pointid, pnextid = self:GetPointID() elevpnt = (asmlib.GetPointElevation(oEnt, pointid) or 0) end; asmlib.ConCommandPly(oPly, "elevpnt", elevpnt) - asmlib.LogInstance("TOOL:ElevateGhost("..tostring(mcspawn).."): <"..tostring(elevpnt)..">") + asmlib.LogInstance("TOOL:ElevateGhost("..tostring(spawncn).."): <"..tostring(elevpnt)..">") end end @@ -870,10 +874,11 @@ end * tArgs > Text draw arguments ]]-- function TOOL:DrawTextSpawn(oScreen, sCol, sMeth, tArgs) - local stS = asmlib.GetOpVar("STRUCT_SPAWN") - local arK = asmlib.GetOpVar("STRUCT_SPAWN_KEYS") - local x,y = oScreen:GetCenter(10,10) - oScreen:SetTextEdge(x,y) + local ply = LocalPlayer() + local stS = asmlib.CacheSpawnPly(ply) + local arK = asmlib.GetOpVar("STRUCT_SPAWN") + local w,h = oScreen:GetSize() + oScreen:SetTextEdge(w - 500,0) oScreen:DrawText("Spawn debug information",sCol,sMeth,tArgs) for ID = 1, #arK, 1 do local def = arK[ID] @@ -885,23 +890,21 @@ function TOOL:DrawTextSpawn(oScreen, sCol, sMeth, tArgs) end end -function TOOL:DrawRelateIntersection(oScreen, oPly, stSpawn, nRad) +function TOOL:DrawRelateIntersection(oScreen, oPly, nRad) if(self:GetDrawRelationRay()) then local stRay = asmlib.IntersectRayRead(oPly, "ray_relate") if(stRay) then local rOrg, rDir = stRay.Orw, stRay.Diw local Rp, nLn = rOrg:ToScreen(), self:GetActiveRadius() - local Re = (rOrg + nLn * rDir:Forward()):ToScreen() - local rF = oScreen:GetDistance(Rp, Re) - local rU = 2 * oScreen:GetDistance(Rp, Ru) - local nR = ((rF > rU) and rF or rU) + local Rf = (rOrg + nLn * rDir:Forward()):ToScreen() local Ru = (rOrg + nLn * 0.5 * rDir:Up()):ToScreen() - if(bEnb) then - oScreen:DrawLine(Rp, Re, "r") - oScreen:DrawLine(Rp, Ru, "b") - oScreen:DrawCircle(Rp, nR / 6, "y") - return Rp, Re - end; return nil + local rF = (oScreen:GetDistance(Rp, Rf) or 0) + local rU = 2 * (oScreen:GetDistance(Rp, Ru) or 0) + local nR = ((rF > rU) and rF or rU) + oScreen:DrawLine(Rp, Rf, "r") + oScreen:DrawLine(Rp, Ru, "b") + oScreen:DrawCircle(Rp, nR / 6, "y") + return Rp, Rf, Ru end; return nil end; return nil end @@ -909,38 +912,35 @@ end function TOOL:DrawModelIntersection(oScreen, oPly, stSpawn, nRad) local model = self:GetModel() local pointid, pnextid = self:GetPointID() - local xx, x1, x2, vO1, vO2 = asmlib.IntersectRayModel(model, pointid, pnextid) + local xx, vO1, vO2 = asmlib.IntersectRayModel(model, pointid, pnextid) if(xx) then local sPos, sAng = stSpawn.SPos, stSpawn.SAng xx:Rotate(sAng); xx:Add(sPos) vO1:Rotate(sAng); vO1:Add(sPos) vO2:Rotate(sAng); vO2:Add(sPos) + local xX = xx:ToScreen() local Os, Ss = stSpawn.OPos:ToScreen(), sPos:ToScreen() - local xX, X1, X2 = xx:ToScreen(), x1:ToScreen(), x2:ToScreen() local O1, O2 = vO1:ToScreen(), vO2:ToScreen() oScreen:DrawLine(Os,Ss,"m") oScreen:DrawCircle(Ss, nRad,"c") oScreen:DrawCircle(xX, 3 * nRad, "ry") - oScreen:DrawLine(xX,O1); oScreen:DrawLine(xX,X1) - oScreen:DrawLine(xX,O2); oScreen:DrawLine(xX,X2) + oScreen:DrawLine(xX,O1) + oScreen:DrawLine(xX,O2) oScreen:DrawCircle(O1, nRad / 2, "r") oScreen:DrawCircle(O2, nRad / 2, "g") - return xX, X1, X2, O1, O2 + return xX, O1, O2 end; return nil end function TOOL:DrawUCS(oScreen, vHit, vOrg, aOrg, nRad) - local uOrg, uAng, UCS = Vector(), Angle(), 30 - if(vOrg) then uOrg:Set(vOrg) else uOrg:Set(stSpawn.OPos) end - if(aOrg) then uAng:Set(aOrg) else uAng:Set(stSpawn.OAng) end - local Os, Tp = uOrg:ToScreen(), vHit:ToScreen() - local Xs = (UCS * uAng:Forward() + uOrg):ToScreen() - local Ys = (UCS * uAng:Right () + uOrg):ToScreen() - local Zs = (UCS * uAng:Up () + uOrg):ToScreen() + local Os, Tp, UCS = vOrg:ToScreen(), vHit:ToScreen(), 30 + local Xs = (vOrg + UCS * aOrg:Forward()):ToScreen() + local Zs = (vOrg + UCS * aOrg:Up()):ToScreen() + local Ys = (vOrg + UCS * aOrg:Right()):ToScreen() oScreen:DrawLine(Os,Xs,"r","SURF") + oScreen:DrawCircle(Os,nRad,"y","SURF") oScreen:DrawLine(Os,Ys,"g") oScreen:DrawLine(Os,Zs,"b") - oScreen:DrawCircle(Os, nRad,"y") - oScreen:DrawLine(Os,Tp) + oScreen:DrawLine(Os,Tp,"y") oScreen:DrawCircle(Tp, nRad / 2) return Os, Tp end @@ -959,7 +959,7 @@ function TOOL:DrawHUD() end; hudMonitor:SetColor() if(not self:GetAdviser()) then return end local ply = LocalPlayer() - local stTrace = asmlib.GetTracePly(ply) + local stTrace = asmlib.CacheTracePly(ply) if(not stTrace) then return end local ratioc = (gnRatio - 1) * 100 local ratiom = (gnRatio * 1000) @@ -976,7 +976,7 @@ function TOOL:DrawHUD() local igntype = self:GetIgnoreType() local actrad = self:GetActiveRadius() local trPos, trAng = trEnt:GetPos(), trEnt:GetAngles() - local stSpawn = asmlib.GetEntitySpawn(trEnt,stTrace.HitPos,model,pointid, + local stSpawn = asmlib.GetEntitySpawn(ply,trEnt,stTrace.HitPos,model,pointid, actrad,spnflat,igntype,nextx,nexty,nextz,nextpic,nextyaw,nextrol) if(not stSpawn) then if(not self:GetPointAssist()) then return end @@ -998,10 +998,10 @@ function TOOL:DrawHUD() end; return end local nRad = mathClamp((ratiom / plyd) * (stSpawn.RLen / actrad),1,ratioc) - local Os, Tp = self:DrawUCS(hudMonitor, stTrace.HitPos, stSpawn.OPos, stSpawn.OAng, stSpawn, nRad, true) + local Os, Tp = self:DrawUCS(hudMonitor, stTrace.HitPos, stSpawn.OPos, stSpawn.OAng, nRad) local Pp = stSpawn.TPnt:ToScreen() - oScreen:DrawLine(Os,Pp,"r") - oScreen:DrawCircle(Pp, nRad / 2) + hudMonitor:DrawLine(Os,Pp,"r") + hudMonitor:DrawCircle(Pp, nRad / 2) if(workmode == 1) then local nxPOA = asmlib.LocatePOA(stSpawn.HRec,pnextid) if(nxPOA and stSpawn.HRec.Kept > 1) then @@ -1011,17 +1011,19 @@ function TOOL:DrawHUD() hudMonitor:DrawLine(Os,Np,"g") hudMonitor:DrawCircle(Np, nRad / 2, "g") end - local Ss = stSpawn.SPos:ToScreen() - hudMonitor:DrawLine(Os,Ss,"m") - hudMonitor:DrawCircle(Ss, nRad,"c") elseif(workmode == 2) then -- Draw point intersection - local Rp, Re = self:DrawRelateIntersection(hudMonitor, ply, stSpawn, nRad) - local xX, X1, X2, O1, O2 = self:DrawModelIntersection(hudMonitor, ply, stSpawn, nRad) + self:IntersectSnap(trEnt, stTrace.HitPos, stSpawn, true) + local Rp, Re = self:DrawRelateIntersection(hudMonitor, ply, nRad) + local xX, O1, O2 = self:DrawModelIntersection(hudMonitor, ply, stSpawn, nRad) if(Rp) then + hudMonitor:DrawLine(Rp,xX,"ry") hudMonitor:DrawLine(Rp,O2,"g") hudMonitor:DrawLine(Os,O1,"r") end end + local Ss = stSpawn.SPos:ToScreen() + hudMonitor:DrawLine(Os,Ss,"m") + hudMonitor:DrawCircle(Ss, nRad,"c") if(not self:GetDeveloperMode()) then return end self:DrawTextSpawn(hudMonitor, "k","SURF",{"Trebuchet18"}) elseif(stTrace.HitWorld) then @@ -1031,16 +1033,18 @@ function TOOL:DrawHUD() local workmode = self:GetWorkingMode() local nRad = mathClamp(ratiom / plyd,1,ratioc) local aAng = asmlib.GetNormalAngle(ply,stTrace,surfsnap,ydegsnp) - if(self:GetSpawnMC()) then -- Relative to MC + if(self:GetSpawnCenter()) then -- Relative to MC + aAng:RotateAroundAxis(aAng:Up() ,-nextyaw) + aAng:RotateAroundAxis(aAng:Right() , nextpic) + aAng:RotateAroundAxis(aAng:Forward(), nextrol) local vPos = Vector() vPos:Set(stTrace.HitPos + elevpnt * stTrace.HitNormal) vPos:Add(nextx * aAng:Forward()) vPos:Add(nexty * aAng:Right()) vPos:Add(nextz * aAng:Up()) - aAng:RotateAroundAxis(aAng:Up() ,-nextyaw) - aAng:RotateAroundAxis(aAng:Right() , nextpic) - aAng:RotateAroundAxis(aAng:Forward(), nextrol) local Os, Tp = self:DrawUCS(hudMonitor, stTrace.HitPos, vPos, aAng, nRad) + if(workmode == 2) then -- Draw point intersection + self:DrawRelateIntersection(hudMonitor, ply, nRad) end if(not self:GetDeveloperMode()) then return end local x,y = hudMonitor:GetCenter(10,10) hudMonitor:SetTextEdge(x,y) @@ -1048,7 +1052,7 @@ function TOOL:DrawHUD() hudMonitor:DrawText("Org ANG: "..tostring(aAng)) else -- Relative to the active Point if(not (pointid > 0 and pnextid > 0)) then return end - local stSpawn = asmlib.GetNormalSpawn(stTrace.HitPos + elevpnt * stTrace.HitNormal, + local stSpawn = asmlib.GetNormalSpawn(ply,stTrace.HitPos + elevpnt * stTrace.HitNormal, aAng,model,pointid,nextx,nexty,nextz,nextpic,nextyaw,nextrol) if(not stSpawn) then return end local Os, Tp = self:DrawUCS(hudMonitor, stTrace.HitPos, stSpawn.OPos, stSpawn.OAng, nRad) @@ -1063,13 +1067,13 @@ function TOOL:DrawHUD() hudMonitor:DrawLine(Os,Np,"g") hudMonitor:DrawCircle(Np,nRad / 2) end - local Ss = stSpawn.SPos:ToScreen() - hudMonitor:DrawLine(Os,Ss,"m") - hudMonitor:DrawCircle(Ss, nRad,"c") elseif(workmode == 2) then -- Draw point intersection - self:DrawRelateIntersection(hudMonitor, ply, stSpawn, nRad) + self:DrawRelateIntersection(hudMonitor, ply, nRad) self:DrawModelIntersection (hudMonitor, ply, stSpawn, nRad) end + local Ss = stSpawn.SPos:ToScreen() + hudMonitor:DrawLine(Os,Ss,"m") + hudMonitor:DrawCircle(Ss, nRad,"c") if(not self:GetDeveloperMode()) then return end self:DrawTextSpawn(hudMonitor, "k","SURF",{"Trebuchet18"}) end @@ -1088,7 +1092,8 @@ function TOOL:DrawToolScreen(w, h) end; scrTool:SetColor() scrTool:DrawRect({x=0,y=0},{x=w,y=h},"k","SURF",{"vgui/white"}) scrTool:SetTextEdge(0,0) - local stTrace = asmlib.GetTracePly(LocalPlayer()) + local oPly = LocalPlayer() + local stTrace = asmlib.CacheTracePly(oPly) local anInfo, anEnt = self:GetAnchor() local tInfo = stringExplode(gsSymRev,anInfo) if(not (stTrace and stTrace.Hit)) then @@ -1120,7 +1125,7 @@ function TOOL:DrawToolScreen(w, h) local trRec = asmlib.CacheQueryPiece(trModel) local nextx, nexty, nextz = self:GetPosOffsets() local nextpic, nextyaw, nextrol = self:GetAngOffsets() - local stSpawn = asmlib.GetEntitySpawn(trEnt,stTrace.HitPos,model,pointid, + local stSpawn = asmlib.GetEntitySpawn(oPly,trEnt,stTrace.HitPos,model,pointid, actrad,spnflat,igntype,nextx,nexty,nextz,nextpic,nextyaw,nextrol) if(stSpawn) then trOID = stSpawn.TID @@ -1339,8 +1344,8 @@ function TOOL.BuildCPanel(CPanel) pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".igntype")) pItem = CPanel:CheckBox (languageGetPhrase ("tool."..gsToolNameL..".spnflat_con"), gsToolPrefL.."spnflat") pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".spnflat")) - pItem = CPanel:CheckBox (languageGetPhrase ("tool."..gsToolNameL..".mcspawn_con"), gsToolPrefL.."mcspawn") - pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".mcspawn")) + pItem = CPanel:CheckBox (languageGetPhrase ("tool."..gsToolNameL..".spawncn_con"), gsToolPrefL.."spawncn") + pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".spawncn")) pItem = CPanel:CheckBox (languageGetPhrase ("tool."..gsToolNameL..".surfsnap_con"), gsToolPrefL.."surfsnap") pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".surfsnap")) pItem = CPanel:CheckBox (languageGetPhrase ("tool."..gsToolNameL..".appangfst_con"), gsToolPrefL.."appangfst")