Refactor, Beatify and EndRound hook fix

master
David Vogel 6 years ago
parent 0877e8a03d
commit 777ffcacbd

@ -1,4 +1,4 @@
if (SERVER) then
if SERVER then
include("d3stats/init.lua")
else
include("d3stats/cl_init.lua")

@ -1,28 +1,28 @@
-- Delete HUD and redo if already existent. This will reset the displayed values until the next update from the server
if d3stats.D3StatsOverlay then
d3stats.D3StatsOverlay:Remove()
d3stats.Overlay_Init()
if D3stats.D3statsOverlay then
D3stats.D3statsOverlay:Remove()
D3stats.Overlay_Init()
end
-- HUD on the left top of the screen
function d3stats.Overlay_Init()
d3stats.D3StatsOverlay = vgui.Create( "D3StatsOverlay" )
d3stats.D3StatsOverlay:SetPos( d3stats.Overlay_X, d3stats.Overlay_Y )
d3stats.D3StatsOverlay:SetSize( 350, 100 )
function D3stats.Overlay_Init()
D3stats.D3statsOverlay = vgui.Create("D3statsOverlay")
D3stats.D3statsOverlay:SetPos(D3stats.Overlay_X, D3stats.Overlay_Y)
D3stats.D3statsOverlay:SetSize(350, 100)
end
-- Call this function from cl_targetid.lua in the gamemode. Works for ZS, needs adjustments for other gamemodes.
local colTemp = Color(255, 255, 255)
function d3stats.DrawTargetID( ent, fade, x, y )
function D3stats.DrawTargetID(ent, fade, x, y)
colTemp.a = fade * 255
--util.ColorCopy(COLOR_FRIENDLY, colTemp)
local Level = ent:GetNWInt( "D3Stats_Level", 0 )
if Level > 0 and d3stats.Levels[Level] then
draw.SimpleTextBlur("Level " .. tostring(Level) .. " \"" .. d3stats.Levels[Level].Name .. "\"", d3stats.Font_TargetID, x, y, colTemp, TEXT_ALIGN_CENTER)
y = y + draw.GetFontHeight(d3stats.Font_TargetID) + 4
local Level = ent:GetNWInt("D3stats_Level", 0)
if Level > 0 and D3stats.Levels[Level] then
draw.SimpleTextBlur("Level " .. tostring(Level) .. " \"" .. D3stats.Levels[Level].Name .. "\"", D3stats.Font_TargetID, x, y, colTemp, TEXT_ALIGN_CENTER)
y = y + draw.GetFontHeight(D3stats.Font_TargetID) + 4
end
return x, y
end
end

@ -1,16 +1,16 @@
d3stats = d3stats or {}
D3stats = D3stats or {}
-- Includes
include( "sh_settings.lua" )
include( "sh_level.lua" )
include( "sh_concommand.lua" )
include("sh_settings.lua")
include("sh_level.lua")
include("sh_concommand.lua")
include( "cl_network.lua" )
include( "cl_hud.lua" )
include("cl_network.lua")
include("cl_hud.lua")
include( "vgui/overlay.lua" )
include("vgui/overlay.lua")
-- Initialisation
hook.Add( "Initialize", "D3Stats_Init", function ()
d3stats.Overlay_Init()
end )
-- Initialization
hook.Add("Initialize", "D3stats_Init", function ()
D3stats.Overlay_Init()
end)

@ -1,9 +1,9 @@
net.Receive( "D3Stats_UpdateXP", function()
local XP = net.ReadUInt( 32 )
net.Receive("D3stats_UpdateXP", function()
local XP = net.ReadUInt(32)
--print( "XP update: " .. tostring(XP))
--print("XP update: " .. tostring(XP))
if d3stats and d3stats.D3StatsOverlay then
d3stats.D3StatsOverlay:StatsUpdate( XP, d3stats.CalculateLevel( XP ) )
if D3stats and D3stats.D3statsOverlay then
D3stats.D3statsOverlay:StatsUpdate(XP, D3stats.CalculateLevel(XP))
end
end )
end)

@ -5,50 +5,58 @@ Any "zombie survival" gamemode specific code goes in here
]]
-- XP rewards for players getting points
hook.Add( "PlayerPointsAdded", "D3Stats_ZS_PlayerPointsAdded", function ( ply, points )
if points <= d3stats.PlayerPointsAdded_Limit then
ply:D3Stats_AddXP( points )
hook.Add("PlayerPointsAdded", "D3stats_ZS_PlayerPointsAdded", function (ply, points)
if points <= D3stats.PlayerPointsAdded_Limit then
ply:D3stats_AddXP(points)
end
end )
end)
-- XP rewards for zombies killing humans
hook.Add( "PostZombieKilledHuman", "D3Stats_ZS_PostZombieKilledHuman", function ( ply, attacker, dmginfo, headshot, wassuicide )
local reward = d3stats.ZombieKilledHuman_Static + d3stats.ZombieKilledHuman_Fraction * ply:Frags()
hook.Add("PostZombieKilledHuman", "D3stats_ZS_PostZombieKilledHuman", function (ply, attacker, dmginfo, headshot, wassuicide)
local reward = D3stats.ZombieKilledHuman_Static + D3stats.ZombieKilledHuman_Fraction * ply:Frags()
reward = math.Clamp( reward, d3stats.ZombieKilledHuman_Min, d3stats.ZombieKilledHuman_Max )
reward = math.Clamp(reward, D3stats.ZombieKilledHuman_Min, D3stats.ZombieKilledHuman_Max)
attacker:D3Stats_AddXP( reward )
end )
attacker:D3stats_AddXP(reward)
end)
-- Message on levelchange
hook.Add( "D3Stats_LevelChanged", "D3Stats_ZS_LevelChanged", function ( ply, oldLevel, Level )
hook.Add("D3stats_LevelChanged", "D3stats_ZS_LevelChanged", function (ply, oldLevel, Level)
if Level > oldLevel then
ply:CenterNotify( Color( 0, 255, 255 ), string.format( d3stats.Message.Level_Ascended, Level, d3stats.Levels[Level].Name ) )
ply:CenterNotify(Color(0, 255, 255), string.format(D3stats.Message.Level_Ascended, Level, D3stats.Levels[Level].Name))
else
ply:CenterNotify( Color( 0, 255, 255 ), string.format( d3stats.Message.Level_Changed, Level, d3stats.Levels[Level].Name ) )
ply:CenterNotify(Color(0, 255, 255), string.format(D3stats.Message.Level_Changed, Level, D3stats.Levels[Level].Name))
end
end )
end)
-- Handle "Use_Hammer" permission. TODO: Only prevent that the person can nail things
hook.Add( "PlayerSwitchWeapon", "D3Stats_ZS_EquipHammer", function( ply, oldWeapon, newWeapon )
hook.Add("PlayerSwitchWeapon", "D3stats_ZS_EquipHammer", function(ply, oldWeapon, newWeapon)
local Class = newWeapon:GetClass()
if Class == "weapon_zs_hammer" or Class == "weapon_zs_electrohammer" then
if not ply:D3Stats_HasPermission( "Use_Hammer" ) then
ply:CenterNotify( Color( 255, 0, 0 ), string.format( d3stats.Message.Disallow_Hold_Hammer, d3stats.GetPermissionLevel( "Use_Hammer" ) ) )
if not ply:D3stats_HasPermission("Use_Hammer") then
ply:CenterNotify(Color(255, 0, 0), string.format(D3stats.Message.Disallow_Hold_Hammer, D3stats.GetPermissionLevel("Use_Hammer")))
return true
end
end
end )
end)
-- Handle EndRound events for statistics
hook.Add( "EndRound", "D3Stats_ZS_EndRound", function( team )
local won = ( TEAM_SURVIVORS == team ) and true or false
hook.Add("EndRound", "D3stats_ZS_EndRound", function(team)
if D3stats.RoundEnded then return end
D3stats.RoundEnded = true
d3stats.Map_End( won )
end )
-- Display map statistic message when the player joined
hook.Add( "PlayerReady", "D3Stats_Map_PlayerReady", function ( ply )
d3stats.Map_Message( false, ply )
end )
local won = (TEAM_SURVIVORS == team) and true or false
D3stats.Map_End(won)
end)
-- Reset stuff on a new game
hook.Add("DoRestartGame", "D3stats_ZS_DoRestartGame", function()
D3stats.RoundEnded = nil
end)
-- Display map statistics message when a player joins
hook.Add("PlayerReady", "D3stats_Map_PlayerReady", function (ply)
D3stats.Map_Message(false, ply)
end)

@ -5,49 +5,49 @@ by David Vogel (Dadido3)
]]
d3stats = d3stats or {}
D3stats = D3stats or {}
AddCSLuaFile( "sh_settings.lua" )
AddCSLuaFile( "sh_level.lua" )
AddCSLuaFile( "sh_concommand.lua" )
AddCSLuaFile("sh_settings.lua")
AddCSLuaFile("sh_level.lua")
AddCSLuaFile("sh_concommand.lua")
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "cl_network.lua" )
AddCSLuaFile( "cl_hud.lua" )
AddCSLuaFile( "vgui/overlay.lua" )
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("cl_network.lua")
AddCSLuaFile("cl_hud.lua")
AddCSLuaFile("vgui/overlay.lua")
include( "sh_settings.lua" )
include( "sh_level.lua" )
include( "sh_concommand.lua" )
include("sh_settings.lua")
include("sh_level.lua")
include("sh_concommand.lua")
include( "gamemodes/sv_zombiesurvival.lua" )
include( "sv_storage.lua" )
include( "sv_map.lua" )
include( "sv_network.lua" )
include("gamemodes/sv_zombiesurvival.lua")
include("sv_storage.lua")
include("sv_map.lua")
include("sv_network.lua")
hook.Add( "PlayerInitialSpawn", "D3Stats_PlayerSpawn", function ( ply )
hook.Add("PlayerInitialSpawn", "D3stats_PlayerSpawn", function (ply)
-- Send its own XP
ply:D3Stats_Net_UpdateXP()
ply:D3stats_Net_UpdateXP()
-- Store level as network and local player variable
ply.D3Stats_Level = d3stats.CalculateLevel( ply:D3Stats_GetXP() )
ply:SetNWInt( "D3Stats_Level", ply.D3Stats_Level )
end )
ply.D3stats_Level = D3stats.CalculateLevel(ply:D3stats_GetXP())
ply:SetNWInt("D3stats_Level", ply.D3stats_Level)
end)
-- Initialisation
hook.Add( "Initialize", "D3Stats_Init", function ()
d3stats.Storage.Initialize()
hook.Add("Initialize", "D3stats_Init", function ()
D3stats.Storage.Initialize()
resource.AddFile("resource/fonts/ghoulfriaoe.ttf")
resource.AddFile("resource/fonts/hauntaoe.ttf")
resource.AddFile("resource/fonts/nightaoe.ttf")
end )
end)
local meta = FindMetaTable( "Player" )
local meta = FindMetaTable("Player")
if not meta then return end
function meta:D3Stats_GetXP()
local XP = tonumber( self:GetPData( "D3Stats_XP", "0" ) )
function meta:D3stats_GetXP()
local XP = tonumber(self:GetPData("D3stats_XP", "0"))
if not XP then
XP = 0
@ -56,43 +56,43 @@ function meta:D3Stats_GetXP()
return XP
end
function meta:D3Stats_SetXP( XP )
function meta:D3stats_SetXP(XP)
if not XP then
XP = 0
end
self:SetPData( "D3Stats_XP", tostring( XP ) )
self:SetPData("D3stats_XP", tostring(XP))
self:D3Stats_Net_UpdateXP()
self:D3stats_Net_UpdateXP()
-- Update network variable and send message on level change
local Level = d3stats.CalculateLevel( XP )
if self.D3Stats_Level and self.D3Stats_Level ~= Level then
self:SetNWInt( "D3Stats_Level", Level )
hook.Call( "D3Stats_LevelChanged" , nil, self, self.D3Stats_Level, Level )
local Level = D3stats.CalculateLevel(XP)
if self.D3stats_Level and self.D3stats_Level ~= Level then
self:SetNWInt("D3stats_Level", Level)
hook.Call("D3stats_LevelChanged" , nil, self, self.D3stats_Level, Level)
end
self.D3Stats_Level = Level
self.D3stats_Level = Level
end
function meta:D3Stats_AddXP( XP )
function meta:D3stats_AddXP(XP)
if not XP then
XP = 0
end
self:D3Stats_SetXP( self:D3Stats_GetXP() + XP )
self:D3stats_SetXP(self:D3stats_GetXP() + XP)
end
function meta:D3Stats_GetLevel()
return self.D3Stats_Level
function meta:D3stats_GetLevel()
return self.D3stats_Level
end
-- Check if the players level has the permission
function meta:D3Stats_HasPermission( Permission )
function meta:D3stats_HasPermission(Permission)
-- If there are too few players with this permission, allow it
if d3stats.Permissions[Permission] and d3stats.Permissions[Permission].AllowIfLessThan and d3stats.Permissions[Permission].AllowIfLessThan > d3stats.CountPermissionPlayers( Permission, d3stats.Permissions[Permission].Team ) then
-- If there are too few players with this permission, allow it anyway
if D3stats.Permissions[Permission] and D3stats.Permissions[Permission].AllowIfLessThan and D3stats.Permissions[Permission].AllowIfLessThan > D3stats.CountPermissionPlayers(Permission, D3stats.Permissions[Permission].Team) then
return true
end
return d3stats.LevelCheckPermission( self:D3Stats_GetLevel(), Permission )
return D3stats.LevelCheckPermission(self:D3stats_GetLevel(), Permission)
end

@ -1,7 +1,7 @@
if SERVER then
concommand.Add( "d3stats_clearall", function( ply, cmd, args )
print( "What the hell are you doing?" )
end )
concommand.Add("D3stats_clearall", function(ply, cmd, args, argsString)
print("What the hell are you doing? Not implemented yet!")
end)
end

@ -1,8 +1,8 @@
-- Calculate the level from the given XP
function d3stats.CalculateLevel( XP )
function D3stats.CalculateLevel(XP)
local Level = 1
for key, value in pairs( d3stats.Levels ) do
for key, value in pairs(D3stats.Levels) do
if value.XP_needed <= XP then
Level = key
else
@ -14,15 +14,15 @@ function d3stats.CalculateLevel( XP )
end
-- Check if the level has the given permission
function d3stats.LevelCheckPermission( Level, Permission )
function D3stats.LevelCheckPermission(Level, Permission)
local Granted = false
-- If the permission is not on the list, allow it
if not d3stats.Permissions[Permission] then
if not D3stats.Permissions[Permission] then
return true
end
for key, value in pairs( d3stats.Levels ) do
for key, value in pairs(D3stats.Levels) do
if key <= Level then
if value.Permissions and value.Permissions[Permission] then
Granted = value.Permissions[Permission]
@ -36,14 +36,14 @@ function d3stats.LevelCheckPermission( Level, Permission )
end
-- Returns what level is needed for the given permission
function d3stats.GetPermissionLevel( Permission )
function D3stats.GetPermissionLevel(Permission)
local Level
if not d3stats.Permissions[Permission] then
if not D3stats.Permissions[Permission] then
return 1
end
for key, value in pairs( d3stats.Levels ) do
for key, value in pairs(D3stats.Levels) do
if value.Permissions and value.Permissions[Permission] then
return key
end
@ -54,13 +54,13 @@ end
-- Count the amount of online players who have the permission
if SERVER then
function d3stats.CountPermissionPlayers( Permission, Team )
function D3stats.CountPermissionPlayers(Permission, Team)
local Counter = 0
local players = player.GetAll()
for key, ply in pairs( players ) do
for key, ply in pairs(players) do
if Team == nil or ply:Team() == Team then
if d3stats.LevelCheckPermission( ply:D3Stats_GetLevel(), Permission ) == true then
if D3stats.LevelCheckPermission(ply:D3stats_GetLevel(), Permission) == true then
Counter = Counter + 1
end
end

@ -7,14 +7,14 @@ Settings and level definitions are stored in here
-- Permissions
-- - Everything not in this list will be allowed by default
-- - AllowIfLessThan: If the amount of players who have the permission is lower than this number, allow it anyway
-- - Team: Reduces count to the specified team. In ZS: TEAM_SURVIVOR = 4,
d3stats.Permissions = {
--["Buy_Hammer"] = { AllowIfLessThan = 4, Team = 4 },
--["Use_Hammer"] = { AllowIfLessThan = 4, Team = 4 },
-- - Team: AllowIfLessThan only counts the specified team. In ZS: TEAM_SURVIVOR = 4,
D3stats.Permissions = {
--["Buy_Hammer"] = {AllowIfLessThan = 4, Team = 4},
--["Use_Hammer"] = {AllowIfLessThan = 4, Team = 4},
}
-- Levels, please sort by XP
d3stats.Levels = {
D3stats.Levels = {
{ XP_needed = 500, Name = "Kleiner" },
{ XP_needed = 1370, Name = "Survivor" },
{ XP_needed = 2612, Name = "Helper" },
@ -50,30 +50,30 @@ d3stats.Levels = {
}
-- Human reward settings
d3stats.PlayerPointsAdded_Limit = 200 -- Ignore all "PlayerPointsAdded" callbacks above this XP value
D3stats.PlayerPointsAdded_Limit = 200 -- Ignore all "PlayerPointsAdded" callbacks above this XP value
-- Zombie reward is calculated as follows: Reward = math.clamp( Static + Fraction * Human_Points, Min, Max )
d3stats.ZombieKilledHuman_Fraction = 1.0 -- Amount of XP a zombie gets of the killed humans points
d3stats.ZombieKilledHuman_Static = 100 -- Amount of XP a zombie gets for killing a human
d3stats.ZombieKilledHuman_Max = 1000 -- Upper XP reward clamp
d3stats.ZombieKilledHuman_Min = 0 -- Lower XP reward clamp
-- Zombie reward is calculated as follows: Reward = math.clamp(Static + Fraction * Human_Points, Min, Max)
D3stats.ZombieKilledHuman_Fraction = 1.0 -- Amount of XP a zombie gets of the killed humans points
D3stats.ZombieKilledHuman_Static = 100 -- Amount of XP a zombie gets for killing a human
D3stats.ZombieKilledHuman_Max = 1000 -- Upper XP reward clamp
D3stats.ZombieKilledHuman_Min = 0 -- Lower XP reward clamp
-- Messages TODO: Multilanguage
d3stats.Message = {}
d3stats.Message.Level_Ascended = "You ascended to level %i \"%s\""
d3stats.Message.Level_Changed = "Your level changed to level %i \"%s\""
d3stats.Message.Disallow_Hold_Hammer = "You can't use the hammer until you have reached level %i"
d3stats.Message.MapStats_Zero = "We are playing %s." -- Message to players who just joined
d3stats.Message.MapStats = "We are playing %s. Humans won %i of %i times (%.1f%%)" -- Message to players who just joined (With statistics)
d3stats.Message.MapStats_End = "%s has been won %i of %i times (%.1f%%)" -- Message to all players at the end of the round (With statistics)
D3stats.Message = {}
D3stats.Message.Level_Ascended = "You ascended to level %i \"%s\""
D3stats.Message.Level_Changed = "Your level changed to level %i \"%s\""
D3stats.Message.Disallow_Hold_Hammer = "You can't use the hammer until you have reached level %i"
D3stats.Message.MapStats_Zero = "We are playing %s." -- Message to players who just joined
D3stats.Message.MapStats = "We are playing %s. Humans won %i of %i times (%.1f%%)" -- Message to players who just joined (With statistics)
D3stats.Message.MapStats_End = "%s has been won %i of %i times (%.1f%%)" -- Message to all players at the end of the round (With statistics)
if CLIENT then
-- Overlay positions
d3stats.Overlay_X = 0
d3stats.Overlay_Y = 80 * math.Clamp(ScrH() / 1080, 0.6, 1) -- This needs to be redone
D3stats.Overlay_X = 0
D3stats.Overlay_Y = 80 * math.Clamp(ScrH() / 1080, 0.6, 1) -- This needs to be redone
-- Fonts
surface.CreateFont( "D3Stats_OverlayFont_XP", {
surface.CreateFont("D3stats_OverlayFont_XP", {
font = "Ghoulish Fright AOE",
extended = false,
size = 22,
@ -89,8 +89,8 @@ if CLIENT then
shadow = false,
additive = false,
outline = false,
} )
surface.CreateFont( "D3Stats_OverlayFont_Level", {
})
surface.CreateFont("D3stats_OverlayFont_Level", {
font = "Haunt AOE",
extended = false,
size = 26,
@ -106,9 +106,9 @@ if CLIENT then
shadow = false,
additive = false,
outline = true,
} )
})
d3stats.Font_Overlay_XP = "D3Stats_OverlayFont_XP"
d3stats.Font_Overlay_Level = "D3Stats_OverlayFont_Level"
d3stats.Font_TargetID = "ZSHUDFontTiny" -- Use ZS Font
D3stats.Font_Overlay_XP = "D3stats_OverlayFont_XP"
D3stats.Font_Overlay_Level = "D3stats_OverlayFont_Level"
D3stats.Font_TargetID = "ZSHUDFontTiny" -- Use ZS Font
end

@ -1,35 +1,35 @@
function d3stats.Map_Message( roundend, ply )
function D3stats.Map_Message(roundend, ply)
local map = game.GetMap()
local count, wins, avg_players = d3stats.Storage.Map_Get( map )
local count, wins, avg_players = D3stats.Storage.Map_Get(map)
local Message
if count > 0 then
if roundend == true then
Message = string.format( d3stats.Message.MapStats_End, map, wins, count, wins / count * 100 )
Message = string.format(D3stats.Message.MapStats_End, map, wins, count, wins / count * 100)
else
Message = string.format( d3stats.Message.MapStats, map, wins, count, wins / count * 100 )
Message = string.format(D3stats.Message.MapStats, map, wins, count, wins / count * 100)
end
else
Message = string.format( d3stats.Message.MapStats_Zero, map )
Message = string.format(D3stats.Message.MapStats_Zero, map)
end
if ply then
ply:ChatPrint( Message )
ply:ChatPrint(Message)
else
PrintMessage( HUD_PRINTTALK, Message )
PrintMessage(HUD_PRINTTALK, Message)
end
end
function d3stats.Map_End( won )
function D3stats.Map_End(won)
local map = game.GetMap()
local players = #player.GetAll()
if players > 0 then
d3stats.Storage.Map_AddOutcome( map, won, players )
d3stats.Map_Message( true )
D3stats.Storage.Map_AddOutcome(map, won, players)
D3stats.Map_Message(true)
end
end
--d3stats.Map_End( false )
--D3stats.Map_End(false)
--d3stats.Map_Message( false, player.GetByID(1) )
--D3stats.Map_Message(false, player.GetByID(1))

@ -1,11 +1,11 @@
util.AddNetworkString( "D3Stats_UpdateXP" )
util.AddNetworkString("D3stats_UpdateXP")
local meta = FindMetaTable( "Player" )
local meta = FindMetaTable("Player")
if not meta then return end
-- Send the XP of this (self) player to itself
function meta:D3Stats_Net_UpdateXP()
net.Start( "D3Stats_UpdateXP" )
net.WriteUInt( self:D3Stats_GetXP(), 32 )
net.Send( self )
function meta:D3stats_Net_UpdateXP()
net.Start("D3stats_UpdateXP")
net.WriteUInt(self:D3stats_GetXP(), 32)
net.Send(self)
end

@ -4,46 +4,46 @@ Storage stuff
]]
d3stats.Storage = {}
D3stats.Storage = {}
function d3stats.Storage.Initialize()
function D3stats.Storage.Initialize()
-- Storage for map data
if not sql.TableExists( "d3stats_maps") then
local result = sql.Query( "CREATE TABLE d3stats_maps ( name varchar(255) PRIMARY KEY, count INT, wins INT, avg_players REAL )" )
if not sql.TableExists("D3stats_maps") then
local result = sql.Query("CREATE TABLE D3stats_maps (name varchar(255) PRIMARY KEY, count INT, wins INT, avg_players REAL)")
end
end
function d3stats.Storage.Map_AddOutcome( name, won, players )
function D3stats.Storage.Map_AddOutcome(name, won, players)
local count = 1
local wins = 0
local avg_players = players
if won == true then wins = 1 end
local result = sql.QueryRow( "SELECT count, wins, avg_players FROM d3stats_maps WHERE name = '" .. name .. "'" )
local result = sql.QueryRow("SELECT count, wins, avg_players FROM D3stats_maps WHERE name = '" .. name .. "'")
if result then
if result ~= false then
count = count + tonumber( result.count )
wins = tonumber( result.wins ) + 1 * ( won and 1 or 0 )
avg_players = ( players + tonumber( result.avg_players ) ) / 2
count = count + tonumber(result.count)
wins = tonumber(result.wins) + 1 * (won and 1 or 0)
avg_players = (players + tonumber(result.avg_players)) / 2
else
Print(sql.LastError())
end
end
local result = sql.Query( "INSERT OR REPLACE INTO d3stats_maps ( name, count, wins, avg_players ) VALUES ( '" .. name .. "', " .. tostring(count) .. ", " .. tostring(wins) .. ", " .. tostring(avg_players) .. " );" )
local result = sql.Query("INSERT OR REPLACE INTO D3stats_maps (name, count, wins, avg_players) VALUES ('" .. name .. "', " .. tostring(count) .. ", " .. tostring(wins) .. ", " .. tostring(avg_players) .. ");")
end
function d3stats.Storage.Map_Get( name )
function D3stats.Storage.Map_Get(name)
local count = 0
local wins = 0
local avg_players = 0
local result = sql.QueryRow( "SELECT count, wins, avg_players FROM d3stats_maps WHERE name = '" .. name .. "'" )
local result = sql.QueryRow("SELECT count, wins, avg_players FROM D3stats_maps WHERE name = '" .. name .. "'")
if result then
if result ~= false then
count = tonumber( result.count )
wins = tonumber( result.wins )
avg_players = tonumber( result.avg_players )
count = tonumber(result.count)
wins = tonumber(result.wins)
avg_players = tonumber(result.avg_players)
else
Print(sql.LastError())
end

@ -1,62 +1,59 @@
local PANEL = {}
function PANEL:Init()
self.Progress = vgui.Create( "DProgress", self )
self.Progress:SetPos( 10, 10 )
self.Progress:SetSize( 200, 20 )
self.Label_XP = vgui.Create( "DLabel", self )
self.Label_XP:SetTextColor( color_black )
self.Label_XP:SetFont( d3stats.Font_Overlay_XP )
self.Label_XP:SetSize( 200, 20 )
self.Label_XP:SetPos( 10, 10 ) -- Set the position of the label
self.Label_XP:SetContentAlignment( 5 )
self.Label_Level = vgui.Create( "DLabel", self )
self.Label_Level:SetFont( d3stats.Font_Overlay_Level )
self.Label_Level:SetPos( 10, 35 ) -- Set the position of the label
self.Label_Level:SetSize( 200, 20 )
self.Label_Level:SetContentAlignment( 5 )
self:StatsUpdate( 0, 1 )
--self.Label:SetDark( 1 ) -- Set the colour of the text inside the label to a darker one
--timer.Create( "D3StatsOverlay_Timer", 0.1, 0, function() self.Progress:SetFraction( math.random() ) end )
self.Progress = vgui.Create("DProgress", self)
self.Progress:SetPos(10, 10)
self.Progress:SetSize(200, 20)
self.Label_XP = vgui.Create("DLabel", self)
self.Label_XP:SetTextColor(color_black)
self.Label_XP:SetFont(D3stats.Font_Overlay_XP)
self.Label_XP:SetSize(200, 20)
self.Label_XP:SetPos(10, 10) -- Set the position of the label
self.Label_XP:SetContentAlignment(5)
self.Label_Level = vgui.Create("DLabel", self)
self.Label_Level:SetFont(D3stats.Font_Overlay_Level)
self.Label_Level:SetPos(10, 35) -- Set the position of the label
self.Label_Level:SetSize(200, 20)
self.Label_Level:SetContentAlignment(5)
self:StatsUpdate(0, 1)
--self.Label:SetDark(1) -- Set the colour of the text inside the label to a darker one
--timer.Create("D3statsOverlay_Timer", 0.1, 0, function() self.Progress:SetFraction(math.random()) end)
end
function PANEL:Paint( aWide, aTall )
function PANEL:Paint(aWide, aTall)
-- Nothing for now
end
function PANEL:StatsUpdate( XP, Level )
function PANEL:StatsUpdate(XP, Level)
local Text_XP
local Text_Level
local Fraction
if d3stats.Levels[Level+1] then
Text_XP = "XP: " .. tostring( XP ) .. " / " .. d3stats.Levels[Level+1].XP_needed
Fraction = ( XP - d3stats.Levels[Level].XP_needed ) / ( d3stats.Levels[Level+1].XP_needed - d3stats.Levels[Level].XP_needed )
if D3stats.Levels[Level+1] then
Text_XP = "XP: " .. tostring(XP) .. " / " .. D3stats.Levels[Level+1].XP_needed
Fraction = (XP - D3stats.Levels[Level].XP_needed) / (D3stats.Levels[Level+1].XP_needed - D3stats.Levels[Level].XP_needed)
else
Text_XP = "XP: " .. tostring( XP )
Text_XP = "XP: " .. tostring(XP)
Fraction = 1
end
Text_Level = "Level: " .. tostring( Level ) .. " \"" .. d3stats.Levels[Level].Name .. "\""
Text_Level = "Level: " .. tostring(Level) .. " \"" .. D3stats.Levels[Level].Name .. "\""
self.Label_XP:SetText( Text_XP ) -- Set the text of the label
self.Label_XP:SetText(Text_XP) -- Set the text of the label
--self.Label_XP:SizeToContents() -- Size the label to fit the text in it
self.Label_Level:SetText( Text_Level ) -- Set the text of the label
self.Label_Level:SetText(Text_Level) -- Set the text of the label
--self.Label_Level:SizeToContents() -- Size the label to fit the text in it
self.Progress:SetFraction( Fraction )
self.Progress:SetFraction(Fraction)
end
function PANEL:SetText( aText ) self.Text = tostring( aText ) end
function PANEL:SetText(aText) self.Text = tostring(aText) end
function PANEL:GetText() return self.Text or "" end
vgui.Register( "D3StatsOverlay", PANEL, "DPanel" )
vgui.Register("D3statsOverlay", PANEL, "DPanel")
Loading…
Cancel
Save