Fixed station spawning at lua refresh

master
AlmTech Software 5 years ago
parent d640b2d56c
commit 1def9f6672
  1. 38
      gamemode/engine/lib/sh_station.lua
  2. 2
      gamemode/init.lua
  3. 1
      gamemode/settings/sv_crafting_stations_locations.lua
  4. 3
      gamemode/settings/sv_settings.lua

@ -24,6 +24,7 @@ function Quantum.Station.Add( id, tbl )
end end
function Quantum.Station.Get( id ) function Quantum.Station.Get( id )
if( isnumber(id) ) then return nil end
return Quantum.Stations[id] return Quantum.Stations[id]
end end
@ -33,12 +34,8 @@ end
if SERVER then if SERVER then
Quantum.Server.Station = {} Quantum.Server.Station = {}
Quantum.Server.Stations = {}
Quantum.Server.Stations.Locations = {}
if( Stations == nil ) then
Stations = {}
Stations.Locations = {}
end
function Quantum.Server.Station.Spawn( stationid, pos, ang ) -- internal function function Quantum.Server.Station.Spawn( stationid, pos, ang ) -- internal function
local ent = ents.Create( "q_crafting_station" ) local ent = ents.Create( "q_crafting_station" )
@ -53,16 +50,20 @@ if SERVER then
end end
function Quantum.Server.Station.Register( stationid, vec, angle ) function Quantum.Server.Station.Register( stationid, vec, angle )
if( Stations.Locations == nil ) then if( Quantum.Server.Stations.Locations == nil ) then
Quantum.Error( "Station tbl is nil" ) Quantum.Error( "Station tbl is nil" )
end end
Quantum.Debug( "Registering station '" .. tostring( stationid ) .. "'." )
Stations.Locations[ #Stations.Locations + 1] = { if( Quantum.Station.Get( stationid ) == nil ) then
Quantum.Error( "The station id is not valid! (" .. tostring( #Quantum.Server.Stations.Locations + 1 ) .. ")" )
end
Quantum.Debug( "Registering station '" .. tostring( stationid ) .. "' (" .. tostring(#Quantum.Server.Stations.Locations + 1) .. ")" )
Quantum.Server.Stations.Locations[#Quantum.Server.Stations.Locations + 1] = {
id = stationid, id = stationid,
pos = vec, pos = vec,
ang = angle ang = angle
} }
print(Stations.Locations[#Stations.Locations])
end end
function Quantum.Server.Station.Create( id, tbl ) function Quantum.Server.Station.Create( id, tbl )
@ -74,8 +75,7 @@ if SERVER then
end end
function Quantum.Server.Station.SpawnAllRegistered() function Quantum.Server.Station.SpawnAllRegistered()
for i, station in pairs( Stations.Locations ) do for i, station in pairs( Quantum.Server.Stations.Locations ) do
print("spawning")
Quantum.Server.Station.Create( station.id, { pos = station.pos, ang = station.ang } ) Quantum.Server.Station.Create( station.id, { pos = station.pos, ang = station.ang } )
end end
end end
@ -93,15 +93,11 @@ if SERVER then
end end
function Quantum.Server.Station.UpdateAll() function Quantum.Server.Station.UpdateAll()
--Quantum.Server.Station.RemoveAll() -- remove all stations on lua refresh Quantum.Debug( "Updating station locations..." )
Quantum.Server.Station.RemoveAll() -- remove all stations on lua refresh
Quantum.Server.Station.SpawnAllRegistered() -- and create new ones Quantum.Server.Station.SpawnAllRegistered() -- and create new ones
end end
print("##############")
PrintTable( Stations.Locations )
print("##############")
hook.Add( "PlayerInitialSpawn", "Quantum_Init_Stations_Load", function() hook.Add( "PlayerInitialSpawn", "Quantum_Init_Stations_Load", function()
Quantum.Debug( "Spawning registered crafting stations..." ) Quantum.Debug( "Spawning registered crafting stations..." )
@ -116,8 +112,10 @@ if SERVER then
if( key == IN_USE ) then if( key == IN_USE ) then
local ent = pl:GetEyeTraceNoCursor().Entity local ent = pl:GetEyeTraceNoCursor().Entity
if( ent:GetClass() == "q_crafting_station" ) then if( ent:GetClass() == "q_crafting_station" ) then
pl:SetLocalVelocity( Vector( 0, 0, 0 ) ) if( ent:GetPos():Distance( pl:GetPos() ) <= 100 ) then
Quantum.Net.OpenMenu( pl, "crafting", { stationEnt = ent, station = ent.stationid } ) pl:SetLocalVelocity( Vector( 0, 0, 0 ) )
Quantum.Net.OpenMenu( pl, "crafting", { stationEnt = ent, station = ent.stationid } )
end
end end
end end
end end

@ -120,6 +120,8 @@ if SERVER then
include( "settings/sh_crafting_stations.lua" ) include( "settings/sh_crafting_stations.lua" )
include( "settings/sh_recipes.lua" ) include( "settings/sh_recipes.lua" )
include( "settings/sv_crafting_stations_locations.lua" ) include( "settings/sv_crafting_stations_locations.lua" )
Quantum.Server.Station.UpdateAll()
end end
local function loadPlugins() local function loadPlugins()

@ -6,3 +6,4 @@
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
Quantum.Server.Station.Register( "barrel", Vector( 747.13494873047, 10483.685546875, 7168.0317382813 ), Angle( 0, -118.23150634766, 0 ) ) Quantum.Server.Station.Register( "barrel", Vector( 747.13494873047, 10483.685546875, 7168.0317382813 ), Angle( 0, -118.23150634766, 0 ) )
Quantum.Server.Station.Register( "barrel", Vector( 885.861328125, 10542.946289063, 7168.03125 ), Angle( 0, -118.23150634766, 0 ) )

@ -113,8 +113,7 @@ Quantum.Server.Settings.IdlePainSounds.Female = {
--- Features to be added --- --- Features to be added ---
Quantum.Server.Settings.MaxJobLevel = 250 Quantum.Server.Settings.MaxJobLevel = 250
Quantum.Server.Settings.MaxJobSlots = Vector( 12418.626953125, 9959.9345703125, 320.03125 ) Quantum.Server.Settings.MaxJobSlots = 2
Angle( 65.102394104004, -2.1179277896881, 0 )
Quantum.Server.Settings.MaxSkillLevel = 100 Quantum.Server.Settings.MaxSkillLevel = 100

Loading…
Cancel
Save