Advertisement
Guest User

sh

a guest
Mar 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1.  
  2. local ENTITY = FindMetaTable("Entity")
  3.  
  4. function ENTITY:isBank()
  5. return (self:GetClass() == "npc_teller")
  6. end
  7. function SCHEMA:CanUseBank(client, atmEntity)
  8. return true
  9. end
  10.  
  11. local CHAR = nut.meta.character
  12.  
  13. function CHAR:getReserve()
  14. return self:getVar("reserve", 0)
  15. end
  16.  
  17. function CHAR:setReserve(amt)
  18. self:setVar("reserve", amt)
  19. hook.Run("OnReserveChanged", self, amt, true)
  20. end
  21.  
  22. function CHAR:addReserve(amt)
  23. nut.log.add(self:getPlayer(), "reserve", amt)
  24. self:setVar("reserve", self:getReserve() + amt)
  25. hook.Run("OnReserveChanged", self, amt)
  26. end
  27.  
  28. function CHAR:takeReserve(amt)
  29. nut.log.add(self:getPlayer(), "reserve", -amt)
  30. self:setVar("reserve", self:getReserve() - amt)
  31. hook.Run("OnReserveChanged", self, amt)
  32. end
  33.  
  34. function CHAR:hasReserve(amt)
  35. return (amt > 0 and self:getReserve() >= amt)
  36. end
  37. nut.command.add("bankdeposit", {
  38. syntax = "<amount>",
  39. onRun = function(client, arguments)
  40. local atmEntity
  41. for k, v in ipairs(ents.FindInSphere(client:GetPos(), 500)) do
  42. if (v:isBank()) then
  43. atmEntity = v
  44. break
  45. end
  46. end
  47.  
  48. if (IsValid(atmEntity) and hook.Run("CanUseBank", client, atmEntity)) then
  49. local amount = tonumber(table.concat(arguments, ""))
  50. local char = client:getChar()
  51.  
  52. if (amount and amount > 0 and char) then
  53. amount = math.Round(amount)
  54. if (char:hasMoney(amount)) then
  55. char:addReserve(amount)
  56. char:takeMoney(amount)
  57. client:notify(L("You have deposited cash into the bank!", client, nut.currency.get(amount)))
  58. else
  59. client:notify(L("You don't have enough funds.", client))
  60. end
  61. else
  62. client:notify(L("Nyet", client))
  63. end
  64. else
  65. client:notify(L("You are too far from the teller", client))
  66. end
  67. end,
  68. })
  69.  
  70. nut.command.add("bankwithdraw", {
  71. syntax = "<amount>",
  72. onRun = function(client, arguments)
  73. local atmEntity
  74. for k, v in ipairs(ents.FindInSphere(client:GetPos(), 500)) do
  75. if (v:isBank()) then
  76. atmEntity = v
  77. break
  78. end
  79. end
  80.  
  81. if (IsValid(atmEntity) and hook.Run("CanUseBank", client, atmEntity)) then
  82. local amount = tonumber(table.concat(arguments, ""))
  83. local char = client:getChar()
  84.  
  85. if (amount and isnumber(amount) and amount > 0 and char) then
  86. amount = math.Round(tonumber(amount))
  87.  
  88. if (char:hasReserve(amount)) then
  89. char:takeReserve(amount)
  90. char:giveMoney(amount)
  91. client:notify(L("You have withdrawn cash from the bank!", client, nut.currency.get(amount)))
  92. else
  93. client:notify(L("You don't have enough funds.", client))
  94. end
  95. else
  96. client:notify(L("Nyet", client))
  97. end
  98. else
  99. client:notify(L("You are too far from the teller", client))
  100. end
  101. end,
  102. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement