bobber_shark.lua 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. -----------------------------------------------------------------------------------------------
  2. -- Fishing - Mossmanikin's version - Bobber Shark 0.0.6
  3. -- License (code & textures): WTFPL
  4. -----------------------------------------------------------------------------------------------
  5. -- Here's what you can catch if you use a fish as bait
  6. local CaTCH_BiG = {
  7. -- MoD iTeM WeaR MeSSaGe ("You caught "..) GeTBaiTBack NRMiN CHaNCe (../120)
  8. {"fishing", "shark", 0, "a small Shark.", false, 1, 2},
  9. {"fishing", "pike", 0, "a Northern Pike.", false, 3, 3}
  10. }
  11. local PLaNTS = {
  12. -- MoD* iTeM MeSSaGe ("You caught "..)
  13. {"flowers", "waterlily", "a Waterlily." },
  14. {"flowers", "waterlily_225", "a Waterlily." },
  15. {"flowers", "waterlily_45", "a Waterlily." },
  16. {"flowers", "waterlily_675", "a Waterlily." },
  17. {"flowers", "waterlily_s1", "a Waterlily." },
  18. {"flowers", "waterlily_s2", "a Waterlily." },
  19. {"flowers", "waterlily_s3", "a Waterlily." },
  20. {"flowers", "waterlily_s4", "a Waterlily." },
  21. {"flowers", "seaweed", "some Seaweed."},
  22. {"flowers", "seaweed_2", "some Seaweed."},
  23. {"flowers", "seaweed_3", "some Seaweed."},
  24. {"flowers", "seaweed_4", "some Seaweed."},
  25. {"trunks", "twig_1", "a Twig." },
  26. {"trunks", "twig_2", "a Twig." },
  27. {"trunks", "twig_3", "a Twig." },
  28. {"trunks", "twig_4", "a Twig." },
  29. {"trunks", "twig_5", "a Twig." },
  30. {"trunks", "twig_7", "a Twig." },
  31. {"trunks", "twig_8", "a Twig." },
  32. {"trunks", "twig_9", "a Twig." },
  33. {"trunks", "twig_10", "a Twig." },
  34. {"trunks", "twig_11", "a Twig." },
  35. {"trunks", "twig_12", "a Twig." },
  36. {"trunks", "twig_13", "a Twig." },
  37. }
  38. -- *as used in the node name
  39. local FISHING_BOBBER_ENTITY_SHARK={
  40. hp_max = 605,
  41. water_damage = 1,
  42. physical = true,
  43. timer = 0,
  44. env_damage_timer = 0,
  45. visual = "wielditem",
  46. visual_size = {x=1/3, y=1/3, z=1/3},
  47. textures = {"fishing:bobber_box"},
  48. -- {left ,bottom, front, right, top , back}
  49. collisionbox = {-2/16, -4/16, -2/16, 2/16, 0/16, 2/16},
  50. view_range = 7,
  51. -- DESTROY BOBBER WHEN PUNCHING IT
  52. on_punch = function (self, puncher, time_from_last_punch, tool_capabilities, dir)
  53. local player = puncher:get_player_name()
  54. if MESSAGES == true then minetest.chat_send_player(player, "Your fish escaped.", false) end -- fish escaped
  55. minetest.sound_play("fishing_bobber1", {
  56. pos = self.object:getpos(),
  57. gain = 0.5,
  58. })
  59. self.object:remove()
  60. end,
  61. -- WHEN RIGHTCLICKING THE BOBBER THE FOLLOWING HAPPENS (CLICK AT THE RIGHT TIME WHILE HOLDING A FISHING POLE)
  62. on_rightclick = function (self, clicker)
  63. local item = clicker:get_wielded_item()
  64. local player = clicker:get_player_name()
  65. local say = minetest.chat_send_player
  66. if item:get_name() == "fishing:pole" then
  67. local inv = clicker:get_inventory()
  68. local pos = self.object:getpos()
  69. -- catch visible plant
  70. if minetest.get_node(pos).name ~= "air" then
  71. for i in ipairs(PLaNTS) do
  72. local PLaNT = PLaNTS[i][1]..":"..PLaNTS[i][2]
  73. local MeSSaGe = PLaNTS[i][3]
  74. local DRoP = minetest.registered_nodes[PLaNT].drop
  75. if minetest.get_node(pos).name == PLaNT then
  76. minetest.add_node({x=pos.x, y=pos.y, z=pos.z}, {name="air"})
  77. if inv:room_for_item("main", {name=DRoP, count=1, wear=0, metadata=""}) then
  78. inv:add_item("main", {name=DRoP, count=1, wear=0, metadata=""})
  79. if MESSAGES == true then say(player, "You caught "..MeSSaGe, false) end -- caught Plant
  80. end
  81. if not minetest.setting_getbool("creative_mode") then
  82. if inv:room_for_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""}) then
  83. inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  84. if MESSAGES == true then say(player, "The bait is still there.", false) end -- bait still there
  85. end
  86. end
  87. end
  88. end
  89. end
  90. --elseif minetest.get_node(pos).name == "air" then
  91. if self.object:get_hp() <= 300 then
  92. if math.random(1, 100) < SHARK_CHANCE then
  93. local chance = math.random(1, 5) -- ><((((º>
  94. for i in pairs(CaTCH_BiG) do
  95. local MoD = CaTCH_BiG[i][1]
  96. local iTeM = CaTCH_BiG[i][2]
  97. local WeaR = CaTCH_BiG[i][3]
  98. local MeSSaGe = CaTCH_BiG[i][4]
  99. local GeTBaiTBack = CaTCH_BiG[i][5]
  100. local NRMiN = CaTCH_BiG[i][6]
  101. local CHaNCe = CaTCH_BiG[i][7]
  102. local NRMaX = NRMiN + CHaNCe - 1
  103. if chance <= NRMaX and chance >= NRMiN then
  104. if minetest.get_modpath(MoD) ~= nil then
  105. if inv:room_for_item("main", {name=MoD..":"..iTeM, count=1, wear=WeaR, metadata=""}) then
  106. inv:add_item("main", {name=MoD..":"..iTeM, count=1, wear=WeaR, metadata=""})
  107. if MESSAGES == true then say(player, "You caught "..MeSSaGe, false) end -- caught somethin'
  108. end
  109. if not minetest.setting_getbool("creative_mode") then
  110. if GeTBaiTBack == true then
  111. if inv:room_for_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""}) then
  112. inv:add_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""})
  113. if MESSAGES == true then say(player, "The bait is still there.", false) end -- bait still there?
  114. end
  115. end
  116. end
  117. end
  118. end
  119. end
  120. else --if math.random(1, 100) > FISH_CHANCE then
  121. if MESSAGES == true then say(player, "Your fish escaped.", false) end -- fish escaped
  122. end
  123. end
  124. if self.object:get_hp() > 300 and minetest.get_node(pos).name == "air" then
  125. if MESSAGES == true then say(player, "You didn't catch any fish.", false) end -- fish escaped
  126. if not minetest.setting_getbool("creative_mode") then
  127. if math.random(1, 3) == 1 then
  128. if inv:room_for_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""}) then
  129. inv:add_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""})
  130. if MESSAGES == true then say(player, "The bait is still there.", false) end -- bait still there
  131. end
  132. end
  133. end
  134. end
  135. --end
  136. else
  137. if MESSAGES == true then say(player, "Your fish escaped.", false) end -- fish escaped
  138. end
  139. minetest.sound_play("fishing_bobber1", {
  140. pos = self.object:getpos(),
  141. gain = 0.5,
  142. })
  143. self.object:remove()
  144. end,
  145. -- AS SOON AS THE BOBBER IS PLACED IT WILL ACT LIKE
  146. on_step = function(self, dtime)
  147. local pos = self.object:getpos()
  148. if BOBBER_CHECK_RADIUS > 0 then
  149. local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, BOBBER_CHECK_RADIUS)
  150. for k, obj in pairs(objs) do
  151. if obj:get_luaentity() ~= nil then
  152. if obj:get_luaentity().name == "fishing:bobber_entity_shark" then
  153. if obj:get_luaentity() ~= self then
  154. self.object:remove()
  155. end
  156. end
  157. end
  158. end
  159. end
  160. if math.random(1, 4) == 1 then
  161. self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/2880*math.pi))
  162. end
  163. for _,player in pairs(minetest.get_connected_players()) do
  164. local s = self.object:getpos()
  165. local p = player:getpos()
  166. local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
  167. if dist > self.view_range then
  168. minetest.sound_play("fishing_bobber1", {
  169. pos = self.object:getpos(),
  170. gain = 0.5,
  171. })
  172. self.object:remove()
  173. end
  174. end
  175. local do_env_damage = function(self)
  176. self.object:set_hp(self.object:get_hp()-self.water_damage)
  177. if self.object:get_hp() == 600 then
  178. self.object:moveto({x=pos.x,y=pos.y-0.015625,z=pos.z})
  179. elseif self.object:get_hp() == 595 then
  180. self.object:moveto({x=pos.x,y=pos.y+0.015625,z=pos.z})
  181. elseif self.object:get_hp() == 590 then
  182. self.object:moveto({x=pos.x,y=pos.y+0.015625,z=pos.z})
  183. elseif self.object:get_hp() == 585 then
  184. self.object:moveto({x=pos.x,y=pos.y-0.015625,z=pos.z})
  185. self.object:set_hp(self.object:get_hp()-(math.random(1, 200)))
  186. elseif self.object:get_hp() == 300 then
  187. minetest.sound_play("fishing_bobber1", {
  188. pos = self.object:getpos(),
  189. gain = 0.7,
  190. })
  191. minetest.add_particlespawner(40, 0.5, -- for how long (?) -- Particles on splash
  192. {x=pos.x,y=pos.y-0.0625,z=pos.z}, {x=pos.x,y=pos.y-0.2,z=pos.z}, -- position min, pos max
  193. {x=-3,y=-0.0625,z=-3}, {x=3,y=5,z=3}, -- velocity min, vel max
  194. {x=0,y=-9.8,z=0}, {x=0,y=-9.8,z=0},
  195. 0.3, 2.4,
  196. 0.25, 0.5, -- min size, max size
  197. false, "default_snow.png")
  198. self.object:moveto({x=pos.x,y=pos.y-0.625,z=pos.z})
  199. elseif self.object:get_hp() == 295 then
  200. self.object:moveto({x=pos.x,y=pos.y+0.425,z=pos.z})
  201. elseif self.object:get_hp() == 290 then
  202. self.object:moveto({x=pos.x,y=pos.y+0.0625,z=pos.z})
  203. elseif self.object:get_hp() == 285 then
  204. self.object:moveto({x=pos.x,y=pos.y-0.0625,z=pos.z})
  205. elseif self.object:get_hp() < 284 then
  206. self.object:moveto({x=pos.x+(0.001*(math.random(-8, 8))),y=pos.y,z=pos.z+(0.001*(math.random(-8, 8)))})
  207. self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/720*math.pi))
  208. elseif self.object:get_hp() == 0 then
  209. minetest.sound_play("fishing_bobber1", {
  210. pos = self.object:getpos(),
  211. gain = 0.5,
  212. })
  213. self.object:remove()
  214. end
  215. end
  216. do_env_damage(self)
  217. end,
  218. }
  219. minetest.register_entity("fishing:bobber_entity_shark", FISHING_BOBBER_ENTITY_SHARK)