Skip to content
4 changes: 1 addition & 3 deletions lua/autorun/photon/cl_emv_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ local function DrawEMVLights()
if not should_render:GetBool() then return end

for k, v in pairs(EMVU:AllVehicles()) do
if IsValid(v) and v.IsEMV and v:IsEMV() then
if IsValid(v) then
if v.Photon_RenderEL then
v:Photon_RenderEL()
else
EMVU:MakeEMV(v, v:EMVName())
end
if v.Photon_RenderIllum then
v:Photon_RenderIllum()
Expand Down
8 changes: 7 additions & 1 deletion lua/autorun/photon/cl_emv_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ end)

local printedErrors = {}

hook.Add("Photon.SimpleNet.ValueChanged", "Photon.SetupEMV", function(name, old, new, ent)
if name == "VehicleIndex" then
EMVU:MakeEMV(ent, new)
end
end)

function EMVU:MakeEMV( emv, name )

if not emv or not emv:IsValid() or not emv:IsVehicle() then return false end
if not emv or not emv:IsValid() or not emv:IsVehicle() or not emv:IsEMV() then return false end

if name == "1" then return end

Expand Down
39 changes: 39 additions & 0 deletions lua/autorun/photon/emv/sh_meta.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--[[-- Emergency Lighting Vehicle Meta
@copyright Photon Team
@release development
@author Photon Team
@module VEHICLE
@alias ENT
--]]--

local ENT = FindMetaTable("Vehicle")

function ENT:EMVName()
return self:GetPhotonNet_VehicleIndex("")
end

function ENT:Photon_GetUnitNumber()
return self:GetPhotonNet_UnitNumber("")
end

function ENT:Photon_GetLiveryID()
return self:GetPhotonNet_LiveryID("")
end

function ENT:Photon_SelectionString()
return self:GetPhotonNet_SelectionString("")
end

function ENT:Photon_SelectionTable()
return string.Split(self:Photon_SelectionString(), ".")
end

function ENT:Photon_GetUtilStringTable()
return {
"",
self:EMVName(),
self:Photon_GetUnitNumber(),
self:Photon_GetLiveryID(),
self:Photon_SelectionString()
}
end
37 changes: 37 additions & 0 deletions lua/autorun/photon/emv/sv_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,40 @@ end
function ENT:ELS_HasAuxSiren()
return self:ELS_AuxSirenSet() ~= nil and self:ELS_AuxSirenSet() ~= 0
end

function ENT:Photon_SetLiveryId(val)
return self:SetPhotonNet_UnitNumber(val)
end

function ENT:Photon_SetUnitNumber(val)
val = tostring(val):upper()
if #val > 3 then
val = string.sub(val, 1, 3)
end
if not val:match("%w") then
val = ""
end
if PHOTON_BANNED_UNIT_IDS[val:lower()] then
val = ""
end

return self:GetPhotonNet_LiveryID(val)
end

function ENT:Photon_SetSelection(index, value)
if not istable(EMVU.Selections[self.Name][index]) then
return
end

local selectionTable = self:Photon_SelectionTable()
selectionTable[index] = value
self:SetPhotonNet_SelectionString(table.concat(selectionTable, "."))

local selectionData = EMVU.Selections[self.Name][index].Options[value]

if istable(selectionData.Bodygroups) then
for _, bgData in ipairs(selectionData.Bodygroups) do
self:SetBodygroup(bgData[1], bgData[2])
end
end
end
3 changes: 2 additions & 1 deletion lua/autorun/photon/sh_emv_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ include( "library/emv_auto.lua" )

Photon.include("emv/cl_meta.lua")
Photon.include("emv/sv_meta.lua")
Photon.include("emv/sh_meta.lua")

local emvVehicleTable = {}
local emvLastScan = 0
Expand All @@ -82,7 +83,7 @@ function EMVU:UpdateVehicles()
end

for _,ent in pairs( ents.GetAll() ) do
if IsValid( ent ) and ent.IsEMV and ent:IsEMV() then
if IsValid( ent ) and ent:IsVehicle() and ent.IsEMV and ent:IsEMV() then
emvVehicleTable[ #emvVehicleTable + 1 ] = ent
end
end
Expand Down
37 changes: 4 additions & 33 deletions lua/autorun/photon/sh_emv_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ local istable = istable
function ent:IsEMV()
if not IsValid( self ) then return false end
if not EMV_INDEX then return false end
local str = self:GetNW2String( "PhotonLE.EMV_INDEX" )
if string.StartWith( tostring(str), "ö" ) then return true end
if self:EMVName() ~= "" then return true end
return false
end

Expand All @@ -26,15 +25,6 @@ function ent:HasPhotonELS()
return true
end

function ent:EMVName()
if not IsValid( self ) then return "" end
if not EMV_INDEX then return "" end
if self:IsEMV() then
return string.Explode( "ö", self:GetNW2String( "PhotonLE.EMV_INDEX" ), false )[2]
end
return ""
end

function ent:Photon_GetSpeed()
if not IsValid( self ) then return 0 end
return self:GetVelocity():Length()
Expand All @@ -45,14 +35,6 @@ function ent:Photon_AdjustedSpeed()
return ( self:GetVelocity():Length() * ( 3600 / 63360 ) )
end

function ent:Photon_GetUnitNumber()
return string.Explode( "ö", self:GetNW2String( "PhotonLE.EMV_INDEX" ), false )[3] or ""
end

function ent:Photon_GetLiveryID()
return string.Explode( "ö", self:GetNW2String( "PhotonLE.EMV_INDEX" ), false )[4] or ""
end

function ent:Photon_GetAutoSkinIndex()
local materials = self:GetMaterials()
for i=1,#materials do
Expand All @@ -75,16 +57,9 @@ end
ent.LegacySetSkin = ent.LegacySetSkin or ent.SetSkin
function ent:SetSkin( index )
self:LegacySetSkin( index )
hook.Call( "Photon.EntityChangedSkin", GM, self, index )
end

function ent:Photon_SelectionString()
return string.Explode( "ö", self:GetNW2String( "PhotonLE.EMV_INDEX" ), false )[5]
end

function ent:Photon_SelectionTable()
local selectionString = string.Explode( "ö", self:GetNW2String( "PhotonLE.EMV_INDEX" ), false )[5]
return string.Explode( ".", selectionString, false )
if self:IsVehicle() and self:IsEMV() then
hook.Call( "Photon.EntityChangedSkin", GM, self, index )
end
end

function ent:Photon_SelectionOption( index )
Expand Down Expand Up @@ -184,10 +159,6 @@ function ent:Photon_ImportSelectionData( inputData )
return resultTable
end

function ent:Photon_GetUtilStringTable()
return string.Explode( "ö", self:GetNW2String( "PhotonLE.EMV_INDEX" ), false )
end

function ent:Photon_SelectionEnabled()
return istable( EMVU.Selections[ self:EMVName() ] )
end
Expand Down
14 changes: 11 additions & 3 deletions lua/autorun/photon/shared/sh_simplenet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,18 @@ function NET:Get(ent, name, default)
end

if CLIENT then
net.Receive("Photon_SimpleNet_Change", function(len, ply)
net.Receive("Photon_SimpleNet_Change", function()
local ent = net.ReadEntity()
local idx = net.ReadUInt(NET.Bits)
local name, netType, extra = unpack(NET.FMap[idx])
ent[NET.Normalise(name)] = NET.ReadFunctions[netType](extra)
local normalName = NET.Normalise(name)
local old = ent[normalName]
ent[normalName] = NET.ReadFunctions[netType](extra)
hook.Run("Photon.SimpleNet.ValueChanged", name, old, ent[normalName], ent)
end)
end

local UInt, Bool = NET.UINT, NET.BOOL
local UInt, Bool, Str = NET.UINT, NET.BOOL, NET.STR

NET:Map("CurrentSignal", UInt, 2)
NET:Map("Blinker", UInt, 2)
Expand All @@ -155,3 +158,8 @@ NET:Map("TrafficOption", UInt, 4)
NET:Map("IlluminationOn", Bool)
NET:Map("IlluminationOption", UInt, 4)
NET:Map("Preset", UInt, 10)

NET:Map("VehicleIndex", Str)
NET:Map("UnitNumber", Str)
NET:Map("LiveryID", Str)
NET:Map("SelectionString", Str)
42 changes: 1 addition & 41 deletions lua/autorun/photon/sv_emv_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -555,23 +555,6 @@ function EMVU:MakeEMV( ent, emv )
end
end

function ent:Photon_SetLiveryId( val )
local curdata = string.Explode( "ö", self:GetNW2String( "PhotonLE.EMV_INDEX" ), false )
curdata[4] = val
self:SetNW2String( "PhotonLE.EMV_INDEX", table.concat( curdata, "ö" ))
end

function ent:Photon_SetUnitNumber( val )
val = string.upper( tostring( val ) )
if string.len( val ) > 3 then val = string.sub( val, 1, 3 ) end
if not string.match( val, "%w" ) then val = "" end
if PHOTON_BANNED_UNIT_IDS[ string.lower( val ) ] then val = "" end
local curdata = string.Explode( "ö", self:GetNW2String( "PhotonLE.EMV_INDEX" ), false )
curdata[3] = val
self:SetNW2String( "PhotonLE.EMV_INDEX", table.concat( curdata, "ö" ) )
return val
end

function ent:Photon_ApplySubMaterials()
if istable( EMVU.SubMaterials[ self.Name ] ) then
local submaterials = EMVU.SubMaterials[ self.Name ]
Expand All @@ -583,25 +566,6 @@ function EMVU:MakeEMV( ent, emv )
end
end

function ent:Photon_SetSelection( index, value )
-- print(string.format( "index: %s value: %s", index, value ))
if istable( EMVU.Selections[ self.Name ][ index ] ) then
local selectionTable = self:Photon_SelectionTable()
selectionTable[index] = value
-- PrintTable( selectionTable )
local photonUtilString = self:Photon_GetUtilStringTable()
photonUtilString[5] = table.concat( selectionTable, "." )
--PrintTable( photonUtilString )
self:Photon_SetUtilString( table.concat( photonUtilString, "ö" ) )
local selectionData = EMVU.Selections[ self.Name ][ index ].Options[value]
if istable( selectionData.Bodygroups ) then
for _,bgData in pairs( selectionData.Bodygroups ) do
self:SetBodygroup( bgData[1], bgData[2] )
end
end
end
end

function ent:Photon_ResetSelections()
if istable( EMVU.Selections[ self.Name ] ) then
for i=1,#EMVU.Selections[ self.Name ] do
Expand All @@ -610,10 +574,6 @@ function EMVU:MakeEMV( ent, emv )
end
end

function ent:Photon_SetUtilString( str )
self:SetNW2String( "PhotonLE.EMV_INDEX", str )
end

function ent:Photon_HasManualWind()
local set = self:ELS_SirenSet()
return istable( EMVU.GetSirenTable()[set].Gain )
Expand All @@ -638,7 +598,7 @@ function EMVU:MakeEMV( ent, emv )
end

ent.IsEMV = true
ent:SetNW2String( "PhotonLE.EMV_INDEX", "ö" .. tostring( ent.Name ) .. "ööö." ) -- Al
ent:SetPhotonNet_VehicleIndex(ent.Name)

------ APPLY EMV PARAMETERS ------

Expand Down