morgut.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. mobs:register_mob("nssm:morgut", {
  2. type = "monster",
  3. hp_max = 35,
  4. hp_min = 28,
  5. collisionbox = {-0.3, -0.1, -0.3, 0.3, 1.8, 0.3},
  6. visual = "mesh",
  7. rotate= 270,
  8. mesh = "morgut.x",
  9. textures = {
  10. {"morgut.png"}
  11. },
  12. visual_size = {x = 5, y = 5},
  13. makes_footstep_sound = true,
  14. view_range = 26,
  15. walk_velocity = 0.5,
  16. reach =2,
  17. run_velocity = 4,
  18. damage = 4,
  19. runaway = true,
  20. jump = true,
  21. sounds = {
  22. random = "morgut",
  23. },
  24. drops = {
  25. {name = "nssm:life_energy", chance = 1, min = 1, max = 3},
  26. {name = "nssm:gluttonous_soul_fragment", chance = 3, min = 1, max = 1},
  27. },
  28. armor = 70,
  29. drawtype = "front",
  30. water_damage = 0,
  31. fear_height = 4,
  32. floats = 1,
  33. lava_damage = 0,
  34. fire_damage = 0,
  35. light_damage = 0,
  36. group_attack = true,
  37. attack_animals = true,
  38. knock_back = 1,
  39. blood_texture = "morparticle.png",
  40. stepheight = 1.1,
  41. attack_type = "dogfight",
  42. animation = {
  43. speed_normal = 15,
  44. speed_run = 30,
  45. stand_start = 10,
  46. stand_end = 40,
  47. walk_start = 50,
  48. walk_end = 90,
  49. run_start = 100,
  50. run_end = 120,
  51. punch_start = 130,
  52. punch_end = 160,
  53. },
  54. do_custom = function (self)
  55. self.flag = (self.flag or 0)
  56. if self.inv_flag ~= 1 then
  57. self.inventory = {}
  58. for i = 1, 32 do
  59. self.inventory[i] = {name = '', num = 0}
  60. end
  61. end
  62. self.inv_flag = (self.inv_flag or 1)
  63. if self.flag == 1 then
  64. self.state = ""
  65. mobs:set_animation(self, "run")
  66. self.object:set_yaw(self.dir)
  67. self:set_velocity(4)
  68. if os.time() - self.morgut_timer > 3 then
  69. self.flag = 0
  70. self.state = "stand"
  71. end
  72. end
  73. end,
  74. custom_attack = function (self)
  75. self.curr_attack = (self.curr_attack or self.attack)
  76. self.morgut_timer = (self.morgut_timer or os.time())
  77. self.dir = (self.dir or 0)
  78. if (os.time() - self.morgut_timer) > 1 then
  79. if self.attack then
  80. local s = self.object:get_pos()
  81. local p = self.attack:get_pos()
  82. mobs:set_animation(self, "punch")
  83. local m = 2
  84. minetest.add_particlespawner({
  85. amount = 6,
  86. time = 1,
  87. minpos = {x=p.x-0.5, y=p.y-0.5, z=p.z-0.5},
  88. maxpos = {x=p.x+0.5, y=p.y+0.5, z=p.z+0.5},
  89. minvel = {x=(s.x-p.x)*m, y=(s.y-p.y)*m, z=(s.z-p.z)*m},
  90. maxvel = {x=(s.x-p.x)*m, y=(s.y-p.y)*m, z=(s.z-p.z)*m},
  91. minacc = {x=s.x-p.x, y=s.y-p.y, z=s.z-p.z},
  92. maxacc = {x=s.x-p.x, y=s.y-p.y, z=s.z-p.z},
  93. minexptime = 0.2,
  94. maxexptime = 0.3,
  95. minsize = 2,
  96. maxsize = 3,
  97. collisiondetection = false,
  98. texture = "roasted_duck_legs.png"
  99. })
  100. minetest.after(1, function(self)
  101. if self and self.attack:is_player() then
  102. local pname = self.attack:get_player_name()
  103. local player_inv = minetest.get_inventory(
  104. {type = 'player', name = pname})
  105. if player_inv:is_empty('main') then
  106. --minetest.chat_send_all("Inventory empty")
  107. else
  108. for i = 1, 32 do
  109. --minetest.chat_send_all("Inventory is not empty")
  110. local items = player_inv:get_stack('main', i)
  111. local n = items:get_name()
  112. if minetest.get_item_group(n, "eatable")==1 then
  113. local index
  114. local found = 0
  115. for j = 1,32 do
  116. if found == 0 then
  117. if self.inventory[j].num == 0 then
  118. --found an empty place
  119. found = 2
  120. index = j
  121. else
  122. --found a corrsponding itemstack
  123. if self.inventory[j].name == n then
  124. self.inventory[j].num = self.inventory[j].num +1
  125. found = 1
  126. end
  127. end
  128. end
  129. end
  130. if found == 2 then
  131. self.inventory[index].name = n
  132. self.inventory[index].num = 1
  133. end
  134. items:take_item()
  135. player_inv:set_stack('main', i, items)
  136. end
  137. end
  138. end
  139. mobs:set_animation(self, "run")
  140. self.flag = 1
  141. self.morgut_timer = os.time()
  142. self.curr_attack = self.attack
  143. self.state = ""
  144. local pyaw = self.curr_attack: get_look_yaw()
  145. self.dir = pyaw
  146. self.object:set_yaw(pyaw)
  147. if self then
  148. self:set_velocity(4)
  149. end
  150. end
  151. end, self)
  152. end
  153. end
  154. end,
  155. on_die = function(self)
  156. local pos = self.object:get_pos()
  157. if (self.inventory ~= nil) then
  158. local elem
  159. for i = 1,32 do
  160. if self.inventory[i].num ~= 0 then
  161. local items = ItemStack(self.inventory[i].name
  162. .. " " .. self.inventory[i].num)
  163. local obj = minetest.add_item(pos, items)
  164. obj:set_velocity({
  165. x = math.random(-1, 1),
  166. y = 6,
  167. z = math.random(-1, 1)
  168. })
  169. end
  170. end
  171. end
  172. self.object:remove()
  173. end,
  174. })