Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ENTITY = FindMetaTable("Entity")
- function ENTITY:isBank()
- return (self:GetClass() == "npc_teller")
- end
- function SCHEMA:CanUseBank(client, atmEntity)
- return true
- end
- local CHAR = nut.meta.character
- function CHAR:getReserve()
- return self:getVar("reserve", 0)
- end
- function CHAR:setReserve(amt)
- self:setVar("reserve", amt)
- hook.Run("OnReserveChanged", self, amt, true)
- end
- function CHAR:addReserve(amt)
- nut.log.add(self:getPlayer(), "reserve", amt)
- self:setVar("reserve", self:getReserve() + amt)
- hook.Run("OnReserveChanged", self, amt)
- end
- function CHAR:takeReserve(amt)
- nut.log.add(self:getPlayer(), "reserve", -amt)
- self:setVar("reserve", self:getReserve() - amt)
- hook.Run("OnReserveChanged", self, amt)
- end
- function CHAR:hasReserve(amt)
- return (amt > 0 and self:getReserve() >= amt)
- end
- nut.command.add("bankdeposit", {
- syntax = "<amount>",
- onRun = function(client, arguments)
- local atmEntity
- for k, v in ipairs(ents.FindInSphere(client:GetPos(), 500)) do
- if (v:isBank()) then
- atmEntity = v
- break
- end
- end
- if (IsValid(atmEntity) and hook.Run("CanUseBank", client, atmEntity)) then
- local amount = tonumber(table.concat(arguments, ""))
- local char = client:getChar()
- if (amount and amount > 0 and char) then
- amount = math.Round(amount)
- if (char:hasMoney(amount)) then
- char:addReserve(amount)
- char:takeMoney(amount)
- client:notify(L("You have deposited cash into the bank!", client, nut.currency.get(amount)))
- else
- client:notify(L("You don't have enough funds.", client))
- end
- else
- client:notify(L("Nyet", client))
- end
- else
- client:notify(L("You are too far from the teller", client))
- end
- end,
- })
- nut.command.add("bankwithdraw", {
- syntax = "<amount>",
- onRun = function(client, arguments)
- local atmEntity
- for k, v in ipairs(ents.FindInSphere(client:GetPos(), 500)) do
- if (v:isBank()) then
- atmEntity = v
- break
- end
- end
- if (IsValid(atmEntity) and hook.Run("CanUseBank", client, atmEntity)) then
- local amount = tonumber(table.concat(arguments, ""))
- local char = client:getChar()
- if (amount and isnumber(amount) and amount > 0 and char) then
- amount = math.Round(tonumber(amount))
- if (char:hasReserve(amount)) then
- char:takeReserve(amount)
- char:giveMoney(amount)
- client:notify(L("You have withdrawn cash from the bank!", client, nut.currency.get(amount)))
- else
- client:notify(L("You don't have enough funds.", client))
- end
- else
- client:notify(L("Nyet", client))
- end
- else
- client:notify(L("You are too far from the teller", client))
- end
- end,
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement