Fixed some character stuff

master
AlmTech 5 years ago
parent 307a872108
commit 0255287dd8
  1. 30
      gamemode/engine/lib/server/sv_character.lua
  2. 2
      gamemode/settings/sv_settings.lua

@ -8,12 +8,14 @@
Quantum.Server.Char = {} Quantum.Server.Char = {}
Quantum.Server.Char.Players = {} Quantum.Server.Char.Players = {}
function Quantum.Server.Char.CreateCharTable( args ) local function CreateCharTable( args )
return { return {
name = args.name || "UNKNOWN", name = args.name || "UNKNOWN",
maxhealth = Quantum.Server.Settings.MaxHealth,
health = math.Clamp( args.health, 0, Quantum.Server.Settings.MaxHealth ) || 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 inventory = args.inventory || {}, -- create new inventory later
jobs = args.jobs || { jobs = args.jobs || {
[1] = { title = "Hobo", level = -1 }, [1] = { title = "Hobo", level = -1 },
}, },
@ -29,10 +31,12 @@ function Quantum.Server.Char.CreateCharTable( args )
} }
end end
function Quantum.Server.Char.Create( 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 ] = tbl Quantum.Server.Char.Players[ id ] = CreateCharTable( tbl ) -- create the character
Quantum.Server.Inventory.Create( Quantum.Server.Char.Players[ id ] ) -- give the character a inventory
Quantum.Debug( "Created character (" .. id .. ")" ) Quantum.Debug( "Created character (" .. id .. ")" )
else else
Quantum.Error( "Tried to duplicate character! Index already used. (" .. id .. ")" ) Quantum.Error( "Tried to duplicate character! Index already used. (" .. id .. ")" )
@ -50,4 +54,22 @@ end
function Quantum.Server.Char.GetCurrentCharacter( pl ) function Quantum.Server.Char.GetCurrentCharacter( pl )
if( pl.character == nil ) then Quantum.Error( tostring( pl ) .. " doesn't have a character! Unable to get current character table." ) end if( pl.character == nil ) then Quantum.Error( tostring( pl ) .. " doesn't have a character! Unable to get current character table." ) end
return pl.character return pl.character
end
local function setupCharacter( pl, char )
pl:SetMaxHealth( char.maxhealth )
pl:SetHealth( char.health )
pl:SetModel( char.model )
end
function Quantum.Server.Char.SetCurrentCharacter( pl, index )
local id = pl:SteamID() .. ":" .. index
if( Quantum.Server.Char.Players[ id ] ) then
pl.character = Quantum.Server.Char.Players[ id ]
setupCharacter( pl, pl.character )
return pl.character
else
Quantum.Error( "Unable to set " .. tostring(pl) .. " character. Character not found!" )
return nil
end
end end

@ -9,6 +9,8 @@
Quantum.Server.Settings.VoiceChatRange = 400 Quantum.Server.Settings.VoiceChatRange = 400
Quantum.Server.Settings.MaxHealth = 100
Quantum.Server.Settings.StarterMoney = 0 Quantum.Server.Settings.StarterMoney = 0
Quantum.Server.Settings.Inventory = { Quantum.Server.Settings.Inventory = {

Loading…
Cancel
Save