You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1KB

  1. --
  2. -- Minetest minibank (sub)mod - A very simple economy mod alternative
  3. --
  4. -- © 2019 by luk3yx
  5. --
  6. local storage = minetest.get_mod_storage()
  7. -- Use mod storage for getbal() and setbal().
  8. -- Store as strings because of weird bugs when using floats.
  9. local function rawgetbal(name)
  10. return tonumber(storage:get_string('minibank-' .. name))
  11. end
  12. local setbal
  13. local function getbal(name)
  14. local lname = name:lower()
  15. if lname ~= name and rawgetbal(name) ~= nil then
  16. setbal(lname, rawgetbal(name) + (rawgetbal(lname) or 0))
  17. storage:set_string('minibank-' .. name, '')
  18. end
  19. return rawgetbal(lname)
  20. end
  21. function setbal(name, balance)
  22. storage:set_string('minibank-' .. name:lower(),
  23. tostring(math.floor(balance * 100) / 100))
  24. end
  25. -- Create an empty account for new players
  26. minetest.register_on_joinplayer(function(player)
  27. if lurkcoin.bank.mod ~= 'lurkcoin' then return end
  28. local name = player:get_player_name()
  29. if not lurkcoin.bank.user_exists(name) then
  30. setbal(name, 0)
  31. end
  32. end)
  33. -- Let bank.lua add everything else.
  34. lurkcoin.change_bank({
  35. getbal = getbal,
  36. setbal = setbal
  37. })