Fixed stations not spawning & reworked stations config system

master
AlmTech Software 5 years ago
parent 4347d45c56
commit ada8e98d4f
  1. 28
      gamemode/engine/lib/sh_station.lua
  2. 23
      gamemode/init.lua
  3. 5
      gamemode/settings/sv_crafting_stations_locations.lua

@ -33,6 +33,7 @@ end
if SERVER then
Quantum.Server.Station = {}
Quantum.Server.StationsPos = {}
function Quantum.Server.Station.Spawn( stationid, pos, ang ) -- internal function
local ent = ents.Create( "q_crafting_station" )
@ -46,6 +47,14 @@ if SERVER then
return tostring(math.floor( vec.x )) .. ", " .. tostring(math.floor( vec.y )) .. ", " .. tostring(math.floor( vec.z ))
end
function Quantum.Server.Station.Register( stationid, vec, angle )
Quantum.Server.StationsPos[#Quantum.Server.StationsPos + 1] = {
id = stationid,
pos = vec,
ang = angle
}
end
function Quantum.Server.Station.Create( id, tbl )
local stationTbl = Quantum.Station.Get( id )
@ -54,6 +63,12 @@ if SERVER then
end
end
function Quantum.Server.Station.SpawnAllRegistered()
for i, station in pairs( Quantum.Server.StationsPos ) do
Quantum.Server.Station.Create( station.id, { pos = station.pos, ang = station.ang } )
end
end
function Quantum.Server.Station.Remove( station )
if( IsValid( station ) ) then
station:Remove()
@ -68,6 +83,19 @@ if SERVER then
Quantum.Server.Station.RemoveAll() -- remove all stations on lua refresh
if( Quantum.Server.StationsSpawned ) then
Quantum.Server.Station.SpawnAllRegistered() -- and create new ones
end
hook.Add( "PlayerInitialSpawn", "Quantum_Init_Stations_Load", function()
Quantum.Debug( "Spawning registered crafting stations..." )
if( #player.GetAll() == 1 ) then -- spawn the stations when the first player joins
Quantum.Server.Station.SpawnAllRegistered()
Quantum.Server.StationsSpawned = true
end
end)
hook.Add( "KeyRelease", "Quantum_Station_KeyRelease", function( pl, key )
if( pl.isloaded ) then
if( key == IN_USE ) then

@ -119,6 +119,7 @@ if SERVER then
include( "settings/sh_effects.lua" )
include( "settings/sh_crafting_stations.lua" )
include( "settings/sh_recipes.lua" )
include( "settings/sv_crafting_stations_locations.lua" )
end
local function loadPlugins()
@ -156,29 +157,7 @@ if SERVER then
end
local function loadStations( luaRefresh )
print( luaRefresh, Quantum.Server.Loaded, Quantum.Server.LoadedStations )
local basepath = "gamemodes/" .. folname .. "/gamemode/settings/"
print( basepath )
if( !luaRefresh ) then
include( basepath .. "sv_crafting_stations_locations.lua" )
elseif( luaRefresh && Quantum.Server.Loaded && Quantum.Server.LoadedStations ) then
include( basepath .. "sv_crafting_stations_locations.lua" )
end
end
hook.Add( "PlayerInitialSpawn", "Quantum_Init_Stations_Load", function()
Quantum.Debug( "Spawning crafting stations..." )
if( #player.GetAll() == 1 ) then -- spawn the stations when the first player joins
loadStations()
Quantum.Server.LoadedStations = true
end
end)
Quantum.Server.Load()
loadStations( true )
MsgC( "\n" )
end

@ -5,7 +5,4 @@
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
Quantum.Server.Station.Create( "barrel", {
pos = Vector( 747.13494873047, 10483.685546875, 7168.0317382813 ),
ang = Angle( 0, -118.23150634766, 0 )
})
Quantum.Server.Station.Register( "barrel", Vector( 747.13494873047, 10483.685546875, 7168.0317382813 ), Angle( 0, -118.23150634766, 0 ) )
Loading…
Cancel
Save