Guest User

Untitled

a guest
Oct 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. -- flags by lauscript
  2.  
  3. Radlands.Flags = { }
  4. Radlands.Flags.Registered = { }
  5.  
  6. function Radlands.Flags:New( flagname, flagdescription, flagkey )
  7.     if ( !flagname or !flagdescription or !flagkey ) then return end
  8.    
  9.     self.Registered[ flagkey ] = { Name = flagname, Description = flagdescription }
  10. end
  11.  
  12. function Radlands.Flags:Get( key )
  13.     if ( key and self.Registered[ key ] ) then
  14.         return self.Registered[ key ]
  15.     end
  16. end
  17.  
  18. function Radlands.Flags:GetName( key )
  19.     if ( !key ) then return end
  20.    
  21.     local info = self:Get( key );
  22.     return info["Name"]
  23. end
  24.  
  25. function Radlands.Flags:GetDescription( key )
  26.     if ( !key ) then return end
  27.    
  28.     local info = self:Get( key );
  29.     return info["Description"]
  30. end
  31.  
  32. function Radlands.Flags:Exists( key )
  33.     if ( !key ) then return end
  34.    
  35.     if ( self.Registered[ key ] ) then
  36.         return true
  37.     else
  38.         return false
  39.     end
  40. end
  41.  
  42. function Radlands.Flags:Unpack( player )
  43.     if ( player:GetPData("Flags") ) then
  44.         local info = glon.decode( player:GetPData("Flags") )
  45.         return info
  46.     end
  47. end
  48.  
  49. function Radlands.Flags:Pack( player, newtable )
  50.     if ( newtable ) then
  51.         local info = glon.encode( newtable )
  52.         player:SetPData("Flags", info );
  53.     end
  54. end
  55.  
  56. function Radlands.Flags:Give( player, key )
  57.     if ( !key or !self:Exists( key ) ) then return end
  58.    
  59.     if ( player:GetPData("Flags") ) then
  60.         local flags = self:Unpack( player );
  61.         if ( !flags[ key ] ) then
  62.             table.insert( flags, key )
  63.             self:Pack( player, flags );
  64.         end
  65.     else
  66.         local flags = { }
  67.         table.insert( flags, key )
  68.         self:Pack( player, flags );
  69.     end
  70. end
  71.  
  72. function Radlands.Flags:HasFlag( player, key )
  73.     if ( !key ) then return end
  74.    
  75.     local flags = self:Unpack( player );
  76.    
  77.     if ( flags ) then
  78.    
  79.         if ( table.HasValue( flags, key ) ) then
  80.             return true
  81.         else
  82.             return false
  83.         end
  84.     else
  85.         return false
  86.     end
  87. end
  88.  
  89. Radlands.Flags:New( "Tooltrust", "Gives access to the toolgun.", "T")
  90. Radlands.Flags:New( "Phystrust", "Gives access to the physgun.", "P")
Add Comment
Please, Sign In to add comment