From 2d25c23b1e14512d212212510b19b4ffb4c0246f Mon Sep 17 00:00:00 2001 From: AlmTech Date: Wed, 30 Oct 2019 21:47:30 +0100 Subject: [PATCH] Bug fixes --- .../engine/core/server/sv_player_spawning.lua | 36 +++++++++++-------- .../engine/derma/menus/menu_character.lua | 36 ++++++++++--------- gamemode/engine/lib/server/sv_networking.lua | 3 +- gamemode/settings/sh_settings.lua | 2 ++ gamemode/settings/sv_settings.lua | 2 -- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/gamemode/engine/core/server/sv_player_spawning.lua b/gamemode/engine/core/server/sv_player_spawning.lua index 79d6228..0ccebbf 100644 --- a/gamemode/engine/core/server/sv_player_spawning.lua +++ b/gamemode/engine/core/server/sv_player_spawning.lua @@ -9,27 +9,33 @@ hook.Add( "PlayerDeath", "Quantum_Player_SaveDeathPos", function( pl ) pl.deathpos = pl:GetPos() end) -hook.Add( "PlayerSpawn", "Quantum_Player_Respawn", function( pl ) - if( pl.isloaded && pl.deathpos ) then - local spawnposdist = {} - for id, spawnpoint in pairs( Quantum.Server.Settings.SpawnLocations[ game.GetMap() ] ) do - spawnposdist[id] = { dist = spawnpoint.pos:Distance( pl.deathpos ), spawnpos = spawnpoint.pos, angle = spawnpoint.ang } - end +local function getNearestSpawn( pl ) + local spawnposdist = {} + for id, spawnpoint in pairs( Quantum.Server.Settings.SpawnLocations[ game.GetMap() ] ) do + spawnposdist[id] = { dist = spawnpoint.pos:Distance( pl.deathpos ), spawnpos = spawnpoint.pos, angle = spawnpoint.ang } + end - local maxdist, spawnpos, spawnangle - for id, spawn in pairs( spawnposdist ) do -- Loop through everything and pick the nearest spawnpoint - if( maxdist ~= nil ) then - if( maxdist >= spawn.dist ) then - maxdist = spawn.dist - spawnpos = spawn.spawnpos - spawnangle = spawn.angle - end - else + local maxdist, spawnpos, spawnangle + for id, spawn in pairs( spawnposdist ) do -- Loop through everything and pick the nearest spawnpoint + if( maxdist ~= nil ) then + if( maxdist >= spawn.dist ) then maxdist = spawn.dist spawnpos = spawn.spawnpos spawnangle = spawn.angle end + else + maxdist = spawn.dist + spawnpos = spawn.spawnpos + spawnangle = spawn.angle end + end + return spawnpos, spawnangle +end + +hook.Add( "PlayerSpawn", "Quantum_Player_Respawn", function( pl ) + if( pl.isloaded && pl.deathpos ) then + + local spawnpos, spawnangle = getNearestSpawn( pl ) Quantum.Debug( "Respawning player at nearest spawnpoint." ) pl:SetPos( spawnpos ) diff --git a/gamemode/engine/derma/menus/menu_character.lua b/gamemode/engine/derma/menus/menu_character.lua index 6fa89a1..afbeb68 100644 --- a/gamemode/engine/derma/menus/menu_character.lua +++ b/gamemode/engine/derma/menus/menu_character.lua @@ -466,24 +466,26 @@ function menu.open( dt ) p.mdl:SetLookAt( eyepos ) end - -- create char button - local cr = vgui.Create( "DButton", p ) - cr:SetText("Create New Character") - cr:SetFont( "q_button" ) - cr:SetTextColor( Color( 0, 0, 0, 255 ) ) - cr:SizeToContents() - cr.w, cr.h = cr:GetSize() - cr:SetPos( clist.x + ( clist.w/2 - cr.w/2 ), clist.y + ( ( clist.h - cr.h ) - padding*2 ) ) - cr.Paint = function( self ) - theme.sharpbutton( self ) - end - cr.DoClick = function() - surface.PlaySound( "UI/buttonclick.wav" ) - p:SetVisible( false ) - local crPage = pages.charCreate( f ) + if( table.Count( dt.cont ) < Quantum.CharacterLimit ) then + -- create char button + local cr = vgui.Create( "DButton", p ) + cr:SetText("Create New Character") + cr:SetFont( "q_button" ) + cr:SetTextColor( Color( 0, 0, 0, 255 ) ) + cr:SizeToContents() + cr.w, cr.h = cr:GetSize() + cr:SetPos( clist.x + ( clist.w/2 - cr.w/2 ), clist.y + ( ( clist.h - cr.h ) - padding*2 ) ) + cr.Paint = function( self ) + theme.sharpbutton( self ) + end + cr.DoClick = function() + surface.PlaySound( "UI/buttonclick.wav" ) + p:SetVisible( false ) + local crPage = pages.charCreate( f ) + end + + cr.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end end - - cr.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end if( selectedChar ) then -- Delete char button diff --git a/gamemode/engine/lib/server/sv_networking.lua b/gamemode/engine/lib/server/sv_networking.lua index c9c3923..5588dde 100644 --- a/gamemode/engine/lib/server/sv_networking.lua +++ b/gamemode/engine/lib/server/sv_networking.lua @@ -64,11 +64,10 @@ local netfuncs = { if( #args.name > 16 ) then Quantum.Debug( "Player " .. tostring( pl ) .. " character name too long. Unable to create." ) return - elseif( pl.charcount + 1 > Quantum.Server.Settings.CharacterLimit ) then -- character limit + elseif( pl.charcount + 1 > Quantum.CharacterLimit ) then -- character limit Quantum.Debug( "Player " .. tostring( pl ) .. " tried to exceed their character limit." ) return end - print(pl.charcount + 1) Quantum.Server.Char.Load( pl, pl.charcount + 1, args ) end, enterWorldChar = function( pl, args ) diff --git a/gamemode/settings/sh_settings.lua b/gamemode/settings/sh_settings.lua index 04a67a9..7e21ff4 100644 --- a/gamemode/settings/sh_settings.lua +++ b/gamemode/settings/sh_settings.lua @@ -5,6 +5,8 @@ -- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ +Quantum.CharacterLimit = 5 + Quantum.Models = { NPC = {}, Player = { diff --git a/gamemode/settings/sv_settings.lua b/gamemode/settings/sv_settings.lua index 3cf3442..30bd68f 100644 --- a/gamemode/settings/sv_settings.lua +++ b/gamemode/settings/sv_settings.lua @@ -7,8 +7,6 @@ Quantum.Server.Settings = {} -Quantum.Server.Settings.CharacterLimit = 5 - Quantum.Server.Settings.VoiceChatRange = 400 Quantum.Server.Settings.MaxHealth = 100