Character system bug fix

master
AlmTech 5 years ago
parent c4c4546805
commit 60a7f4bd41
  1. 14
      gamemode/engine/lib/server/sv_character.lua

@ -12,7 +12,7 @@ local function CreateCharTable( args )
return { return {
name = args.name || "UNKNOWN", name = args.name || "UNKNOWN",
maxhealth = Quantum.Server.Settings.MaxHealth, maxhealth = Quantum.Server.Settings.MaxHealth,
health = math.Clamp( args.health, 0, Quantum.Server.Settings.MaxHealth ) || Quantum.Server.Settings.MaxHealth, health = args.health || Quantum.Server.Settings.MaxHealth,
model = args.model || "models/player.mdl", model = args.model || "models/player.mdl",
money = args.money || Quantum.Server.Settings.StarterMoney, money = args.money || Quantum.Server.Settings.StarterMoney,
inventory = args.inventory || {}, -- create new inventory later inventory = args.inventory || {}, -- create new inventory later
@ -32,8 +32,8 @@ local function CreateCharTable( args )
end end
function Quantum.Server.Char.Load( pl, index, tbl ) function Quantum.Server.Char.Load( pl, index, tbl )
local id = pl:SteamID() .. ":" .. index local id = pl:SteamID() .. ";" .. index
if( Quantum.Server.Char.Players[ id ] ~= nil ) then if( Quantum.Server.Char.Players[ id ] == nil ) then
Quantum.Server.Char.Players[ id ] = CreateCharTable( tbl ) -- create the character Quantum.Server.Char.Players[ id ] = CreateCharTable( tbl ) -- create the character
Quantum.Server.Char.Players[ id ].inventory = tbl.inventory || Quantum.Server.Inventory.Create( Quantum.Server.Char.Players[ id ] ) -- give the character an inventory Quantum.Server.Char.Players[ id ].inventory = tbl.inventory || Quantum.Server.Inventory.Create( Quantum.Server.Char.Players[ id ] ) -- give the character an inventory
@ -73,4 +73,12 @@ function Quantum.Server.Char.SetCurrentCharacter( pl, index )
Quantum.Error( "Unable to set " .. tostring(pl) .. " character. Character not found!" ) Quantum.Error( "Unable to set " .. tostring(pl) .. " character. Character not found!" )
return nil return nil
end end
end
function Quantum.Server.Char.GetPlayerChars( pl )
local chars = {}
for id, char in pairs( Quantum.Server.Char.Players ) do
chars[id] = char
end
return chars
end end
Loading…
Cancel
Save