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 if SERVER then
Quantum.Server.Station = {} Quantum.Server.Station = {}
Quantum.Server.StationsPos = {}
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" )
@ -45,6 +46,14 @@ if SERVER then
local function floorVectorString( vec ) local function floorVectorString( vec )
return tostring(math.floor( vec.x )) .. ", " .. tostring(math.floor( vec.y )) .. ", " .. tostring(math.floor( vec.z )) return tostring(math.floor( vec.x )) .. ", " .. tostring(math.floor( vec.y )) .. ", " .. tostring(math.floor( vec.z ))
end 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 ) function Quantum.Server.Station.Create( id, tbl )
local stationTbl = Quantum.Station.Get( id ) local stationTbl = Quantum.Station.Get( id )
@ -54,6 +63,12 @@ if SERVER then
end end
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 ) function Quantum.Server.Station.Remove( station )
if( IsValid( station ) ) then if( IsValid( station ) ) then
station:Remove() station:Remove()
@ -68,6 +83,19 @@ if SERVER then
Quantum.Server.Station.RemoveAll() -- remove all stations on lua refresh 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 ) hook.Add( "KeyRelease", "Quantum_Station_KeyRelease", function( pl, key )
if( pl.isloaded ) then if( pl.isloaded ) then
if( key == IN_USE ) then if( key == IN_USE ) then

@ -119,6 +119,7 @@ if SERVER then
include( "settings/sh_effects.lua" ) include( "settings/sh_effects.lua" )
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" )
end end
local function loadPlugins() local function loadPlugins()
@ -155,30 +156,8 @@ if SERVER then
Quantum.Server.Loaded = true Quantum.Server.Loaded = true
end 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() Quantum.Server.Load()
loadStations( true )
MsgC( "\n" ) MsgC( "\n" )
end end

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