I'm trying to code weapon rights that can be given to a player in game, curently I have this:
player.lua:
[CODE]
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
[/CODE]
rights.lua:
[CODE]
--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)
[/CODE]
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!??!?!
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.
[url]http://wiki.garrysmod.com/?title=Sql[/url]
I think that PData just uses the premade databases within the garrysmod folder, but it is sql.
[QUOTE=Lyeol;20311851]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.
[url]http://wiki.garrysmod.com/?title=Sql[/url][/QUOTE]
It's simply a premade failsafe sql query. The source is here :
[url]http://luabin.foszor.com/code/lua/includes/extensions/player.lua#145[/url]
Sorry, you need to Log In to post a reply to this thread.