A Minetest trading mod by crabman, under the original idea of Cyberpangolin.
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.

222 lines
7.4KB

  1. local coins_convert = {
  2. ["minercantile:copper_coin"]=1, ["minercantile:silver_coin"]=100, ["minercantile:gold_coin"]=10000,
  3. ["maptools:copper_coin"]=1, ["maptools:silver_coin"]=100, ["maptools:gold_coin"]=10000,
  4. }
  5. --if maptools then use maptools coins else use minercantile coins
  6. if minetest.get_modpath("maptools") ~= nil then
  7. minetest.override_item("maptools:copper_coin", {
  8. inventory_image = "minercantile_copper_coin.png",
  9. })
  10. minetest.override_item("maptools:silver_coin", {
  11. inventory_image = "minercantile_silver_coin.png",
  12. })
  13. minetest.override_item("maptools:gold_coin", {
  14. inventory_image = "minercantile_gold_coin.png",
  15. })
  16. else
  17. minetest.register_craftitem("minercantile:copper_coin", {
  18. description = "Copper Coin",
  19. inventory_image = "minercantile_copper_coin.png",
  20. wield_scale = {x = 0.5, y = 0.5, z = 0.25},
  21. stack_max = 10000,
  22. groups = {not_in_creative_inventory = 0},
  23. })
  24. minetest.register_craftitem("minercantile:silver_coin", {
  25. description = "Silver Coin",
  26. inventory_image = "minercantile_silver_coin.png",
  27. wield_scale = {x = 0.5, y = 0.5, z = 0.25},
  28. stack_max = 10000,
  29. groups = {not_in_creative_inventory = 0},
  30. })
  31. minetest.register_craftitem("minercantile:gold_coin", {
  32. description = "Gold Coin",
  33. inventory_image = "minercantile_gold_coin.png",
  34. wield_scale = {x = 0.5, y = 0.5, z = 0.25},
  35. stack_max = 10000,
  36. groups = {not_in_creative_inventory = 0},
  37. })
  38. minetest.register_alias("maptools:copper_coin", "minercantile:copper_coin")
  39. minetest.register_alias("maptools:silver_coin", "minercantile:silver_coin")
  40. minetest.register_alias("maptools:gold_coin", "minercantile:gold_coin")
  41. end
  42. local function get_bancomatic_formspec(pos, name)
  43. local spos = pos.x .. "," .. pos.y .. "," .. pos.z
  44. local formspec =
  45. "size[8,9]bgcolor[#2A2A2A;]label[3.35,0;Bancomatic]" ..
  46. "label[0,0;Your money:"..minercantile.wallet.get_money(name).."$]" ..
  47. "label[2,1;Put your coins to convert on your wallet]" ..
  48. "image[0,1.5;1,1;minercantile_gold_coin.png]" ..
  49. "label[1,1.7;= "..coins_convert["minercantile:gold_coin"].."$]" ..
  50. "image[0,2.5;1,1;minercantile_silver_coin.png]" ..
  51. "label[1,2.7;= "..coins_convert["minercantile:silver_coin"].."$]" ..
  52. "image[0,3.5;1,1;minercantile_copper_coin.png]" ..
  53. "label[1,3.7;= "..coins_convert["minercantile:copper_coin"].."$]" ..
  54. "list[nodemeta:" .. spos .. ";main;3.5,2.5;1,1;]" ..
  55. "list[current_player;main;0,4.85;8,1;]" ..
  56. "list[current_player;main;0,6.08;8,3;8]" ..
  57. "listring[nodemeta:" .. spos .. ";main]" ..
  58. "listring[current_player;main]" --..
  59. --default.get_hotbar_bg(0,4.85)
  60. return formspec
  61. end
  62. --change money. code based on atm from https://github.com/minetest-mods/global_exchange
  63. minetest.register_node("minercantile:bancomatic_bottom", {
  64. description = "Bancomatic",
  65. inventory_image = "minercantile_bancomatic_front.png",
  66. wield_image = "minercantile_bancomatic_front.png",
  67. drawtype = "nodebox",
  68. tiles = {
  69. "minercantile_bancomatic_back.png",
  70. "minercantile_bancomatic_back.png",
  71. "minercantile_bancomatic_back.png",
  72. "minercantile_bancomatic_back.png",
  73. "minercantile_bancomatic_back.png",
  74. "minercantile_bancomatic_back.png",
  75. },
  76. paramtype = "light",
  77. paramtype2 = "facedir",
  78. is_ground_content = false,
  79. light_source = 3,
  80. groups = {cracky=2, atm = 1},
  81. node_box = {
  82. type = "fixed",
  83. fixed = {
  84. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  85. }
  86. },
  87. selection_box = {
  88. type = "fixed",
  89. fixed = {
  90. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  91. {-0.5, 0.5, -0.5, -0.375, 1.125, -0.25},
  92. {0.375, 0.5, -0.5, 0.5, 1.125, -0.25},
  93. {-0.5, 0.5, -0.25, 0.5, 1.5, 0.5},
  94. {-0.5, 1.125, -0.4375, -0.375, 1.25, -0.25},
  95. {0.375, 1.125, -0.4375, 0.5, 1.25, -0.25},
  96. {-0.5, 1.25, -0.375, -0.375, 1.375, -0.25},
  97. {0.375, 1.25, -0.375, 0.5, 1.375, -0.25},
  98. {-0.5, 1.375, -0.3125, -0.375, 1.5, -0.25},
  99. {0.375, 1.375, -0.3125, 0.5, 1.5, -0.25},
  100. },
  101. },
  102. on_place = function(itemstack, placer, pointed_thing)
  103. local under = pointed_thing.under
  104. local pos
  105. if minetest.registered_items[minetest.get_node(under).name].buildable_to then
  106. pos = under
  107. else
  108. pos = pointed_thing.above
  109. end
  110. local def = minetest.registered_nodes[minetest.get_node(pos).name]
  111. if not def or not def.buildable_to then
  112. minetest.remove_node(pos)
  113. return itemstack
  114. end
  115. local dir = minetest.dir_to_facedir(placer:get_look_dir())
  116. local pos2 = {x = pos.x, y = pos.y + 1, z = pos.z}
  117. local def2 = minetest.registered_nodes[minetest.get_node(pos2).name]
  118. if not def2 or not def2.buildable_to then
  119. return itemstack
  120. end
  121. minetest.set_node(pos, {name = "minercantile:bancomatic_bottom", param2 = dir})
  122. minetest.set_node(pos2, {name = "minercantile:bancomatic_top", param2 = dir})
  123. end,
  124. on_destruct = function(pos)
  125. local pos2 = {x = pos.x, y = pos.y + 1, z = pos.z}
  126. local n2 = minetest.get_node(pos2)
  127. if minetest.get_item_group(n2.name, "atm") == 2 then
  128. minetest.remove_node(pos2)
  129. end
  130. end,
  131. on_construct = function(pos)
  132. local meta = minetest.get_meta(pos)
  133. meta:set_string("infotext", "Bancomatic")
  134. local inv = meta:get_inventory()
  135. inv:set_size("main", 1 * 1)
  136. end,
  137. can_dig = function(pos, player)
  138. local name = player:get_player_name()
  139. return (minetest.check_player_privs(name, {protection_bypass = true}) or minetest.check_player_privs(name, {shop = true}))
  140. end,
  141. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  142. return 0
  143. end,
  144. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  145. local itname = stack:get_name()
  146. if coins_convert[itname] ~= nil then
  147. return stack:get_count()
  148. end
  149. return 0
  150. end,
  151. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  152. return 0
  153. end,
  154. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  155. local itname = stack:get_name()
  156. if coins_convert[itname] ~= nil then
  157. local name = player:get_player_name()
  158. local meta = minetest.get_meta(pos)
  159. local inv = meta:get_inventory()
  160. local nb = stack:get_count()
  161. local amount = coins_convert[itname]*nb
  162. minercantile.wallet.give_money(name, amount)
  163. inv:set_stack(listname, index, nil)
  164. minetest.log("action", player:get_player_name() .. " put " .. stack:get_name() .. " to bancomatic at " .. minetest.pos_to_string(pos))
  165. minetest.show_formspec(name, "minercantile:bancomatic", get_bancomatic_formspec(pos, name))
  166. end
  167. end,
  168. on_rightclick = function(pos, node, clicker)
  169. minetest.show_formspec(clicker:get_player_name(), "minercantile:bancomatic", get_bancomatic_formspec(pos, clicker:get_player_name()))
  170. end,
  171. })
  172. minetest.register_node("minercantile:bancomatic_top", {
  173. drawtype = "nodebox",
  174. tiles = {
  175. "minercantile_bancomatic_back.png",
  176. "minercantile_bancomatic_back.png",
  177. "minercantile_bancomatic_side.png",
  178. "minercantile_bancomatic_side.png",
  179. "minercantile_bancomatic_back.png",
  180. "minercantile_bancomatic_front.png",
  181. },
  182. paramtype = "light",
  183. paramtype2 = "facedir",
  184. is_ground_content = false,
  185. light_source = 3,
  186. node_box = {
  187. type = "fixed",
  188. fixed = {
  189. {-0.5, -0.5, -0.5, -0.375, 0.125, -0.25},
  190. {0.375, -0.5, -0.5, 0.5, 0.125, -0.25},
  191. {-0.5, -0.5, -0.25, 0.5, 0.5, 0.5},
  192. {-0.5, 0.125, -0.4375, -0.375, 0.25, -0.25},
  193. {0.375, 0.125, -0.4375, 0.5, 0.25, -0.25},
  194. {-0.5, 0.25, -0.375, -0.375, 0.375, -0.25},
  195. {0.375, 0.25, -0.375, 0.5, 0.375, -0.25},
  196. {-0.5, 0.375, -0.3125, -0.375, 0.5, -0.25},
  197. {0.375, 0.375, -0.3125, 0.5, 0.5, -0.25},
  198. }
  199. },
  200. selection_box = {
  201. type = "fixed",
  202. fixed = {0, 0, 0, 0, 0, 0},
  203. },
  204. groups = { atm = 2, not_in_creative_inventory = 1},
  205. })