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:
Ivan Gordeev
2021-07-12 19:46:28 +03:00
committed by GitHub
parent fd797d93a1
commit d1f826636b
2 changed files with 40 additions and 36 deletions

View File

@@ -151,6 +151,7 @@ end
function ENT:Initialize()
self.MotorPowerSound = 0
self.PlayTime = { 0, 0 }
self.SmoothAngleDelta = 0
self.CurrentBrakeSqueal = 0
self:ReinitializeSounds()
@@ -437,4 +438,34 @@ net.Receive("metrostroi-bogey-menu",function()
havepb=net.ReadBool(),
pbdisabled=net.ReadBool(),
}
end)
net.Receive("metrostroi_bogey_contact",function()
local ent = net.ReadEntity()
if not IsValid(ent) then return end
local PantNum = net.ReadUInt(1)+1
local PantPos = net.ReadVector()
local Spark = net.ReadUInt(1) > 0
local dt = CurTime() - ent.PlayTime[PantNum]
ent.PlayTime[PantNum] = CurTime()
local volume = 0.53
if dt < 1.0 then volume = 0.43 end
sound.Play("subway_trains/bogey/tr_"..math.random(1,5)..".wav",ent:LocalToWorld(PantPos),65,math.random(90,120),volume)
if not Spark then return end
local effectdata = EffectData()
effectdata:SetOrigin(ent:LocalToWorld(PantPos))
effectdata:SetNormal(Vector(0,0,-1))
util.Effect("stunstickimpact", effectdata, true, true)
local light = ents.CreateClientside("gmod_train_dlight")
light:SetPos(effectdata:GetOrigin())
light:SetDColor(Color(100,220,255))
light:SetSize(256)
light:SetBrightness(5)
light:Spawn()
SafeRemoveEntityDelayed(light,0.1)
sound.Play("subway_trains/bogey/spark.mp3",effectdata:GetOrigin(),75,math.random(100,150),volume)
end)

View File

@@ -3,6 +3,7 @@
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
util.AddNetworkString("metrostroi_bogey_contact")
local DECOUPLE_TIMEOUT = 2 -- Time after decoupling furing wich a bogey cannot couple
local COUPLE_MAX_DISTANCE = 20 -- Maximum distance between couple offsets
@@ -117,7 +118,6 @@ function ENT:Initialize()
self.Voltage = 0
self.VoltageDrop = 0
self.DropByPeople = 0
self.PlayTime = { 0, 0 }
self.ContactStates = { false, false }
self.DisableContacts = false
self.DisableContactsManual = false
@@ -449,43 +449,16 @@ function ENT:CheckVoltage(dT)
if state ~= self.ContactStates[i] then
self.ContactStates[i] = state
if not state then continue end
self.VoltageDrop = -40*(0.5 + 0.5*math.random())
local dt = CurTime() - self.PlayTime[i]
self.PlayTime[i] = CurTime()
local volume = 0.53
if dt < 1.0 then volume = 0.43 end
if i == 1 then sound.Play("subway_trains/bogey/tr_"..math.random(1,5)..".wav",self:LocalToWorld(self.PantLPos),65,math.random(90,120),volume) end
if i == 2 then sound.Play("subway_trains/bogey/tr_"..math.random(1,5)..".wav",self:LocalToWorld(self.PantRPos),65,math.random(90,120),volume) end
-- Sparking probability
local probability = math.Clamp(1-(self.MotorPower/2),0,1)
if math.random() > probability then
local effectdata = EffectData()
if i == 1 then effectdata:SetOrigin(self:LocalToWorld(self.PantLPos)) end
if i == 2 then effectdata:SetOrigin(self:LocalToWorld(self.PantRPos)) end
effectdata:SetNormal(Vector(0,0,-1))
util.Effect("stunstickimpact", effectdata, true, true)
local light = ents.Create("light_dynamic")
light:SetPos(effectdata:GetOrigin())
light:SetKeyValue("_light","100 220 255")
light:SetKeyValue("style", 0)
light:SetKeyValue("distance", 256)
light:SetKeyValue("brightness", 5)
light:Spawn()
light:Fire("TurnOn","","0")
light.Time = CurTime()
timer.Simple(0.1,function()
SafeRemoveEntity(light)
end)
sound.Play("subway_trains/bogey/spark.mp3",effectdata:GetOrigin(),75,math.random(100,150),volume)
--self.Train:PlayOnce("zap",sound_source,0.7*volume,50+math.random(90,120))
end
net.Start("metrostroi_bogey_contact")
net.WriteEntity(self) -- Bogey
net.WriteUInt(i-1,1) -- PantNum
net.WriteVector(i == 1 and self.PantLPos or self.PantRPos) -- PantPos
net.WriteUInt((math.random() > math.Clamp(1-(self.MotorPower/2),0,1)) and 1 or 0,1) -- Sparking probability
net.Broadcast()
end
end
-- Voltage spikes
self.VoltageDrop = math.max(-30,math.min(30,self.VoltageDrop + (0 - self.VoltageDrop)*10*dT))