Permalink
Browse files

Added ability to modify pdata of offline players.

Lets you easily grab the pdata by steamid instead of needing to have a
playerobject.
1 parent 37aba35 commit 828ddc1b5c5b5ccd6448a419ae7a1c2421a6e427 @Donkie Donkie committed Dec 1, 2013
Showing with 41 additions and 0 deletions.
  1. +41 −0 garrysmod/lua/includes/extensions/util.lua
@@ -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.