From 6f4ff6850f9fb6c5371d6f7db502047f47ecc4bc Mon Sep 17 00:00:00 2001 From: Deyan Dobromirov Date: Fri, 3 Jun 2016 17:42:27 +0300 Subject: [PATCH] Added: "self.player" usage in the wire extension in server-side Removed: Discontinued AddControl( string type, table controlinfo ) Removed: Temporary variables for name and type in the panel Updated: LoadKeyPly to player info hash Updated: IsPlayer and IsOther --- data/todo.txt | 9 +- lua/autorun/trackassembly_init.lua | 2 +- .../core/custom/trackasmlib_wire.lua | 19 +- lua/trackassembly/trackasmlib.lua | 101 ++++---- .../gmod_tool/stools/trackassembly.lua | 230 ++++++------------ 5 files changed, 138 insertions(+), 223 deletions(-) diff --git a/data/todo.txt b/data/todo.txt index ad106918..297ef689 100644 --- a/data/todo.txt +++ b/data/todo.txt @@ -4,5 +4,10 @@ D - Discontinued N - Not applicable ? - Not yet tested -Make TA export the database in Unix format -Make the player own the track spawned +? Make TA export the database in Unix format +V Make the player own the track spawned + Check what these return + ["USERID"] = pPly:UserID(), + ["STEAMID"] = pPly:SteamID(), + ["UNIQUEID"] = pPly:UniqueID(), + ["STEAMID64"] = pPly:SteamID64() diff --git a/lua/autorun/trackassembly_init.lua b/lua/autorun/trackassembly_init.lua index 90a88e7c..4886c324 100644 --- a/lua/autorun/trackassembly_init.lua +++ b/lua/autorun/trackassembly_init.lua @@ -26,7 +26,7 @@ local asmlib = trackasmlib ------ CONFIGURE ASMLIB ------ asmlib.InitAssembly("track","assembly") -asmlib.SetOpVar("TOOL_VERSION","5.242") +asmlib.SetOpVar("TOOL_VERSION","5.243") asmlib.SetLogControl(0,"") asmlib.SetIndexes("V",1,2,3) asmlib.SetIndexes("A",1,2,3) 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 88e94ced..f6bdbc9b 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/trackasmlib_wire.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/trackasmlib_wire.lua @@ -4,20 +4,19 @@ local asmlib = trackasmlib local Vector = Vector local Angle = Angle local Color = Color -local LocalPlayer = LocalPlayer local tonumber = tonumber local tostring = tostring local stringSub = string and string.sub local stringUpper = string and string.upper local stringLen = string and string.len +local mathClamp = math and math.Clamp ----- Get extension enabled flag -local plPlayer = LocalPlayer() local enFlag = ((tonumber(asmlib.GetCoVar("enwiremod","INT")) or 0) ~= 0) and true or false local anyTrue = 1 local anyFalse = 0 ---------- Pieces ---------- +--------- Pieces ---------- __e2setcost(50) e2function string entity:trackasmlibGenActivePointINS(entity ucsEnt, string sType, string sName, number nPoint, string sP) if(not (this and this:IsValid() and enFlag)) then return "" end @@ -178,7 +177,6 @@ e2function number entity:trackasmlibGetPointsCount() end ---------- Additions ------------ - __e2setcost(30) e2function number trackasmlibHasAdditions(string sModel) if(not enFlag) then return anyFalse end @@ -248,7 +246,6 @@ e2function array entity:trackasmlibGetAdditionsLine(number nLine) end ------------ PhysProperties ------------ - __e2setcost(15) e2function array trackasmlibGetProperty(string sType) if(not enFlag) then return {} end @@ -266,20 +263,24 @@ e2function array trackasmlibGetProperty() end ----------- Piece creator -------------- - __e2setcost(50) e2function entity trackasmlibMakePiece(string sModel, vector vPos, angle aAng, number nMass, string sBgpID, number nR, number nG, number nB, number nA) if(not enFlag) then return nil end - return asmlib.MakePiece(plPlayer,sModel, + 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]), nMass or 50000,sBgpID or "", - Color(nR or 255, nG or 255, nB or 255, nA or 255)) + Color(mathClamp(nR or 255,0,255), + mathClamp(nG or 255,0,255), + mathClamp(nB or 255,0,255), + mathClamp(nA or 255,0,255))) end __e2setcost(50) e2function entity entity:trackasmlibMakePiece(vector vPos, angle aAng) if(not (this and this:IsValid() and enFlag)) then return nil end + if(not asmlib.IsPlayer(self.player)) then return nil end local phthis = this:GetPhysicsObject() if(not (phthis and phthis:IsValid())) then return nil end local stRecord = asmlib.CacheQueryPiece(this:GetModel()) @@ -287,7 +288,7 @@ e2function entity entity:trackasmlibMakePiece(vector vPos, angle aAng) local sBgpID = asmlib.GetPropBodyGroup(this).. asmlib.GetOpVar("OPSYM_DIRECTORY").. asmlib.GetPropSkin(this) - return asmlib.MakePiece(this:GetModel(), + 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()) diff --git a/lua/trackassembly/trackasmlib.lua b/lua/trackassembly/trackasmlib.lua index e378ceb4..20e93903 100644 --- a/lua/trackassembly/trackasmlib.lua +++ b/lua/trackassembly/trackasmlib.lua @@ -185,22 +185,22 @@ function IsNumber(anyValue) return ((tonumber(anyValue) and true) or false) end -function IsPlayer(anyValue) - if(not IsExistent(anyValue)) then return false end - if(not IsValid (anyValue)) then return false end - if(not anyValue:IsPlayer( )) then return false end +function IsPlayer(oPly) + if(not IsExistent(oPly)) then return false end + if(not oPly:IsValid ()) then return false end + if(not oPly:IsPlayer ()) then return false end return true end function IsOther(oEnt) - if(not oEnt) then return true end - if(not oEnt:IsValid()) then return true end - if(oEnt:IsPlayer()) then return true end - if(oEnt:IsVehicle()) then return true end - if(oEnt:IsNPC()) then return true end - if(oEnt:IsRagdoll()) then return true end - if(oEnt:IsWeapon()) then return true end - if(oEnt:IsWidget()) then return true end + if(not IsExistent(oEnt)) then return true end + if(not oEnt:IsValid()) then return true end + if(oEnt:IsPlayer()) then return true end + if(oEnt:IsVehicle()) then return true end + if(oEnt:IsNPC()) then return true end + if(oEnt:IsRagdoll()) then return true end + if(oEnt:IsWeapon()) then return true end + if(oEnt:IsWidget()) then return true end return false end @@ -407,7 +407,7 @@ function InitAssembly(sName,sPurpose) SetOpVar("MODE_DATABASE",GetOpVar("MISS_NOAV")) SetOpVar("HASH_USER_PANEL",GetOpVar("TOOLNAME_PU").."USER_PANEL") SetOpVar("HASH_QUERY_STORE",GetOpVar("TOOLNAME_PU").."QHASH_QUERY") - SetOpVar("HASH_PLAYER_KEYDOWN","PLAYER_KEYDOWN") + SetOpVar("HASH_PLAYER_INFO","PLAYER_INFO") SetOpVar("HASH_PROPERTY_NAMES","PROPERTY_NAMES") SetOpVar("HASH_PROPERTY_TYPES","PROPERTY_TYPES") SetOpVar("NAV_PIECE",{}) @@ -1464,45 +1464,41 @@ function UndoFinishPly(pPly,anyMessage) end function LoadKeyPly(pPly, sKey) - local keyPly = GetOpVar("HASH_PLAYER_KEYDOWN") + local keyPly = GetOpVar("HASH_PLAYER_INFO") local plyCache = libCache[keyPly] if(not IsExistent(plyCache)) then - libCache[keyPly] = {} - plyCache = libCache[keyPly] - end + libCache[keyPly] = {}; plyCache = libCache[keyPly] end if(not IsPlayer(pPly)) then return StatusLog(false,"LoadKeyPly: Player <"..type(pPly)"> not available") end - local spName = pPly:GetName() - local plyPlace = plyCache[spName] + local plyNick = pPly:Nick() + local plyPlace = plyCache[plyNick] if(not IsExistent(plyPlace)) then - plyCache[spName] = { - ["ALTLFT"] = false, - ["ALTRGH"] = false, - ["ATTLFT"] = false, - ["ATTRGH"] = false, - ["FORWARD"] = false, - ["BACK"] = false, - ["MOVELFT"] = false, - ["MOVERGH"] = false, - ["RELOAD"] = false, - ["USE"] = false, - ["DUCK"] = false, - ["JUMP"] = false, - ["SPEED"] = false, - ["SCORE"] = false, - ["ZOOM"] = false, - ["LEFT"] = false, - ["RIGHT"] = false, - ["WALK"] = false + plyCache[plyNick] = { + ["ALTLFT"] = false, + ["ALTRGH"] = false, + ["ATTLFT"] = false, + ["ATTRGH"] = false, + ["FORWARD"] = false, + ["BACK"] = false, + ["MOVELFT"] = false, + ["MOVERGH"] = false, + ["RELOAD"] = false, + ["USE"] = false, + ["DUCK"] = false, + ["JUMP"] = false, + ["SPEED"] = false, + ["SCORE"] = false, + ["ZOOM"] = false, + ["LEFT"] = false, + ["RIGHT"] = false, + ["WALK"] = false } - plyPlace = plyCache[spName] + plyPlace = plyCache[plyNick] end if(IsExistent(sKey)) then if(not IsString(sKey)) then return StatusLog(false,"LoadKeyPly: Key hash {"..type(sKey).."}<"..tostring(sKey).."> not string") end - if(sKey == "DEBUG") then - return plyPlace - end + if(sKey == "DEBUG") then return plyPlace end LogInstance("LoadKeyPly: NamePK <"..sKey.."> = "..tostring(plyPlace[sKey])) return plyPlace[sKey] end @@ -1524,7 +1520,7 @@ function LoadKeyPly(pPly, sKey) plyPlace["LEFT"] = pPly:KeyDown(IN_LEFT ) plyPlace["RIGHT"] = pPly:KeyDown(IN_RIGHT ) plyPlace["WALK"] = pPly:KeyDown(IN_WALK ) - return StatusLog(true,"LoadKeyPly: Player <"..spName.."> keys loaded") + return StatusLog(true,"LoadKeyPly: Player <"..plyNick.."> keys loaded") end -------------------------- BUILDSQL ------------------------------ @@ -3069,15 +3065,15 @@ end function MakePiece(pPly,sModel,vPos,aAng,nMass,sBgSkIDs,clColor) if(CLIENT) then return StatusLog(nil,"MakePiece: Working on client") end - if(not IsPlayer(pPly)) then + if(not IsPlayer(pPly)) then -- If not player we cannot register limit return StatusLog(nil,"MakePiece: Player missing <"..tostring(pPly)..">") end - local sLimit = GetOpVar("CVAR_LIMITNAME") - if(not pPly:CheckLimit(sLimit)) then -- Returns false if the limit is hit + local sLimit = GetOpVar("CVAR_LIMITNAME") -- Get limit name + if(not pPly:CheckLimit(sLimit)) then -- Check TA interanl limit return StatusLog(nil,"MakePiece: Track limit reached") end - if(not pPly:CheckLimit("props")) then -- Check the props too + if(not pPly:CheckLimit("props")) then -- Check the props limit return StatusLog(nil,"MakePiece: Prop limit reached") end local stPiece = CacheQueryPiece(sModel) - if(not IsExistent(stPiece)) then + if(not IsExistent(stPiece)) then -- Not present in the database return StatusLog(nil,"MakePiece: Record missing <"..sModel..">") end local ePiece = entsCreate("prop_physics") if(not (ePiece and ePiece:IsValid())) then @@ -3106,11 +3102,10 @@ function MakePiece(pPly,sModel,vPos,aAng,nMass,sBgSkIDs,clColor) return StatusLog(nil,"MakePiece: Failed to attach bodygroups") end if(not AttachAdditions(ePiece)) then ePiece:Remove() return StatusLog(nil,"MakePiece: Failed to attach additions") end - -- pPly:AddCleanup sets the ownership - pPly:AddCount (sLimit , ePiece) - pPly:AddCount ("props", ePiece) - pPly:AddCleanup(sLimit , ePiece) - pPly:AddCleanup("props", ePiece) + pPly:AddCount (sLimit , ePiece) -- Register it to the TA internal limit + pPly:AddCount ("props", ePiece) -- Register it to the props also + pPly:AddCleanup(sLimit , ePiece) -- This sets the ownership + pPly:AddCleanup("props", ePiece) -- To be deleted with clearing props return StatusLog(ePiece,"MakePiece: Success "..tostring(ePiece)) end diff --git a/lua/weapons/gmod_tool/stools/trackassembly.lua b/lua/weapons/gmod_tool/stools/trackassembly.lua index ac4cd809..b1a7dd79 100644 --- a/lua/weapons/gmod_tool/stools/trackassembly.lua +++ b/lua/weapons/gmod_tool/stools/trackassembly.lua @@ -949,10 +949,24 @@ function TOOL:DrawToolScreen(w, h) end function TOOL.BuildCPanel(CPanel) - Header = CPanel:AddControl( "Header", {Text = languageGetPhrase("tool."..gsToolNameL..".name"), - Description = languageGetPhrase("tool."..gsToolNameL..".desc")}) - local CurY = Header:GetTall() + 2 - + local CurY = 0 -- pItem is the current panel created + pItem = CPanel:SetName(languageGetPhrase("tool."..gsToolNameL..".name")) + CurY = CurY + pItem:GetTall() + 2 + + pItem = CPanel:Help(languageGetPhrase("tool."..gsToolNameL..".desc")) + CurY = CurY + pItem:GetTall() + 2 + + pItem = vguiCreate("ControlPresets") + pItem:SetPos(2, CurY) + pItem:SetLabel("Presets") + pItem:SetPreset(gsToolNameL) + for k, v in pairs(self.ClientConVar) do + pItem:AddConVar(k) + end; CurY = CurY + pItem:GetTall() + 2 + pItem:Update() + CPanel:AddItem(pItem) + + --[[ local Combo = {} Combo["Label"] = "#Presets" Combo["MenuButton"] = "1" @@ -983,8 +997,10 @@ function TOOL.BuildCPanel(CPanel) Combo["CVars"][22] = gsToolPrefL.."nocollide" Combo["CVars"][23] = gsToolPrefL.."gravity" Combo["CVars"][24] = gsToolPrefL.."physmater" - CPanel:AddControl("ComboBox",Combo) - CurY = CurY + 25 + pItem = CPanel:AddControl("ComboBox",Combo) + CurY = CurY + pItem:GetTall() + 2 + + ]]-- local Panel = asmlib.CacheQueryPanel() if(not Panel) then return asmlib.StatusPrint(nil,"TOOL:BuildCPanel(cPanel): Panel population empty") end @@ -994,7 +1010,7 @@ function TOOL.BuildCPanel(CPanel) pTree:SetSize(2, 250) pTree:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".tree")) pTree:SetIndentSize(0) - local iCnt, pFolders, pNode, pItem = 1, {} + local iCnt, pFolders, pNode = 1, {} while(Panel[iCnt]) do local Rec = Panel[iCnt] local Mod = Rec[defTable[1][1]] @@ -1049,19 +1065,16 @@ function TOOL.BuildCPanel(CPanel) if(not Property) then return asmlib.StatusPrint(nil,"TOOL:BuildCPanel(cPanel): Property population empty") end asmlib.Print(Property,"Property") local CntTyp = 1 - local qNames, Type while(Property[CntTyp]) do - Type = Property[CntTyp] - pComboPhysType:AddChoice(Type) + pComboPhysType:AddChoice(Property[CntTyp]) pComboPhysType.OnSelect = function(pnSelf, nInd, sVal, anyData) - qNames = asmlib.CacheQueryProperty(sVal) + local qNames = asmlib.CacheQueryProperty(sVal) if(qNames) then pComboPhysName:Clear() pComboPhysName:SetValue("