init.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. local nici = 1
  2. local lastcard = nil
  3. local rplayers = {}
  4. local function inform_near_players(pos, msg)
  5. for _,player in pairs(minetest.get_objects_inside_radius(pos, 10)) do
  6. if player:is_player() then
  7. minetest.chat_send_player(player:get_player_name(), msg)
  8. end
  9. end
  10. end
  11. function apn(pos, placer, itemstack)
  12. local grop = minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "myuno")
  13. if grop > 3 then
  14. return
  15. end
  16. local name = placer:get_player_name()
  17. if grop == 0 then
  18. minetest.chat_send_player(name, "You can not place a card there!")
  19. minetest.remove_node(pos)
  20. return itemstack
  21. end
  22. local node = minetest.get_node(pos)
  23. local nodeu = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
  24. local descr = minetest.registered_items[node.name].description
  25. if grop == 1 then
  26. inform_near_players(pos, name.." placed a "..descr)
  27. return
  28. end
  29. lastcard = nodeu.name
  30. minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, node)
  31. minetest.remove_node(pos)
  32. if grop == 3 then
  33. return itemstack
  34. end
  35. print(node.name)
  36. inform_near_players(pos, name.." placed a "..descr)
  37. end
  38. function od(pos, node, player, pointed_thing)
  39. local node = minetest.get_node(pos)
  40. local nn = node.name
  41. local nodeu = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
  42. local inv = player:get_inventory()
  43. local lc = lastcard
  44. print(nn)
  45. print(lc)
  46. if lastcard ~= nil then
  47. inv:add_item("main",nn)
  48. minetest.set_node(pos, {name = lc})
  49. lastcard = nil
  50. else
  51. return
  52. end
  53. end
  54. local sbox1 = {
  55. type = "fixed",
  56. fixed = {
  57. {-0.5, -0.5, -0.5, 0.5, -0.49, 0.5}}
  58. }
  59. local sbox2 = {
  60. type = "fixed",
  61. fixed = {
  62. {-0.3, -0.5, -0.45, 0.3, -0.3, 0.45}}
  63. }
  64. for nu = 1,13 do
  65. local num = nu
  66. local deck = {
  67. {"Red "..num,"1_"..num,"^[colorize:red:220","a"..num},
  68. {"Red "..num,"2_"..num,"^[colorize:red:220","b"..num},
  69. {"Yellow "..num,"3_"..num,"^[colorize:yellow:220","a"..num},
  70. {"Yellow "..num,"4_"..num,"^[colorize:yellow:220","b"..num},
  71. {"Green "..num,"5_"..num,"^[colorize:green:220","a"..num},
  72. {"Green "..num,"6_"..num,"^[colorize:green:220","b"..num},
  73. {"Blue "..num,"7_"..num,"^[colorize:blue:220","a"..num},
  74. {"Blue "..num,"8_"..num,"^[colorize:blue:220","b"..num},
  75. }
  76. for i in ipairs(deck) do
  77. local desc = deck[i][1]
  78. local itm = deck[i][2]
  79. local col = deck[i][3]
  80. local nimg = deck[i][4]
  81. for imgnum = 1,13 do
  82. local inum = imgnum
  83. if nimg == "b"..inum then
  84. nimg = "a"..inum
  85. else nimg = nimg
  86. local desc2 = "Card"
  87. if nimg == "a10" or
  88. nimg == "b10" then
  89. desc2 = string.gsub(desc, 10, "Change Direction")
  90. elseif nimg == "a11" or
  91. nimg == "b11" then
  92. desc2 = string.gsub(desc, 11, "Miss A Turn")
  93. elseif nimg == "a12" or
  94. nimg == "b12" then
  95. desc2 = string.gsub(desc, 12, "Pick Up 2")
  96. elseif nimg == "a13" then
  97. desc2 = string.gsub(desc, 13, 0)
  98. elseif nimg == "b13" then
  99. desc2 = "Pick Up 4"
  100. else
  101. desc2 = desc
  102. end
  103. minetest.register_node("myuno:"..itm,{
  104. description = desc2,
  105. inventory_image = "myuno_color.png"..col.."^myuno_white.png^myuno_"..nimg..".png",
  106. tiles = {"myuno_color.png"..col.."^myuno_white.png^myuno_"..nimg..".png"},
  107. drawtype = "mesh",
  108. mesh = "myuno_card.obj",
  109. paramtype = "light",
  110. -- paramtype2 = "facedir",
  111. stack_max = 1,
  112. groups = {oddly_breakable_by_hand = 3,not_in_creative_inventory = nici,myuno=2},
  113. selection_box = sbox1,
  114. collision_box = sbox1,
  115. after_place_node = apn,
  116. on_punch = od,
  117. })
  118. end
  119. end
  120. end
  121. end
  122. minetest.register_node("myuno:col",{
  123. description = "Any Color ",
  124. inventory_image = "myuno_col.png",
  125. tiles = {"myuno_card.png^myuno_col.png"},
  126. drawtype = "mesh",
  127. mesh = "myuno_card.obj",
  128. paramtype = "light",
  129. -- paramtype2 = "facedir",
  130. stack_max = 1,
  131. groups = {oddly_breakable_by_hand = 3,not_in_creative_inventory = nici,myuno=3},
  132. selection_box = sbox1,
  133. collision_box = sbox1,
  134. on_place = function(itemstack, placer, pointed_thing)
  135. local pos = pointed_thing.above
  136. local node = minetest.get_node(pos)
  137. local meta = minetest.get_meta(pos)
  138. minetest.show_formspec(placer:get_player_name(),"cform",
  139. "size[4,4;]"..
  140. "image_button_exit[0,0;2,2;myuno_form_red.png;red; ]"..
  141. "image_button_exit[2,0;2,2;myuno_form_yellow.png;yellow; ]"..
  142. "image_button_exit[0,2;2,2;myuno_form_blue.png;blue; ]"..
  143. "image_button_exit[2,2;2,2;myuno_form_green.png;green; ]")
  144. minetest.register_on_player_receive_fields(function(player, formname, fields)
  145. if formname == "cform" then
  146. if fields["red"] then
  147. minetest.set_node(pos,{name="air"})
  148. minetest.set_node({x=pos.x,y=pos.y-1,z=pos.z},{name="myuno:red"})
  149. return itemstack
  150. elseif fields["blue"] then
  151. minetest.set_node(pos,{name="air"})
  152. minetest.set_node({x=pos.x,y=pos.y-1,z=pos.z},{name="myuno:blue"})
  153. elseif fields["yellow"] then
  154. minetest.set_node(pos,{name="air"})
  155. minetest.set_node({x=pos.x,y=pos.y-1,z=pos.z},{name="myuno:yellow"})
  156. elseif fields["green"] then
  157. minetest.set_node(pos,{name="air"})
  158. minetest.set_node({x=pos.x,y=pos.y-1,z=pos.z},{name="myuno:green"})
  159. end
  160. end
  161. end)
  162. itemstack:take_item()
  163. return itemstack
  164. end,
  165. after_place_node = apn,
  166. on_punch = od,
  167. })
  168. minetest.register_node("myuno:deck",{
  169. description = "Uno Card Deck",
  170. tiles = {"myuno_deck.png"},
  171. drawtype = "mesh",
  172. mesh = "myuno_deck.obj",
  173. paramtype = "light",
  174. -- paramtype2 = "facedir",
  175. stack_max = 1,
  176. groups = {oddly_breakable_by_hand = 1,not_in_creative_inventory = nici},
  177. selection_box = sbox2,
  178. collision_box = sbox2,
  179. on_punch = function(pos, node, puncher, pointed_thing)
  180. local inv = puncher:get_inventory()
  181. local rand = math.random(1,108)
  182. local rcol = math.random(1,8)
  183. local scol = tostring(rcol)
  184. local rnum = math.random(1,13)
  185. local snum = tostring(rnum)
  186. local card = "myuno:"..scol.."_"..snum.." 1"
  187. if rand <= 4 then
  188. if inv
  189. and inv:room_for_item("main", "myuno:col 1") then
  190. inv:add_item("main", "myuno:col 1")
  191. else
  192. minetest.add_item(pos, item)
  193. end
  194. else
  195. if inv
  196. and inv:room_for_item("main", card) then
  197. inv:add_item("main", card)
  198. else
  199. minetest.add_item(pos, item)
  200. end
  201. end
  202. end,
  203. })
  204. minetest.register_node("myuno:board",{
  205. description = "My Uno",
  206. inventory_image = "myuno_inv.png",
  207. wield_image = "myuno_inv.png",
  208. tiles = {"default_clay.png^bubble.png"},
  209. drawtype = "normal",
  210. paramtype = "light",
  211. groups = {oddly_breakable_by_hand = 1},
  212. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  213. local schem = minetest.get_modpath("myuno").."/schems/myuno.mts"
  214. minetest.place_schematic({x=pos.x,y=pos.y,z=pos.z},schem,0, "air", true)
  215. count = 0
  216. end,
  217. after_place_node = function(pos, placer, itemstack, pointed_thing)
  218. if placer and minetest.check_player_privs(placer:get_player_name(), {myboardgames = true}) then
  219. else
  220. minetest.remove_node(pos)
  221. return true
  222. end
  223. end,
  224. })
  225. minetest.register_node("myuno:placer",{
  226. description = "Placer",
  227. tiles = {"default_clay.png"},
  228. drawtype = "normal",
  229. paramtype = "light",
  230. drop = "",
  231. groups = {cracky=1,not_in_creative_inventory = nici,myuno=1},
  232. })
  233. local colcards = {
  234. {"Red Card","red"},
  235. {"Blue Card","blue"},
  236. {"Yellow Card","yellow"},
  237. {"Green Card","green"},
  238. }
  239. for i in ipairs(colcards) do
  240. local desc = colcards[i][1]
  241. local itm = colcards[i][2]
  242. minetest.register_node("myuno:"..itm,{
  243. description = desc,
  244. tiles = {"myuno_"..itm..".png"},
  245. drawtype = "mesh",
  246. mesh = "myuno_card.obj",
  247. paramtype = "light",
  248. -- paramtype2 = "facedir",
  249. drop = "",
  250. groups = {oddly_breakable_by_hand = 3,not_in_creative_inventory = nici,myuno=2},
  251. selection_box = sbox1,
  252. collision_box = sbox1,
  253. after_place_node = apn,
  254. on_punch = od,
  255. })
  256. end