Skip to content

Commit

Permalink
Added ability to modify pdata of offline players.
Browse files Browse the repository at this point in the history
Lets you easily grab the pdata by steamid instead of needing to have a
playerobject.
  • Loading branch information
Donkie committed Dec 1, 2013
1 parent 37aba35 commit 828ddc1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions garrysmod/lua/includes/extensions/util.lua
Expand Up @@ -305,4 +305,45 @@ function util.Stack()
t.objs = {}
return t
end
--Helper for the following functions.
local function GetUniqueID( sid )
return util.CRC( "gm_"..sid.."_gm" )
end
--[[---------------------------------------------------------
Name: GetPData( steamid, name, default )
Desc: Gets the persistant data from a player by steamid
-----------------------------------------------------------]]
function util.GetPData( steamid, name, default )
name = Format( "%s[%s]", GetUniqueID( steamid ), name )
local val = sql.QueryValue( "SELECT value FROM playerpdata WHERE infoid = " .. SQLStr(name) .. " LIMIT 1" )
if ( val == nil ) then return default end
return val
end
--[[---------------------------------------------------------
Name: SetPData( steamid, name, value )
Desc: Sets the persistant data of a player by steamid
-----------------------------------------------------------]]
function util.SetPData( steamid, name, value )
name = Format( "%s[%s]", GetUniqueID( steamid ), name )
sql.Query( "REPLACE INTO playerpdata ( infoid, value ) VALUES ( "..SQLStr(name)..", "..SQLStr(value).." )" )
end
--[[---------------------------------------------------------
Name: RemovePData( steamid, name )
Desc: Removes the persistant data from a player by steamid
-----------------------------------------------------------]]
function util.RemovePData( steamid, name )
name = Format( "%s[%s]", GetUniqueID( steamid ), name )
sql.Query( "DELETE FROM playerpdata WHERE infoid = "..SQLStr(name) )
end

0 comments on commit 828ddc1

Please sign in to comment.