Skip to content

Commit

Permalink
add SetPlayerSteamIDLevel and AddPlayerSteamIDLevels
Browse files Browse the repository at this point in the history
  • Loading branch information
GlorifiedPig committed Dec 20, 2020
1 parent 8de7d2c commit 4652c38
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/autorun/sh_glorifiedleveling_autoincluder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GlorifiedLeveling = GlorifiedLeveling or {
Perks = {
Enum = {}
},
Version = "2.2.2"
Version = "2.2.3"
}

print( "[GlorifiedLeveling] This server is running version " .. GlorifiedLeveling.Version .. "." )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ local function ValidationChecks( ply, level )
or not ply:IsConnected() )
end

local function ValidationChecksSteamID( steamID, level )
level = tonumber( level )
return not ( GlorifiedLeveling.LockdownEnabled
or not level
or level < 0
or not isstring( steamID ) )
end

local function PerkValidationChecks( ply, perkTbl )
return not ( GlorifiedLeveling.LockdownEnabled
or not perkTbl
Expand Down Expand Up @@ -47,6 +55,16 @@ function GlorifiedLeveling.SetPlayerLevel( ply, level )
ply:SetNWInt( "GlorifiedLeveling.Level", level )
end

function GlorifiedLeveling.SetPlayerSteamIDLevel( steamID, level )
if not ValidationChecksSteamID( steamID, level ) then return end
local ply = player.GetBySteamID64( steamID )
if ply then GlorifiedLeveling.SetPlayerLevel( ply, level ) end
level = tonumber( level )
level = math.Round( level )
level = math.Clamp( level, 1, GlorifiedLeveling.Config.MAX_LEVEL )
GlorifiedLeveling.SQL.Query( "UPDATE `gl_players` SET `Level` = '" .. level .. "' WHERE `SteamID64` = '" .. steamID .. "'" )
end

function GlorifiedLeveling.GetPlayerLevel( ply )
return tonumber( ply:GlorifiedLeveling().Level ) or 1
end
Expand Down Expand Up @@ -83,6 +101,16 @@ function GlorifiedLeveling.AddPlayerLevels( ply, levels )
GlorifiedLeveling.SetPlayerXP( ply, 0 )
end

function GlorifiedLeveling.AddPlayerSteamIDLevels( steamID, levels )
if not ValidationChecksSteamID( steamID, levels ) then return end
local ply = player.GetBySteamID64( steamID )
if ply then GlorifiedLeveling.AddPlayerLevels( ply, levels ) end
levels = tonumber( levels )
levels = math.Round( levels )
levels = math.Clamp( levels, 1, GlorifiedLeveling.Config.MAX_LEVEL )
GlorifiedLeveling.SQL.Query( "UPDATE `gl_players` SET `Level` = `Level` + '" .. levels .. "' WHERE `SteamID64` = '" .. steamID .. "'" )
end

function GlorifiedLeveling.AddPlayerXP( ply, xp, ignoreMultiplier, showNotification, notificationOverride, carriedOver )
if not ValidationChecks( ply, xp ) then return end
if not ignoreMultiplier then xp = xp * ( GlorifiedLeveling.Config.MULTIPLIER_AMOUNT_CUSTOMFUNC( ply ) or 1 ) end
Expand Down

0 comments on commit 4652c38

Please sign in to comment.