1
0
mirror of https://github.com/metrostroi-repo/MetrostroiAddon.git synced 2026-05-02 00:42:29 +00:00
This commit is contained in:
g_brzhezinskiy
2021-01-02 12:51:45 +03:00
commit 1d05caf866
613 changed files with 337020 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
include("shared.lua")
ENT.DigitPositions = {
{
{Vector(16+7,-1,1)},
{Vector(9+7,-1,1)},
{Vector(-0+7,-1,1)},
{Vector(-7+7,-1,1)},
{Vector(-16+7,-1,1)},
{Vector(-23+7,-1,1)},
{Vector(-11+7-0.5,-1,0.7), true}, --точка
{Vector(5+7-0.5,-1,0.7), true}, --точка
{Vector(-7+7,-1,-11)},
{Vector(-16+7,-1,-11)},
{Vector(-23+7,-1,-11)},
{Vector(-11+7-0.5,-1,-11.3), true}, -- точка
},{
{Vector(18.3,-0.3,0.8)},
{Vector(12.8,-0.3,0.8)},
{Vector( 7.3,-0.3,0.8)},
{Vector( 1.8,-0.3,0.8)},
{Vector(-3.7,-0.3,0.8)},
{Vector(-9.2,-0.3,0.8)},
{Vector( 8.8,-0.3,0.5), true}, --точка
{Vector(-2.3,-0.3,0.5), true}, --точка
{Vector(18.3,-0.3,-8.7)},
{Vector(12.8,-0.3,-8.7)},
{Vector( 7.3,-0.3,-8.7)},
{Vector(14.2,-0.3,-9), true}, -- точка
}
}
function ENT:Initialize()
self.Digits = {}
end
function ENT:Think()
if self:IsDormant() then self:OnRemove();return end
for k,v in pairs(self.DigitPositions[self:GetNW2Int("Type") == 2 and 2 or 1]) do
if not IsValid(self.Digits[k]) then
local model
if v[2] then
if self:GetNW2Int("Type") == 2 then
model = "models/metrostroi/mus_clock/ind_small_orange_dot_spb.mdl"
else
model = "models/metrostroi/mus_clock/ind_small_"..(self:GetNW2Int("Type") == 1 and "red" or "orange").."_dot.mdl"
end
else
if self:GetNW2Int("Type") == 2 then
model = "models/metrostroi/mus_clock/ind_small_orange_numb_spb.mdl"
else
model = "models/metrostroi/mus_clock/ind_small_"..(self:GetNW2Int("Type") == 1 and "red" or "orange").."_numb.mdl"
end
end
--self.Digits[k] = ents.CreateClientProp("models/metrostroi/81-717/reverser.mdl")
--self.Digits[k]:SetModel(model)
--hook.Add("MetrostroiBigLag",self.Digits[k],function(ent)
-- ent:SetPos(self:LocalToWorld(v[1]))
-- --if ent.Spawned then hook.Remove("MetrostroiBigLag",ent) end
-- --ent.Spawned = true
--end)
self.Digits[k] = ClientsideModel(model,RENDERGROUP_OPAQUE)
self.Digits[k]:SetPos(self:LocalToWorld(v[1]))
self.Digits[k]:SetAngles(self:GetAngles())
self.Digits[k]:SetSkin(10)
self.Digits[k]:SetParent(self)
end
end
local d = os.date("!*t",Metrostroi.GetSyncTime())
if IsValid(self.Digits[1]) then self.Digits[1]:SetSkin(math.floor(d.hour / 10)) end
if IsValid(self.Digits[2]) then self.Digits[2]:SetSkin(math.floor(d.hour % 10)) end
if IsValid(self.Digits[3]) then self.Digits[3]:SetSkin(math.floor(d.min / 10)) end
if IsValid(self.Digits[4]) then self.Digits[4]:SetSkin(math.floor(d.min % 10)) end
if IsValid(self.Digits[5]) then self.Digits[5]:SetSkin(math.floor(d.sec / 10)) end
if IsValid(self.Digits[6]) then self.Digits[6]:SetSkin(math.floor(d.sec % 10)) end
--local dT = Metrostroi.GetTimedT()
local interval = Metrostroi.GetSyncTime() - (self:GetIntervalResetTime()+GetGlobalFloat("MetrostroiTY"))
if (interval <= (9*60+59)) and (interval >= 0) then
if IsValid(self.Digits[9]) then self.Digits[9]:SetSkin(math.floor(interval/60)) end
if IsValid(self.Digits[10]) then self.Digits[10]:SetSkin(math.floor((interval%60)/10)) end
if IsValid(self.Digits[11]) then self.Digits[11]:SetSkin(math.floor((interval%60)%10)) end
else
for i = 9,11 do
if IsValid(self.Digits[i]) then
self.Digits[i]:SetSkin(10)
end
end
end
end
function ENT:OnRemove()
for _,v in pairs(self.Digits) do
SafeRemoveEntity(v)
end
end
function ENT:Draw()
self:DrawModel()
end

View File

@@ -0,0 +1,102 @@
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:KeyValue(key, value)
self.VMF = self.VMF or {}
self.VMF[key] = value
end
function ENT:Initialize()
self:EntIndex()
self.VMF = self.VMF or {}
self.Type = (tonumber(self.VMF.Type) or tonumber(self.VMF.type) or 2)
self.NoAutoSearch = (tonumber(self.VMF.NoAutoSearch) or 0)
self.NoInterval = (tonumber(self.VMF.NoInterval) or 0)
self:SetNW2Int("Type",self.Type)
if self.Type == 2 then
self:SetModel("models/metrostroi/mus_clock/ind_small_base_spb.mdl")
else
self:SetModel("models/metrostroi/mus_clock/ind_small_base.mdl")
end
end
function ENT:PostInitalize()
if self.NoInterval == 1 then return end
self.Signal = nil
if self.NoAutoSearch == 0 then
local mind, sig
for _,v in pairs(ents.FindInSphere(self:GetPos(),1512)) do
if v:GetClass() == "gmod_track_signal" and not v.ARSOnly and (not sig or v:GetPos():Distance(self:GetPos()) < mind) and (self:GetAngles()-v:GetAngles()):Forward().x > 0 then
--err = self:WorldToLocal(v:GetPos()).y < 0
--print(self:WorldToLocal(v:GetPos()).x)
sig = v
mind = v:GetPos():Distance(self:GetPos())
delta_z = math.abs(self:GetPos().z-v:GetPos().z)
end
end
if sig then
self.Signal = sig
--print(self,"linked to",sig.Name,mind,self:WorldToLocal(sig:GetPos()).x)
end
end
end
function ENT:Think()
if self.NoInterval == 1 then return end
self.SensingTrain = false
if self.NoAutoSearch == 0 then
if IsValid(self.Signal) then
if self.Signal.OccupiedBy and self.Signal.OccupiedBy ~= self.Signal then
self.SensingTrain = true
end
else
-- Check if train passes the sign
for ray=0,6 do
local trace = {
start = self:GetPos() - self:GetRight()*16 + self:GetForward()*50*(ray-3) + Vector(0,0,64),
endpos = self:GetPos() - self:GetRight()*16 + self:GetForward()*50*(ray-3) - Vector(0,0,256),
--mask = -1,
--filter = { },
ignoreworld = true,
}
--debugoverlay.Cross(trace.start,10,1,Color(0,0,255))
--debugoverlay.Line(trace.start,trace.endpos,1,Color(0,0,255))
local result = util.TraceLine(trace)
if result.Hit and (not result.HitWorld) then
--debugoverlay.Sphere(result.HitPos,5,1,Color(0,0,255),true)
if result.Entity and (not result.Entity:IsPlayer()) then
self.SensingTrain = true
end
end
end
end
end
-- If only sensing train for the first time, reset
self.SensingTime = self.SensingTime or (Metrostroi.GetSyncTime())
if self.SensingTrain and (not self.IntervalReset) then
self:SetIntervalResetTime(Metrostroi.GetSyncTime()-GetGlobalFloat("MetrostroiTY")+Metrostroi.GetTimedT())
self.SensingTime = Metrostroi.GetSyncTime()
self.IntervalReset = true
end
-- If not sensing anything for more than 3 seconds, expect something again
if (not self.SensingTrain) and (Metrostroi.GetSyncTime() - self.SensingTime > 7.0) then
self.IntervalReset = false
end
self:NextThink(CurTime() + (self.NoAutoSearch ~= 0 and 2 or not IsValid(self.Signal) and 1 or 0.5))
return true
end
function ENT:AcceptInput( input, activator, called, data )
if self.NoInterval == 1 then return end
if input == "Reset" then
if not self.IntervalReset then
self:SetIntervalResetTime(Metrostroi.GetSyncTime()-GetGlobalFloat("MetrostroiTY")+Metrostroi.GetTimedT())
self.SensingTime = Metrostroi.GetSyncTime()
self.IntervalReset = true
end
end
end

View File

@@ -0,0 +1,10 @@
ENT.Type = "anim"
ENT.Category = "Metrostroi (utility)"
ENT.Spawnable = true
ENT.AdminSpawnable = false
function ENT:SetupDataTables()
self:NetworkVar("Float", 0, "IntervalResetTime")
end