mirror of
https://github.com/metrostroi-repo/MetrostroiAddon.git
synced 2026-05-04 00:52:33 +00:00
init
This commit is contained in:
66
lua/entities/gmod_track_clock_interval/cl_init.lua
Normal file
66
lua/entities/gmod_track_clock_interval/cl_init.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
include("shared.lua")
|
||||
ENT.DigitPositions = {
|
||||
{Vector(14,-8.5,0)},
|
||||
{Vector(-2,-8.5,0)},
|
||||
{Vector(-15,-8.5,0)},
|
||||
{Vector(7,-8.5,0),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) do
|
||||
if not IsValid(self.Digits[k]) then
|
||||
local model
|
||||
if v[2] then
|
||||
model = "models/metrostroi/mus_clock/ind_"..(self:GetNW2Bool("Type") and "spb" or "msk").."_type"..tostring(self:GetNW2Int("Light",1)).."_dot.mdl"
|
||||
else
|
||||
model = "models/metrostroi/mus_clock/ind_"..(self:GetNW2Bool("Type") and "spb" or "msk").."_type"..tostring(self:GetNW2Int("Light",1)).."_numb.mdl"
|
||||
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]))
|
||||
--end)
|
||||
self.Digits[k] = ClientsideModel(model, RENDERGROUP_OPAQUE)
|
||||
|
||||
--if ent.Spawned then hook.Remove("MetrostroiBigLag",ent) end
|
||||
--ent.Spawned = true
|
||||
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 dT = Metrostroi.GetTimedT()
|
||||
--local interval = -dT + os.time() - (self:GetIntervalResetTime()+GetGlobalFloat("MetrostroiTY"))
|
||||
local interval = Metrostroi.GetSyncTime() - (self:GetIntervalResetTime() + GetGlobalFloat("MetrostroiTY"))
|
||||
if (interval <= (9 * 60 + 59)) and (interval >= 0) then
|
||||
if IsValid(self.Digits[1]) then self.Digits[1]:SetSkin(math.floor(interval / 60)) end
|
||||
if IsValid(self.Digits[2]) then self.Digits[2]:SetSkin(math.floor((interval % 60) / 10)) end
|
||||
if IsValid(self.Digits[3]) then self.Digits[3]:SetSkin(math.floor((interval % 60) % 10)) end
|
||||
else
|
||||
for i = 1, 3 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
|
||||
103
lua/entities/gmod_track_clock_interval/init.lua
Normal file
103
lua/entities/gmod_track_clock_interval/init.lua
Normal file
@@ -0,0 +1,103 @@
|
||||
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 0)
|
||||
self.Light = (tonumber(self.VMF.Light) or 0)
|
||||
self.NoAutoSearch = (tonumber(self.VMF.NoAutoSearch) or 0)
|
||||
self.NoInterval = (tonumber(self.VMF.NoInterval) or 0)
|
||||
if self.Type == 0 then
|
||||
self:SetModel("models/metrostroi/clock_interval_moscow.mdl")
|
||||
else
|
||||
self:SetModel("models/metrostroi/clock_interval_type2.mdl")
|
||||
end
|
||||
self:SetNW2Bool("Type",self.Type > 0)
|
||||
self:SetNW2Int("Light",self.Light+1)
|
||||
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
|
||||
11
lua/entities/gmod_track_clock_interval/shared.lua
Normal file
11
lua/entities/gmod_track_clock_interval/shared.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
ENT.Type = "anim"
|
||||
|
||||
ENT.Category = "Metrostroi (utility)"
|
||||
|
||||
ENT.Spawnable = true
|
||||
ENT.AdminSpawnable = false
|
||||
|
||||
function ENT:SetupDataTables()
|
||||
self:NetworkVar("Float", 0, "IntervalResetTime")
|
||||
self:NetworkVar("Float", 0, "IntervalResetTime")
|
||||
end
|
||||
Reference in New Issue
Block a user