From ada8e98d4f734c8a1f99c0888386971e92b2d227 Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Sat, 25 Jan 2020 02:03:10 +0100 Subject: [PATCH] Fixed stations not spawning & reworked stations config system --- gamemode/engine/lib/sh_station.lua | 28 +++++++++++++++++++ gamemode/init.lua | 23 +-------------- .../sv_crafting_stations_locations.lua | 5 +--- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/gamemode/engine/lib/sh_station.lua b/gamemode/engine/lib/sh_station.lua index 169485c..8b76e53 100644 --- a/gamemode/engine/lib/sh_station.lua +++ b/gamemode/engine/lib/sh_station.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" ) @@ -45,6 +46,14 @@ if SERVER then local function floorVectorString( vec ) 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 diff --git a/gamemode/init.lua b/gamemode/init.lua index 84a6d14..9691a19 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -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() @@ -155,30 +156,8 @@ if SERVER then Quantum.Server.Loaded = true 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 diff --git a/gamemode/settings/sv_crafting_stations_locations.lua b/gamemode/settings/sv_crafting_stations_locations.lua index 5560d48..cccbb1b 100644 --- a/gamemode/settings/sv_crafting_stations_locations.lua +++ b/gamemode/settings/sv_crafting_stations_locations.lua @@ -5,7 +5,4 @@ -- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ -Quantum.Server.Station.Create( "barrel", { - pos = Vector( 747.13494873047, 10483.685546875, 7168.0317382813 ), - ang = Angle( 0, -118.23150634766, 0 ) -}) \ No newline at end of file +Quantum.Server.Station.Register( "barrel", Vector( 747.13494873047, 10483.685546875, 7168.0317382813 ), Angle( 0, -118.23150634766, 0 ) ) \ No newline at end of file