Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. _G.GetUser = {
  2.     users = {},
  3.     users_group = {},
  4.     userSource = {},
  5.     userData = {},
  6.     phoneSource = {},
  7.     CurrentCharacter = {}
  8. }
  9.  
  10. _G.GetUserMethods = {}
  11.  
  12. GetUserMethods.__call = function(self, source)
  13.     local o = setmetatable({}, {
  14.         __index = self
  15.     })
  16.  
  17.     o.src = source
  18.  
  19.     o.id = self.users[o.src]
  20.  
  21.     o.rank = self.users_group[o.src]
  22.  
  23.     o.identifier = GetPlayerIdentifiers(o.src)[1]
  24.  
  25.     return o
  26. end
  27.  
  28. GetUserMethods.__index = {
  29.     getCurrentCharacter = function(self)
  30.         self.character = {}
  31.  
  32.         self.character.id = self.CurrentCharacter[self.id]
  33.  
  34.         local shared_bank
  35.         local data_mt = {
  36.              __index =
  37.                     function(t, k)
  38.                          if k == "bank" then
  39.                                 return shared_bank
  40.                          end
  41.                     end,
  42.              __newindex =
  43.                     function(t, k, v)
  44.                          if k == "bank" then
  45.                                 shared_bank = v
  46.                          else
  47.                                 rawset(t, k, v)
  48.                          end
  49.                     end,
  50.         }
  51.         self.character.data = function()
  52.              local d = self.userData[self.character.id]
  53.              if d and getmetatable(d) ~= data_mt then
  54.                     d.bank = nil
  55.                     setmetatable(d, data_mt)
  56.              end
  57.              return d
  58.         end
  59.    
  60.         self.character.getCash = function()
  61.             if self.character.data() then
  62.                 return self.character.data().cash
  63.             end
  64.            
  65.             return nil
  66.         end
  67.        
  68.         self.character.giveCash = function(value)
  69.             if self.character.data() then
  70.               self.character.data().cash = self.character.data().cash + value
  71.             end
  72.         end
  73.        
  74.         self.character.giveBank = function(value)
  75.             if self.character.data() then
  76.               self.character.data().bank = self.character.data().bank + value
  77.             end
  78.         end
  79.        
  80.         self.character.getBank = function()
  81.             if self.character.data() then
  82.               return self.character.data().bank
  83.             end
  84.        
  85.             return 0
  86.         end
  87.        
  88.         self.character.tryPayment = function(type,amount)
  89.             if type == "cash" then
  90.               if self.character.data().cash >= amount then
  91.                     self.character.data().cash = self.character.data().cash - amount
  92.  
  93.                     return true
  94.               else
  95.                     return false
  96.               end
  97.             elseif type == "bank" then
  98.               if self.character.data().bank >= amount then
  99.                     self.character.data().bank = self.character.data().bank - amount
  100.  
  101.                     return true
  102.               else
  103.                     return false
  104.               end
  105.             end
  106.         end
  107.        
  108.         self.character.getHunger = function()
  109.             if self.character.data() then
  110.               return self.character.data().hunger
  111.             end
  112.  
  113.             return 0
  114.         end
  115.        
  116.         self.character.getThirst = function()
  117.             if self.character.data() then
  118.               return self.character.data().thirst
  119.             end
  120.  
  121.             return 0
  122.         end
  123.        
  124.         self.character.getStress = function()
  125.             if self.character.data() then
  126.               return self.character.data().stress
  127.             end
  128.  
  129.             return 0
  130.         end
  131.        
  132.         self.character.addStress = function(value)
  133.             if self.character.data() then
  134.               self.character.data().stress = self.character.data().stress + value
  135.        
  136.               if self.character.data().stress <= 0 then
  137.                     self.character.data().stress = 0
  138.               elseif self.character.data().stress >= 100 then
  139.                     self.character.data().stress = 100
  140.               end
  141.             end
  142.         end
  143.        
  144.         self.character.addThirst = function(value)
  145.             if self.character.data() then
  146.               self.character.data().thirst = self.character.data().thirst + value
  147.        
  148.               if self.character.data().thirst <= 0 then
  149.                     self.character.data().thirst = 0
  150.               elseif self.character.data().thirst >= 100 then
  151.                     self.character.data().thirst = 100
  152.               end
  153.             end
  154.         end
  155.        
  156.         self.character.addHunger = function(value)
  157.             if self.character.data() then
  158.               self.character.data().hunger = self.character.data().hunger + value
  159.        
  160.               if self.character.data().hunger <= 0 then
  161.                     self.character.data().hunger = 0
  162.               elseif self.character.data().hunger >= 100 then
  163.                     self.character.data().hunger = 100
  164.               end
  165.             end
  166.         end
  167.  
  168.         return self.character
  169.     end
  170. }
  171.  
  172. setmetatable(GetUser, GetUserMethods)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement