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!??!?!