Player Data Saving?

I’m trying to code weapon rights that can be given to a player in game, curently I have this:

player.lua:



local meta = FindMetaTable("Player")

function meta:GiveRights()
   self:SetPData("swep_rights", 1)
   self:SendHint( "You have been given rights!",5)
end

function meta:RemoveRights()
   self:SetPData("swep_rights", 0)
   self:SendHint( "You have lost your weapon rights!",5)
end

function meta:HasWeaponRights()
   if self:GetPData("swep_rights") == 0 then
      return false
   else
      return true
   end
end


rights.lua:



--Weapon spawning rights

function FirstSpawn( ply )
	if (ply:GetPData("swep_rights") == nil or ply:GetPData("swep_rights") == "") then
      ply:SetPData("swep_rights", "0")
   end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )

function GM:PlayerSpawnSWEP( ply, class, wep )
   if (ply:HasWeaponRights() == true) then
         return true
   else
         return false
   end
end


function cmd_revoke(ply,command,args)
   local pl = player.GetByID(args[1])
   pl:RemoveRights()
end

function cmd_give(ply,command,args)
   local pl = player.GetByID(args[1])
   pl:GiveRights()
end

function cmd_ban(ply,command,args)
   local pl = player.GetByID(args[1])
   pl:SwepBan()
end

function cmd_unban(ply,command,args)
   local pl = player.GetByID(args[1])
   pl:SwepUnban()
end

concommand.Add("urp_removeRights",cmd_revoke)
concommand.Add("urp_giveRights",cmd_give)
concommand.Add("urp_swepban",cmd_ban)
concommand.Add("urp_swepunban",cmd_unban)


But my code always fails when using: SetPData
It keeps saying it is nil.

I call the console commands using rcon, but they still don’t work.
Any help?


Anyone know how to get this working?

If not, another way of doing this!??!?!

player:SetPData(val)

Is serverside. You’re running it clientside.

I run this from my console,

Also, do I replace my self:SetPData with player:SetPData?

Could you give me my code back with the fixes?

Alright, I’ve been seeing multiple topics about PData lately, is there really a difference between actual Sql coding like the following link, or is it the same with a more basic structure.

I think that PData just uses the premade databases within the garrysmod folder, but it is sql.

It’s simply a premade failsafe sql query. The source is here :
http://luabin.foszor.com/code/lua/includes/extensions/player.lua#145