diff --git a/lua/entities/gmod_track_signal/cl_init.lua b/lua/entities/gmod_track_signal/cl_init.lua index bf649b9..f905cbe 100644 --- a/lua/entities/gmod_track_signal/cl_init.lua +++ b/lua/entities/gmod_track_signal/cl_init.lua @@ -59,16 +59,18 @@ function ENT:SpawnMainModels(pos,ang,LenseNum,add) local TLM = self.TrafficLightModels[self.LightType] for k,v in pairs(TLM) do if type(v) == "string" and not k:find("long") then - if IsValid(self.Models[1][add and v..add or v]) then break else - if TLM[k.."_long"] and LenseNum >= 7 then - self.Models[1][add and v..add or v] = ClientsideModel(TLM[k.."_long"],RENDERGROUP_OPAQUE) + local idx = add and v..add or v + if IsValid(self.Models[1][idx]) then break else + local k_long = k.."_long" + if TLM[k_long] and LenseNum >= 7 then + self.Models[1][idx] = ClientsideModel(TLM[k_long],RENDERGROUP_OPAQUE) self.LongOffset = Vector(0,0,TLM[k.."_long_pos"]) else - self.Models[1][add and v..add or v] = ClientsideModel(v,RENDERGROUP_OPAQUE) + self.Models[1][idx] = ClientsideModel(v,RENDERGROUP_OPAQUE) end - self.Models[1][add and v..add or v]:SetPos(self:LocalToWorld(pos)) - self.Models[1][add and v..add or v]:SetAngles(self:LocalToWorldAngles(ang)) - self.Models[1][add and v..add or v]:SetParent(self) + self.Models[1][idx]:SetPos(self:LocalToWorld(pos)) + self.Models[1][idx]:SetAngles(self:LocalToWorldAngles(ang)) + self.Models[1][idx]:SetParent(self) end end end @@ -85,23 +87,27 @@ function ENT:SpawnHeads(ID,model,pos,ang,glass,notM,add) self.RN = self.RN + 1 end local id = self.RN - if id and not IsValid(self.Models[1]["rou"..id]) then + local rouid = id and "rou"..id + if rouid and not IsValid(self.Models[1][rouid]) then local rnadd = ((self.RouteNumbers[id] and self.RouteNumbers[id][1] ~= "X") and (self.RouteNumbers[id][3] and not self.RouteNumbers[id][2] and "2" or "") or "5") - self.Models[1]["rou"..id] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator"..rnadd..".mdl",RENDERGROUP_OPAQUE) - self.Models[1]["rou"..id]:SetPos(self:LocalToWorld(pos-self.RouteNumberOffset*Vector(self.Left and 0.2 or 1))) - self.Models[1]["rou"..id]:SetAngles(self:GetAngles()) - self.Models[1]["rou"..id]:SetParent(self) - if self.RouteNumbers[id] then self.RouteNumbers[id].pos = pos-self.RouteNumberOffset*Vector(self.Left and 0.2 or 1) end + local LampIndicator = self.TrafficLightModels[self.LightType].LampIndicator + self.Models[1][rouid] = ClientsideModel(LampIndicator.model..rnadd..".mdl",RENDERGROUP_OPAQUE) + self.Models[1][rouid]:SetPos(self:LocalToWorld(pos-self.RouteNumberOffset*(self.Left and LampIndicator[1] or LampIndicator[2]))) + self.Models[1][rouid]:SetAngles(self:GetAngles()) + self.Models[1][rouid]:SetParent(self) + if self.RouteNumbers[id] then self.RouteNumbers[id].pos = pos-self.RouteNumberOffset*(self.Left and LampIndicator[1] or LampIndicator[2]) end self.RN = self.RN + 1 end if notM then if glass then + local ID_glass = tostring(ID).."_glass" for i,tbl in pairs(glass) do - if not IsValid(self.Models[1][tostring(ID).."_glass"..i]) then --NEWLENSES - self.Models[1][tostring(ID).."_glass"..i] = ClientsideModel(tbl[1],RENDERGROUP_OPAQUE) - self.Models[1][tostring(ID).."_glass"..i]:SetPos(self:LocalToWorld(pos+tbl[2]*Vector(add and -1 or 1,1,1))) - self.Models[1][tostring(ID).."_glass"..i]:SetAngles(self:LocalToWorldAngles(ang)) - self.Models[1][tostring(ID).."_glass"..i]:SetParent(self) + local ID_glassi = ID_glass..i + if not IsValid(self.Models[1][ID_glassi]) then --NEWLENSES + self.Models[1][ID_glassi] = ClientsideModel(tbl[1],RENDERGROUP_OPAQUE) + self.Models[1][ID_glassi]:SetPos(self:LocalToWorld(pos+tbl[2]*(add and Vector(-1,1,1) or 1))) + self.Models[1][ID_glassi]:SetAngles(self:LocalToWorldAngles(ang)) + self.Models[1][ID_glassi]:SetParent(self) end end end @@ -109,44 +115,53 @@ function ENT:SpawnHeads(ID,model,pos,ang,glass,notM,add) end function ENT:SetLight(ID,ID2,pos,ang,skin,State,Change) - if State >0 and Change and not IsValid(self.Models[3][ID..ID2]) then - self.Models[3][ID..ID2] = ClientsideModel("models/metrostroi/signals/mus/lamp_base.mdl",RENDERGROUP_OPAQUE) - self.Models[3][ID..ID2]:SetPos(self:LocalToWorld(pos)) - self.Models[3][ID..ID2]:SetAngles(self:LocalToWorldAngles(ang)) - self.Models[3][ID..ID2]:SetSkin(skin) - self.Models[3][ID..ID2]:SetParent(self) - self.Models[3][ID..ID2]:SetRenderMode(RENDERMODE_TRANSCOLOR) - self.Models[3][ID..ID2]:SetColor(Color(255,255,255,0)) - end - if IsValid(self.Models[3][ID..ID2]) then - if State > 0 and Change then - self.Models[3][ID..ID2]:SetColor(Color(255,255,255,State*255)) - elseif State == 0 then - self.Models[3][ID..ID2]:Remove() + local IsStateAboveZero = State > 0 + local IDID2 = ID..ID2 + local IsModelValid = IsValid(self.Models[3][IDID2]) + if IsModelValid then + if IsStateAboveZero then + if Change then + self.Models[3][IDID2]:SetColor(Color(255,255,255,State*255)) + end + else + self.Models[3][IDID2]:Remove() end + elseif IsStateAboveZero then + self.Models[3][IDID2] = ClientsideModel(self.TrafficLightModels[self.LightType].LampBase.model,RENDERGROUP_OPAQUE) + self.Models[3][IDID2]:SetPos(self:LocalToWorld(pos)) + self.Models[3][IDID2]:SetAngles(self:LocalToWorldAngles(ang)) + self.Models[3][IDID2]:SetSkin(skin) + self.Models[3][IDID2]:SetParent(self) + self.Models[3][IDID2]:SetRenderMode(RENDERMODE_TRANSCOLOR) + -- self.Models[3][IDID2]:SetColor(Color(255, 255, 255, 0)) + self.Models[3][IDID2]:SetColor(Color(255,255,255,State*255)) end end function ENT:SpawnLetter(i,model,pos,letter,double) + local LetMaterials = self.TrafficLightModels[self.LightType].LetMaterials.str + local LetMaterialsStart = LetMaterials.."let_start" + local LetMaterialsletter = LetMaterials..letter if double ~= false and not IsValid(self.Models[2][i]) and (self.Double or not self.Left) and (not letter:match("s[1-3]") or letter == "s3" or self.Double and self.Left) then self.Models[2][i] = ClientsideModel(model,RENDERGROUP_OPAQUE) self.Models[2][i]:SetAngles(self:LocalToWorldAngles(Angle(0,180,0))) self.Models[2][i]:SetPos(self:LocalToWorld(self.BasePosition+pos)) self.Models[2][i]:SetParent(self) for k,v in pairs(self.Models[2][i]:GetMaterials()) do - if v:find("models/metrostroi/signals/let/let_start") then - self.Models[2][i]:SetSubMaterial(k-1,"models/metrostroi/signals/let/"..letter) + if v:find(LetMaterialsStart) then + self.Models[2][i]:SetSubMaterial(k-1,LetMaterialsletter) end end end - if not double and not IsValid(self.Models[2][i.."d"]) and (self.Double or self.Left) and (not letter:match("s[1-3]") or letter == "s3" or self.Double and not self.Left) then - self.Models[2][i.."d"] = ClientsideModel(model,RENDERGROUP_OPAQUE) - self.Models[2][i.."d"]:SetAngles(self:LocalToWorldAngles(Angle(0,180,0))) - self.Models[2][i.."d"]:SetPos(self:LocalToWorld((self.BasePosition+pos)*Vector(-1,1,1))) - self.Models[2][i.."d"]:SetParent(self) - for k,v in pairs(self.Models[2][i.."d"]:GetMaterials()) do - if v:find("models/metrostroi/signals/let/let_start") then - self.Models[2][i.."d"]:SetSubMaterial(k-1,"models/metrostroi/signals/let/"..letter) + local id = i.."d" + if not double and not IsValid(self.Models[2][id]) and (self.Double or self.Left) and (not letter:match("s[1-3]") or letter == "s3" or self.Double and not self.Left) then + self.Models[2][id] = ClientsideModel(model,RENDERGROUP_OPAQUE) + self.Models[2][id]:SetAngles(self:LocalToWorldAngles(Angle(0,180,0))) + self.Models[2][id]:SetPos(self:LocalToWorld((self.BasePosition+pos)*Vector(-1,1,1))) + self.Models[2][id]:SetParent(self) + for k,v in pairs(self.Models[2][id]:GetMaterials()) do + if v:find(LetMaterialsStart) then + self.Models[2][id]:SetSubMaterial(k-1,LetMaterialsletter) end end end @@ -184,6 +199,8 @@ net.Receive("metrostroi-signal", function() end) function ENT:Think() + local CurTime = CurTime() + self:SetNextClientThink(CurTime + 0.0333) self.PrevTime = self.PrevTime or RealTime() self.DeltaTime = (RealTime() - self.PrevTime) self.PrevTime = RealTime() @@ -191,7 +208,7 @@ function ENT:Think() if not self.ReloadModels and self.ModelsCreated then self:RemoveModels() end - return + return true end if self.ReloadModels then @@ -200,16 +217,16 @@ function ENT:Think() end if not self.Name then - if self.sended and (CurTime() - self.sended) > 0 then + if self.sended and (CurTime - self.sended) > 0 then self.sended = nil end if not self.sended then net.Start("metrostroi-signal") net.WriteEntity(self) net.SendToServer() - self.sended = CurTime() + 1.5 + self.sended = CurTime + 1.5 end - return + return true end local TLM = self.TrafficLightModels[self.LightType] @@ -219,34 +236,37 @@ function ENT:Think() -- Create new clientside models if not self.ARSOnly then --SPAWN A OLD ROUTE Numbers + --оператор # съедает больше производительности, чем исопльзование своей переменной с хранением количества элементов в таблице + --поэтому добавляю каунтеры + --TODO вообще сравнить бы это здесь xD local rn1 = {} + local rn1N = 0 local rn2 = {} self.RouteNumbers = {} self.SpecRouteNumbers = {} for i=1,#self.RouteNumberSetup do local CurRN = self.RouteNumberSetup[i] if self.OldRouteNumberSetup[1]:find(CurRN) then - table.insert(rn1,CurRN) + rn1N = table.insert(rn1,CurRN) elseif self.OldRouteNumberSetup[2]:find(CurRN) then table.insert(rn2,CurRN) elseif self.OldRouteNumberSetup[3]:find(CurRN) then table.insert(self.SpecRouteNumbers,{CurRN,CurRN == "F"}) end end - for i=1,#rn1,2 do + for i=1,rn1N,2 do table.insert(self.RouteNumbers,{rn1[i],rn1[i+1],true}) end for k,v in pairs(rn2) do table.insert(self.RouteNumbers,{v}) end self.Arrow = nil - if #self.SpecRouteNumbers > 0 then - for k,v in pairs(self.SpecRouteNumbers) do - if not v[2] then - self.Arrow = k - self.SpecRouteNumbers = v - break - end + + for k,v in pairs(self.SpecRouteNumbers) do + if not v[2] then + self.Arrow = k + self.SpecRouteNumbers = v + break end end local LenseNum = self.Arrow and 1 or 0 @@ -262,9 +282,9 @@ function ENT:Think() end end if LenseNum == 0 then OneLense = false end - local offset = self.RenderOffset[self.LightType] or Vector(0,0,0) - self.LongOffset = self.LongOffset or Vector(0,0,0) - if not self.Left or self.Double then self:SpawnMainModels(self.BasePosition,Angle(0,0,0),LenseNum) end + local offset = self.RenderOffset[self.LightType] or Vector(0, 0, 0) + self.LongOffset = self.LongOffset or Vector(0, 0, 0) + if not self.Left or self.Double then self:SpawnMainModels(self.BasePosition,Angle(0, 0, 0),LenseNum) end if self.Left or self.Double then self:SpawnMainModels(self.BasePosition*Vector(-1,1,1),Angle(0,180,0),LenseNum,self.Double and "d" or nil) end @@ -276,17 +296,17 @@ function ENT:Think() if self.RouteNumbers.sep and self.RouteNumbers[self.RouteNumbers.sep][1] ~= "X" then local id = self.RouteNumbers.sep local rnadd = self.RouteNumbers[id][3] and not self.RouteNumbers[id][2] and "3" or "4" - self.Models[1]["rous"] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator"..rnadd..".mdl",RENDERGROUP_OPAQUE) - self.RouteNumbers[id].pos = (self.BasePosition+offset+self.LongOffset-Vector(8,0,0)) - if self.Left then self.RouteNumbers[id].pos = self.RouteNumbers[id].pos*Vector(-0.9,1,1) end + self.Models[1]["rous"] = ClientsideModel(TLM.LampIndicator.model..rnadd..".mdl",RENDERGROUP_OPAQUE) + self.RouteNumbers[id].pos = (self.BasePosition+offset+self.LongOffset-TLM.LampIndicator[3]) + if self.Left then self.RouteNumbers[id].pos = self.RouteNumbers[id].pos*TLM.LampIndicator[4] end self.Models[1]["rous"]:SetPos(self:LocalToWorld(self.RouteNumbers[id].pos)) self.Models[1]["rous"]:SetAngles(self:GetAngles()) self.Models[1]["rous"]:SetParent(self) end if #self.RouteNumbers > 0 and (#self.RouteNumbers ~= 1 or not self.RouteNumbers.sep) then self.RN = 1 - self.RouteNumberOffset = Vector(10,0,0) - offset = offset + self.RouteNumberOffset*Vector(self.Left and -1 or 1,1,1) + self.RouteNumberOffset = TLM.RouteNumberOffset + offset = offset + self.RouteNumberOffset*(self.Left and Vector(-1,1,1) or 1) else self.RouteNumberOffset = nil self.RN = nil @@ -299,7 +319,7 @@ function ENT:Think() self.Models[1]["autostop"]:SetParent(self) end end - self.NamesOffset = Vector(0,0,0) + self.NamesOffset = Vector(0, 0, 0) -- Create traffic light models --if self.LightType > 2 then self.LightType = 2 end --if self.LightType < 0 then self.LightType = 0 end @@ -315,24 +335,26 @@ function ENT:Think() data = self.TrafficLightModels[self.LightType][v] end if not data then continue end + local vec = Vector(0,0,data[1]) if first then first = false else - offset = offset - Vector(0,0,data[1]) + offset = offset - vec end - self.NamesOffset = self.NamesOffset + Vector(0,0,data[1]) - if not self.Left or self.Double then self:SpawnHeads(ID,data[2],self.BasePosition + offset + self.LongOffset,Angle(0,0,0),data[3] and data[3].glass,v~="M") end - if self.Left or self.Double then self:SpawnHeads((self.Double and ID.."d" or ID),(not TLM.noleft) and data[2]:Replace(".mdl","_mirror.mdl") or data[2],self.BasePosition*Vector(-1,1,1) + offset + self.LongOffset,Angle(0,0,0),data[3] and data[3].glass,v~="M",true) end + self.NamesOffset = self.NamesOffset + vec + local offsetAndLongOffset = offset + self.LongOffset + if not self.Left or self.Double then self:SpawnHeads(ID,data[2],self.BasePosition + offsetAndLongOffset,Angle(0, 0, 0),data[3] and data[3].glass,v~="M") end + if self.Left or self.Double then self:SpawnHeads((self.Double and ID.."d" or ID),(not TLM.noleft) and data[2]:Replace(".mdl","_mirror.mdl") or data[2],self.BasePosition*Vector(-1,1,1) + offsetAndLongOffset,Angle(0, 0, 0),data[3] and data[3].glass,v~="M",true) end if v ~= "M" then for i = 1,#v do ID2 = ID2 + 1 if not self.Signals[ID2] then self.Signals[ID2] = {} end if not self.DoubleL then - self:SetLight(ID,ID2,self.BasePosition*Vector(self.Left and -1 or 1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(self.Left and -1 or 1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,0 ) + self:SetLight(ID,ID2,self.BasePosition*(self.Left and Vector(-1,1,1) or 1) + offsetAndLongOffset + data[3][i-1]*(self.Left and Vector(-1,1,1) or 1),Angle(0, 0, 0),self.SignalConverter[v[i]]-1,0 ) else - self:SetLight(ID,ID2,self.BasePosition*Vector( 1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,0) - self:SetLight(ID,ID2.."x",self.BasePosition*Vector(-1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(-1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,0) + self:SetLight(ID,ID2,self.BasePosition + offsetAndLongOffset + data[3][i-1],Angle(0, 0, 0),self.SignalConverter[v[i]]-1,0) + self:SetLight(ID,ID2.."x",self.BasePosition*Vector(-1,1,1) + offsetAndLongOffset + data[3][i-1]*Vector(-1,1,1),Angle(0, 0, 0),self.SignalConverter[v[i]]-1,0) end end end @@ -341,41 +363,41 @@ function ENT:Think() end if self.Arrow then local id = self.Arrow - self.Models[1]["roua"] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator4.mdl",RENDERGROUP_OPAQUE) - self.SpecRouteNumbers.pos = (self.BasePosition+offset+self.LongOffset-Vector(3,0,3))*Vector(self.Left and -1 or 1,1,self.Left and 0.85 or 1)-(self.RouteNumberOffset or Vector()) + self.Models[1]["roua"] = ClientsideModel(TLM.LampIndicator.model.."4.mdl",RENDERGROUP_OPAQUE) + self.SpecRouteNumbers.pos = (self.BasePosition+offset+self.LongOffset-TLM.LampIndicator[5])*(self.Left and TLM.LampIndicator[6] or 1) - (self.RouteNumberOffset or Vector(0, 0, 0)) self.Models[1]["roua"]:SetPos(self:LocalToWorld(self.SpecRouteNumbers.pos)) - self.Models[1]["roua"]:SetAngles(self:LocalToWorldAngles(Angle(self.Left and -90 or 90,0,0))) + self.Models[1]["roua"]:SetAngles(self:LocalToWorldAngles(self.Left and Angle(-90,0,0) or Angle(90,0,0))) self.Models[1]["roua"]:SetParent(self) end - offset = self.RenderOffset[self.LightType]+(OneLense and TLM.name_one or TLM.name)+(OneLense and self.RouteNumberOffset or Vector()) + offset = self.RenderOffset[self.LightType]+(OneLense and TLM.name_one or TLM.name)+(OneLense and self.RouteNumberOffset or Vector(0, 0, 0)) if self.LightType == 1 then offset = offset - self.NamesOffset end local double = self.LightType ~= 1 and string.find(self.Name,"^[A-Z][A-Z]") if double then if not self.Left or self.Double then - self:SpawnLetter(0,"models/metrostroi/signals/mus/sign_letter_small.mdl",offset - Vector(-1.5,0,0),(Metrostroi.LiterWarper[self.Name[0+1]] or self.Name[0+1]),true) - self:SpawnLetter(1,"models/metrostroi/signals/mus/sign_letter_small.mdl",offset - Vector(1.5,0,0),(Metrostroi.LiterWarper[self.Name[1+1]] or self.Name[1+1]),true) + self:SpawnLetter(0,TLM.SignLetterSmall.model,offset - TLM.SignLetterSmall[2],(Metrostroi.LiterWarper[self.Name[0+1]] or self.Name[0+1]),true) + self:SpawnLetter(1,TLM.SignLetterSmall.model,offset - TLM.SignLetterSmall[1],(Metrostroi.LiterWarper[self.Name[1+1]] or self.Name[1+1]),true) end if self.Left or self.Double then - self:SpawnLetter(0,"models/metrostroi/signals/mus/sign_letter_small.mdl",offset - Vector(1.5,0,0),(Metrostroi.LiterWarper[self.Name[0+1]] or self.Name[0+1]),false) - self:SpawnLetter(1,"models/metrostroi/signals/mus/sign_letter_small.mdl",offset - Vector(-1.5,0,0),(Metrostroi.LiterWarper[self.Name[1+1]] or self.Name[1+1]),false) + self:SpawnLetter(0,TLM.SignLetterSmall.model,offset - TLM.SignLetterSmall[1],(Metrostroi.LiterWarper[self.Name[0+1]] or self.Name[0+1]),false) + self:SpawnLetter(1,TLM.SignLetterSmall.model,offset - TLM.SignLetterSmall[2],(Metrostroi.LiterWarper[self.Name[1+1]] or self.Name[1+1]),false) end end local min = 0 for i = double and 2 or 0,#self.Name-1 do local id = (double and i-1 or i) - min - if double and i == 2 then offset = offset + Vector(0,0,1.62) end + if double and i == 2 then offset = offset + TLM.DoubleOffset end if self.Name[i+1] == " " then continue end if self.Name[i+1] == "/" then min = min + 1; continue end --if not IsValid(self.Models[2][i]) then - self:SpawnLetter(i,"models/metrostroi/signals/mus/sign_letter.mdl",offset - Vector(0,0,id*5.85),(Metrostroi.LiterWarper[self.Name[i+1]] or self.Name[i+1])) + self:SpawnLetter(i,TLM.SignLetter.model,offset - Vector(0,0,id*TLM.SignLetter.z),(Metrostroi.LiterWarper[self.Name[i+1]] or self.Name[i+1])) --end end if self.Name and self.Name:match("(/+)$") then local i = #self.Name local id = (double and i-1 or i) - min - self:SpawnLetter(i,"models/metrostroi/signals/mus/sign_letter.mdl",offset - Vector(0,0,id*5.85),Format("s%d",math.min(3,#self.Name:match("(/+)$")))) + self:SpawnLetter(i,TLM.SignLetter.model,offset - Vector(0,0,id*TLM.SignLetter.z),Format("s%d",math.min(3,#self.Name:match("(/+)$")))) end else local k = "m1" @@ -383,8 +405,8 @@ function ENT:Think() if not IsValid(self.Models[1][k]) then local v = TLM["m1"] self.Models[1][k] = ClientsideModel(v,RENDERGROUP_OPAQUE) - self.Models[1][k]:SetPos(self:LocalToWorld(self.BasePosition*Vector(self.Left and -1 or 1,1,1))) - self.Models[1][k]:SetAngles(self:LocalToWorldAngles(Angle(self.Left and -1 or 1,1,1))) + self.Models[1][k]:SetPos(self:LocalToWorld(self.BasePosition*(self.Left and Vector(-1,1,1) or 1))) + self.Models[1][k]:SetAngles(self:LocalToWorldAngles(self.Left and Angle(-1,1,1) or Angle(1,1,1))) self.Models[1][k]:SetParent(self) end end @@ -402,16 +424,16 @@ function ENT:Think() self.Sig = self:GetNW2String("Signal","") self.Num = self:GetNW2String("Number",nil) if self.OldNum ~= self.Num then - self.NextNumWork = CurTime() + 1 + self.NextNumWork = CurTime + 1 end self.OldNum = self.Num - if (self.NextNumWork or CurTime()) - CurTime() >= 0 then + if (self.NextNumWork or CurTime) - CurTime >= 0 then self.Num = "" end - if self.ARSOnly then return end - local offset = (self.RenderOffset[self.LightType] or Vector(0,0,0)) - if self.RouteNumberOffset then offset = offset + self.RouteNumberOffset*Vector(self.Left and -1 or 1,1) end + if self.ARSOnly then return true end + local offset = (self.RenderOffset[self.LightType] or Vector(0, 0, 0)) + if self.RouteNumberOffset then offset = offset + self.RouteNumberOffset*(self.Left and Vector(-1,1) or Vector(1,1)) end local ID = 0 local ID2 = 0 local first = true @@ -433,20 +455,22 @@ function ENT:Think() if v ~= "M" then for i = 1,#v do ID2 = ID2 + 1 - if tonumber(self.Sig[ID2]) and self.Signals[ID2].RealState ~= (tonumber(self.Sig[ID2]) > 0) then - self.Signals[ID2].RealState = tonumber(self.Sig[ID2]) > 0 - self.Signals[ID2].Stop = CurTime() + 0.5 + local n = tonumber(self.Sig[ID2]) + if n and self.Signals[ID2].RealState ~= (n > 0) then + self.Signals[ID2].RealState = n > 0 + self.Signals[ID2].Stop = CurTime + 0.5 end - if self.Signals[ID2].Stop and CurTime()-self.Signals[ID2].Stop > 0 then + if self.Signals[ID2].Stop and CurTime-self.Signals[ID2].Stop > 0 then self.Signals[ID2].Stop = nil end - local State = self:Animate(ID.."/"..i, ((tonumber(self.Sig[ID2]) == 1 or (tonumber(self.Sig[ID2]) == 2 and (RealTime() % 1.2 > 0.4))) and not self.Signals[ID2].Stop) and 1 or 0, 0,1, 128) + local State = self:Animate(ID.."/"..i, ((n == 1 or (n == 2 and (RealTime() % 1.2 > 0.4))) and not self.Signals[ID2].Stop) and 1 or 0, 0,1, 128) if not IsValid(self.Models[3][ID..ID2]) and State > 0 then self.Signals[ID2].State = nil end + local offsetAndLongOffset = offset + self.LongOffset if not self.DoubleL then - self:SetLight(ID,ID2,self.BasePosition*Vector(self.Left and -1 or 1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(self.Left and -1 or 1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) + self:SetLight(ID,ID2,self.BasePosition*(self.Left and Vector(-1,1,1) or 1) + offsetAndLongOffset + data[3][i-1]*(self.Left and Vector(-1,1,1) or 1),Angle(0, 0, 0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) else - self:SetLight(ID,ID2,self.BasePosition*Vector( 1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) - self:SetLight(ID,ID2.."x",self.BasePosition*Vector(-1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(-1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) + self:SetLight(ID,ID2,self.BasePosition + offsetAndLongOffset + data[3][i-1],Angle(0, 0, 0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) + self:SetLight(ID,ID2.."x",self.BasePosition*Vector(-1,1,1) + offsetAndLongOffset + data[3][i-1]*Vector(-1,1,1),Angle(0, 0, 0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) end self.Signals[ID2].State = State end @@ -456,52 +480,57 @@ function ENT:Think() ID = ID + 1 end + + local LampIndicatorModels_numb_mdl = TLM.LampIndicator.model.."_numb.mdl" + local LampIndicatorModels_lamp_mdl = TLM.LampIndicator.model.."_lamp.mdl" for k,v in pairs(self.RouteNumbers) do if k == "sep" then continue end - local State1 = self:Animate("rou1"..k,self.Num:find(v[1]) and 1 or 0, 0,1, 256) + local rou1k = "rou1"..k + local State1 = self:Animate(rou1k,self.Num:find(v[1]) and 1 or 0, 0,1, 256) local State2 --if v[3] then - if v[2] then State2 = self:Animate("rou2"..k,self.Num:find(v[2])and 1 or 0, 0,1, 256) end - if not IsValid(self.Models[3]["rou1"..k]) and State1 > 0 then - self.Models[3]["rou1"..k] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator_"..(v[3] and "numb" or "lamp")..".mdl",RENDERGROUP_OPAQUE) - self.Models[3]["rou1"..k]:SetPos(self:LocalToWorld(v.pos + self.OldRouteNumberSetup[4])) - self.Models[3]["rou1"..k]:SetAngles(self:GetAngles()) - self.Models[3]["rou1"..k]:SetParent(self) - self.Models[3]["rou1"..k]:SetSkin(v[3] and self.OldRouteNumberSetup[5][v[1]] or self.OldRouteNumberSetup[6][v[1]] or tonumber(v[1])-1) - self.Models[3]["rou1"..k]:SetRenderMode(RENDERMODE_TRANSCOLOR) - self.Models[3]["rou1"..k]:SetColor(Color(255,255,255,0)) + local rou2k = "rou2"..k + if v[2] then State2 = self:Animate(rou2k,self.Num:find(v[2])and 1 or 0, 0,1, 256) end + if not IsValid(self.Models[3][rou1k]) and State1 > 0 then + self.Models[3][rou1k] = ClientsideModel(v[3] and LampIndicatorModels_numb_mdl or LampIndicatorModels_lamp_mdl,RENDERGROUP_OPAQUE) + self.Models[3][rou1k]:SetPos(self:LocalToWorld(v.pos + self.OldRouteNumberSetup[4])) + self.Models[3][rou1k]:SetAngles(self:GetAngles()) + self.Models[3][rou1k]:SetParent(self) + self.Models[3][rou1k]:SetSkin(v[3] and self.OldRouteNumberSetup[5][v[1]] or self.OldRouteNumberSetup[6][v[1]] or tonumber(v[1])-1) + self.Models[3][rou1k]:SetRenderMode(RENDERMODE_TRANSCOLOR) + self.Models[3][rou1k]:SetColor(Color(255, 255, 255, 0)) end - if IsValid(self.Models[3]["rou1"..k]) then + if IsValid(self.Models[3][rou1k]) then if State1 > 0 then - self.Models[3]["rou1"..k]:SetColor(Color(255,255,255,State1*255)) + self.Models[3][rou1k]:SetColor(Color(255,255,255,State1*255)) elseif State1 == 0 then - self.Models[3]["rou1"..k]:Remove() + self.Models[3][rou1k]:Remove() end end - if not IsValid(self.Models[3]["rou2"..k]) and v[3] and v[2] and State2 > 0 then - self.Models[3]["rou2"..k] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator_numb.mdl",RENDERGROUP_OPAQUE) - self.Models[3]["rou2"..k]:SetPos(self:LocalToWorld(v.pos + self.OldRouteNumberSetup[4] + Vector(0,0,7.2))) - self.Models[3]["rou2"..k]:SetAngles(self:GetAngles()) - self.Models[3]["rou2"..k]:SetParent(self) - self.Models[3]["rou2"..k]:SetSkin(self.OldRouteNumberSetup[5][v[2]] or tonumber(v[2])-1) - self.Models[3]["rou2"..k]:SetRenderMode(RENDERMODE_TRANSCOLOR) - self.Models[3]["rou2"..k]:SetColor(Color(255,255,255,0)) + if not IsValid(self.Models[3][rou2k]) and v[3] and v[2] and State2 > 0 then + self.Models[3][rou2k] = ClientsideModel(LampIndicatorModels_numb_mdl,RENDERGROUP_OPAQUE) + self.Models[3][rou2k]:SetPos(self:LocalToWorld(v.pos + self.OldRouteNumberSetup[4] + TLM.RouteNumberOffset2)) + self.Models[3][rou2k]:SetAngles(self:GetAngles()) + self.Models[3][rou2k]:SetParent(self) + self.Models[3][rou2k]:SetSkin(self.OldRouteNumberSetup[5][v[2]] or tonumber(v[2])-1) + self.Models[3][rou2k]:SetRenderMode(RENDERMODE_TRANSCOLOR) + self.Models[3][rou2k]:SetColor(Color(255, 255, 255, 0)) end - if IsValid(self.Models[3]["rou2"..k]) then + if IsValid(self.Models[3][rou2k]) then if State2 > 0 then - self.Models[3]["rou2"..k]:SetColor(Color(255,255,255,State2*255)) + self.Models[3][rou2k]:SetColor(Color(255,255,255,State2*255)) elseif State2 == 0 then - self.Models[3]["rou2"..k]:Remove() + self.Models[3][rou2k]:Remove() end end end if self.Arrow then local State = self:Animate("roua",self.Num:find(self.SpecRouteNumbers[1]) and 1 or 0, 0,1, 256) if not IsValid(self.Models[3]["roua"]) and State > 0 then - self.Models[3]["roua"] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator_lamp.mdl",RENDERGROUP_OPAQUE) - self.SpecRouteNumbers.pos = (self.BasePosition+offset-Vector(3,-1,3))-self.RouteNumberOffset+ Vector(10.5,0,-6) - if self.Left then self.SpecRouteNumbers.pos = self.SpecRouteNumbers.pos*Vector(-0.8,1,0.94) end - self.Models[3]["roua"]:SetPos(self.Models[1]["roua"]:LocalToWorld(Vector(6.2,0,24.5))) + self.Models[3]["roua"] = ClientsideModel(LampIndicatorModels_lamp_mdl,RENDERGROUP_OPAQUE) + self.SpecRouteNumbers.pos = (self.BasePosition+offset-TLM.SpecRouteNumberOffset)-(self.RouteNumberOffset or Vector(0, 0, 0))+TLM.RouteNumberOffset3 + if self.Left then self.SpecRouteNumbers.pos = self.SpecRouteNumbers.pos*TLM.SpecRouteNumberOffset2 end + self.Models[3]["roua"]:SetPos(self.Models[1]["roua"]:LocalToWorld(TLM.RouaOffset)) self.Models[3]["roua"]:SetAngles(self.Models[1]["roua"]:LocalToWorldAngles(Angle(180,0,0))) self.Models[3]["roua"]:SetParent(self) if self.Left then @@ -514,7 +543,7 @@ function ENT:Think() self.Models[3]["roua"]:SetSkin(self.OldRouteNumberSetup[6][self.Num[1]] or 0) end self.Models[3]["roua"]:SetRenderMode(RENDERMODE_TRANSCOLOR) - self.Models[3]["roua"]:SetColor(Color(255,255,255,0)) + self.Models[3]["roua"]:SetColor(Color(255, 255, 255, 0)) end if IsValid(self.Models[3]["roua"]) then if State > 0 then @@ -526,6 +555,8 @@ function ENT:Think() end --self.SpecRouteNumbers end + + return true end function ENT:Draw() @@ -545,11 +576,20 @@ local ars = { {"125 Hz", "70 KM/H"}, {"75 Hz", "80 KM/H"}, } + + +local cols = { + R = Color(200,0,0), + Y = Color(200,200,0), + G = Color(0,200,0), + W = Color(200,200,200), + B = Color(0,0,200), +} local function enableDebug() if debug:GetBool() then - hook.Add("PostDrawTranslucentRenderables","MetrostroiSignalDebug",function(bDrawingDepth,bDrawingSkybox) - for _,ent in pairs(ents.FindByClass("gmod_track_signal")) do - if bDrawingDepth and LocalPlayer():GetPos():Distance(sig:GetPos()) < 384 then + hook.Add("PreDrawEffects","MetrostroiSignalDebug",function() + for _,sig in pairs(ents.FindByClass("gmod_track_signal")) do + if IsValid(sig) and LocalPlayer():GetPos():Distance(sig:GetPos()) < 384 then local pos = sig:LocalToWorld(Vector(48,0,150)) local ang = sig:LocalToWorldAngles(Angle(0,180,90)) cam.Start3D2D(pos, ang, 0.25) @@ -569,27 +609,27 @@ local function enableDebug() if sig.Name then draw.DrawText(Format("Joint main info (%d)",sig:EntIndex()),"Trebuchet24",5,-60,Color(200,0,0,255)) - draw.DrawText("Signal name: "..sig.Name,"Trebuchet24", 15, -40,Color(0,0,0,255)) - draw.DrawText("TrackID: "..sig:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0,0,0,255)) - draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0,0,0,255)) - draw.DrawText(Format("NextSignalName: %s",sig:GetNW2String("NextSignalName","N/A")),"Trebuchet24", 15, 0,Color(0,0,0,255)) - draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("NextPosID",0)),"Trebuchet24", 25, 20,Color(0,0,0,255)) - draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("NextPos",0)),"Trebuchet24", 135, 20,Color(0,0,0,255)) - draw.DrawText(Format("Dist: %.02f",sig:GetNW2Float("DistanceToNext",0)),"Trebuchet24", 15, 40,Color(0,0,0,255)) - draw.DrawText(Format("PrevSignalName: %s",sig:GetNW2String("PrevSignalName","N/A")),"Trebuchet24", 15, 60,Color(0,0,0,255)) - draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("PrevPosID",0)),"Trebuchet24", 25, 80,Color(0,0,0,255)) - draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("PrevPos",0)),"Trebuchet24", 135, 80,Color(0,0,0,255)) - draw.DrawText(Format("DistPrev: %.02f",sig:GetNW2Float("DistanceToPrev",0)),"Trebuchet24", 15, 100,Color(0,0,0,255)) - draw.DrawText(Format("Current route: %d",sig:GetNW2Int("CurrentRoute",-1)),"Trebuchet24", 15, 120,Color(0,0,0,255)) + draw.DrawText("Signal name: "..sig.Name,"Trebuchet24", 15, -40,Color(0, 0, 0, 255)) + draw.DrawText("TrackID: "..sig:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0, 0, 0, 255)) + draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0, 0, 0, 255)) + draw.DrawText(Format("NextSignalName: %s",sig:GetNW2String("NextSignalName","N/A")),"Trebuchet24", 15, 0,Color(0, 0, 0, 255)) + draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("NextPosID",0)),"Trebuchet24", 25, 20,Color(0, 0, 0, 255)) + draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("NextPos",0)),"Trebuchet24", 135, 20,Color(0, 0, 0, 255)) + draw.DrawText(Format("Dist: %.02f",sig:GetNW2Float("DistanceToNext",0)),"Trebuchet24", 15, 40,Color(0, 0, 0, 255)) + draw.DrawText(Format("PrevSignalName: %s",sig:GetNW2String("PrevSignalName","N/A")),"Trebuchet24", 15, 60,Color(0, 0, 0, 255)) + draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("PrevPosID",0)),"Trebuchet24", 25, 80,Color(0, 0, 0, 255)) + draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("PrevPos",0)),"Trebuchet24", 135, 80,Color(0, 0, 0, 255)) + draw.DrawText(Format("DistPrev: %.02f",sig:GetNW2Float("DistanceToPrev",0)),"Trebuchet24", 15, 100,Color(0, 0, 0, 255)) + draw.DrawText(Format("Current route: %d",sig:GetNW2Int("CurrentRoute",-1)),"Trebuchet24", 15, 120,Color(0, 0, 0, 255)) draw.DrawText("AB info","Trebuchet24",5,160,Color(200,0,0,255)) - draw.DrawText(Format("Occupied: %s",sig:GetNW2Bool("Occupied",false) and "Y" or "N"),"Trebuchet24",5,180,Color(0,0,0,255)) - draw.DrawText(Format("Linked to controller: %s",sig:GetNW2Bool("LinkedToController",false) and "Y" or "N"),"Trebuchet24",5,200,Color(0,0,0,255)) - draw.DrawText(Format("Num: %d",sig:GetNW2Int("ControllersNumber",0)),"Trebuchet24",10,220,Color(0,0,0,255)) - draw.DrawText(Format("Controller logic: %s",sig:GetNW2Bool("BlockedByController",false) and "Y" or "N"),"Trebuchet24",5,240,Color(0,0,0,255)) - draw.DrawText(Format("Autostop: %s",not sig.ARSOnly and sig.AutostopPresent and (sig:GetNW2Bool("Autostop") and "Up" or "Down") or "No present"),"Trebuchet24",5,260,Color(0,0,0,255)) - draw.DrawText(Format("2/6: %s",sig:GetNW2Bool("2/6",false) and "Y" or "N"),"Trebuchet24",5,280,Color(0,0,0,255)) - draw.DrawText(Format("FreeBS: %d",sig:GetNW2Int("FreeBS")),"Trebuchet24",5,300,Color(0,0,0,255)) + draw.DrawText(Format("Occupied: %s",sig:GetNW2Bool("Occupied",false) and "Y" or "N"),"Trebuchet24",5,180,Color(0, 0, 0, 255)) + draw.DrawText(Format("Linked to controller: %s",sig:GetNW2Bool("LinkedToController",false) and "Y" or "N"),"Trebuchet24",5,200,Color(0, 0, 0, 255)) + draw.DrawText(Format("Num: %d",sig:GetNW2Int("ControllersNumber",0)),"Trebuchet24",10,220,Color(0, 0, 0, 255)) + draw.DrawText(Format("Controller logic: %s",sig:GetNW2Bool("BlockedByController",false) and "Y" or "N"),"Trebuchet24",5,240,Color(0, 0, 0, 255)) + draw.DrawText(Format("Autostop: %s",not sig.ARSOnly and sig.AutostopPresent and (sig:GetNW2Bool("Autostop") and "Up" or "Down") or "No present"),"Trebuchet24",5,260,Color(0, 0, 0, 255)) + draw.DrawText(Format("2/6: %s",sig:GetNW2Bool("2/6",false) and "Y" or "N"),"Trebuchet24",5,280,Color(0, 0, 0, 255)) + draw.DrawText(Format("FreeBS: %d",sig:GetNW2Int("FreeBS")),"Trebuchet24",5,300,Color(0, 0, 0, 255)) draw.DrawText("ARS info","Trebuchet24",5,335,Color(200,0,0,255)) local num = 0 @@ -599,8 +639,8 @@ local function enableDebug() draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0,100,0,255)) draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0,100,0,255)) else - draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0,0,0,255)) - draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0,0,0,255)) + draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0, 0, 0, 255)) + draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255)) end num = num+1 end @@ -608,8 +648,8 @@ local function enableDebug() draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0,100,0,255)) draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0,100,0,255)) else - draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0,0,0,255)) - draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0,0,0,255)) + draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0, 0, 0, 255)) + draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255)) end if not sig.ARSOnly then @@ -627,17 +667,11 @@ local function enableDebug() if not data then continue end --sig.NamesOffset = sig.NamesOffset + Vector(0,0,data[1]) - local cols = { - R = Color(200,0,0), - Y = Color(200,200,0), - G = Color(0,200,0), - W = Color(200,200,200), - B = Color(0,0,200), - } if v ~= "M" then for i = 1,#v do ID2 = ID2 + 1 - local State = tonumber(sig.Sig[ID2]) == 1 and "X" or (tonumber(sig.Sig[ID2]) == 2 and (RealTime() % 1.2 > 0.4)) and "B" or false + local n = tonumber(sig.Sig[ID2]) + local State = n == 1 and "X" or (n == 2 and (RealTime() % 1.2 > 0.4)) and "B" or false draw.DrawText(Format(v[i],sig:EntIndex()),"Trebuchet24",250,160 + ID*20 + ID2*20,cols[v[i]]) if State then draw.DrawText(State,"Trebuchet24",280,160 + ID*20 + ID2*20,cols[v[i]]) @@ -655,22 +689,22 @@ local function enableDebug() end end else - draw.DrawText("No data...","Trebuchet24",5,0,Color(0,0,0,255)) + draw.DrawText("No data...","Trebuchet24",5,0,Color(0, 0, 0, 255)) end else surface.SetDrawColor(sig.ARSOnly and 255 or 125, 125, 0, 255) surface.DrawRect(0, 0, 364, 25) - draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0,0,0,255)) + draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0, 0, 0, 255)) end cam.End3D2D() end end end) else - hook.Remove("PostDrawTranslucentRenderables","MetrostroiSignalDebug") + hook.Remove("PreDrawEffects","MetrostroiSignalDebug") end end -hook.Remove("PostDrawTranslucentRenderables","MetrostroiSignalDebug") +hook.Remove("PreDrawEffects","MetrostroiSignalDebug") cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug) enableDebug() diff --git a/lua/entities/gmod_track_signal/init.lua b/lua/entities/gmod_track_signal/init.lua index 9372587..bca3d5f 100644 --- a/lua/entities/gmod_track_signal/init.lua +++ b/lua/entities/gmod_track_signal/init.lua @@ -178,7 +178,7 @@ function MSignalSayHook(ply, comm, fromULX) end hook.Add("PlayerSay","metrostroi-signal-say", function(ply, comm) MSignalSayHook(ply,comm) end) function ENT:Initialize() - self:SetModel("models/metrostroi/signals/mus/ars_box.mdl") + self:SetModel(self.TrafficLightModels[self.SignalType or 0].ArsBox.model) self.Sprites = {} self.Sig = "" self.FreeBS = 1 @@ -303,9 +303,9 @@ function ENT:PostInitalize() self.GoodInvationSignal = -1 end if self.Left then - self:SetModel("models/metrostroi/signals/mus/ars_box_mittor.mdl") + self:SetModel(self.TrafficLightModels[self.SignalType or 0].ArsBoxMittor.model) else - self:SetModel("models/metrostroi/signals/mus/ars_box.mdl") + self:SetModel(self.TrafficLightModels[self.SignalType or 0].ArsBox.model) end self.PostInitalized = false diff --git a/lua/entities/gmod_track_signal/shared.lua b/lua/entities/gmod_track_signal/shared.lua index 106aa6f..3ab5b60 100644 --- a/lua/entities/gmod_track_signal/shared.lua +++ b/lua/entities/gmod_track_signal/shared.lua @@ -171,7 +171,7 @@ ENT.OldRouteNumberSetup = { "1234D", "WKFX","LR", Vector(6,0,10.5), - {D=4},{["F"]=0,["L"]=0,["R"]=2,W=3,K=4} + {D=4},{["F"]=0,["L"]=2,["R"]=0,W=3,K=4} } -------------------------------------------------------------------------------- @@ -294,3 +294,26 @@ ENT.SignalConverter = { B = 4, W = 5 } + + +for i = 0,2 do + --SERVER + ENT.TrafficLightModels[i].ArsBox = {model = "models/metrostroi/signals/mus/ars_box.mdl"} + ENT.TrafficLightModels[i].ArsBoxMittor = {model = "models/metrostroi/signals/mus/ars_box_mittor.mdl"} + + --CLIENT + ENT.TrafficLightModels[i].LampIndicator = {model = "models/metrostroi/signals/mus/light_lampindicator", Vector(0.2), Vector(1), Vector(8), Vector(-0.9,1,1), Vector(3,0,3), Vector(-1,1,0.85)} + ENT.TrafficLightModels[i].LampBase = {model = "models/metrostroi/signals/mus/lamp_base.mdl"} + ENT.TrafficLightModels[i].SignLetterSmall = {model = "models/metrostroi/signals/mus/sign_letter_small.mdl", Vector(1.5,0,0), Vector(-1.5,0,0)} + ENT.TrafficLightModels[i].SignLetter = {model = "models/metrostroi/signals/mus/sign_letter.mdl", z = 5.85} + ENT.TrafficLightModels[i].LetMaterials = {str = "models/metrostroi/signals/let/"} + + ENT.TrafficLightModels[i].RouteNumberOffset = Vector(10,0,0) + ENT.TrafficLightModels[i].DoubleOffset = Vector(0,0,1.62) + ENT.TrafficLightModels[i].RouteNumberOffset2 = Vector(0,0,7.2) + ENT.TrafficLightModels[i].SpecRouteNumberOffset = Vector(3,-1,3) + ENT.TrafficLightModels[i].RouteNumberOffset3 = Vector(10.5,0,-6) + ENT.TrafficLightModels[i].SpecRouteNumberOffset2 = Vector(-0.8,1,0.94) + ENT.TrafficLightModels[i].RouaOffset = Vector(6.2,0,24.5) +end + diff --git a/lua/entities/gmod_track_switch/cl_init.lua b/lua/entities/gmod_track_switch/cl_init.lua index 8a6c5bf..7f8c7f1 100644 --- a/lua/entities/gmod_track_switch/cl_init.lua +++ b/lua/entities/gmod_track_switch/cl_init.lua @@ -3,9 +3,9 @@ include("shared.lua") local debug = GetConVar("metrostroi_drawsignaldebug") local function enableDebug() if debug:GetBool() then - hook.Add("PostDrawTranslucentRenderables","MetrostroiSwitchDebug",function(bDrawingDepth,bDrawingSkybox) + hook.Add("PreDrawEffects","MetrostroiSwitchDebug",function() for _,ent in pairs(ents.FindByClass("gmod_track_switch")) do - if bDrawingDepth and LocalPlayer():GetPos():Distance(sig:GetPos()) < 512 then + if IsValid(ent) and LocalPlayer():GetPos():Distance(ent:GetPos()) < 512 then local pos = ent:LocalToWorld(Vector(30,0,75)) local ang = ent:LocalToWorldAngles(Angle(0,180,90)) cam.Start3D2D(pos, ang, 0.25) @@ -18,9 +18,9 @@ local function enableDebug() end end) else - hook.Remove("PostDrawTranslucentRenderables","MetrostroiSwitchDebug") + hook.Remove("PreDrawEffects","MetrostroiSwitchDebug") end end -hook.Remove("PostDrawTranslucentRenderables","MetrostroiSwitchDebug") +hook.Remove("PreDrawEffects","MetrostroiSwitchDebug") cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug) enableDebug() \ No newline at end of file