morde.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. mobs:register_mob("nssm:morde", {
  2. type = "monster",
  3. hp_max = 47,
  4. hp_min = 37,
  5. collisionbox = {-0.4, -0.1, -0.4, 0.4, 1.6, 0.4},
  6. visual = "mesh",
  7. rotate= 270,
  8. mesh = "morde.x",
  9. textures = {
  10. {"morde.png"}
  11. },
  12. visual_size = {x = 10, y = 10},
  13. makes_footstep_sound = true,
  14. view_range = 20,
  15. walk_velocity = 0.5,
  16. reach =3,
  17. run_velocity = 3.5,
  18. damage = 6,
  19. jump = true,
  20. sounds = {
  21. random = "morde",
  22. },
  23. drops = {
  24. {name = "nssm:life_energy", chance = 1, min = 2, max = 4},
  25. {name = "nssm:proud_soul_fragment", chance = 3, min = 1, max = 1},
  26. },
  27. armor = 60,
  28. drawtype = "front",
  29. water_damage = 0,
  30. fear_height = 4,
  31. floats = 1,
  32. lava_damage = 0,
  33. fire_damage = 0,
  34. light_damage = 0,
  35. group_attack = true,
  36. attack_animals = true,
  37. knock_back = 1,
  38. blood_texture = "morparticle.png",
  39. stepheight = 1.1,
  40. attack_type = "dogfight",
  41. animation = {
  42. speed_normal = 15,
  43. speed_run = 25,
  44. stand_start = 10,
  45. stand_end = 40,
  46. walk_start = 50,
  47. walk_end = 90,
  48. run_start = 100,
  49. run_end = 120,
  50. punch_start = 130,
  51. punch_end = 160,
  52. },
  53. custom_attack = function (self)
  54. self.morde_timer = self.morde_timer or os.time()
  55. if (os.time() - self.morde_timer) > 1 then
  56. self.morde_timer = os.time()
  57. local s = self.object:get_pos()
  58. local p = self.attack:get_pos()
  59. mobs:set_animation(self, "punch")
  60. self.health = self.health + (self.damage * 2)
  61. local m = 3
  62. if minetest.line_of_sight(
  63. {x = p.x, y = p.y + 1.5, z = p.z},
  64. {x = s.x, y = s.y + 1.5, z = s.z}) == true then
  65. -- play attack sound
  66. if self.sounds.attack then
  67. minetest.sound_play(self.sounds.attack, {
  68. object = self.object,
  69. max_hear_distance = self.sounds.distance
  70. })
  71. end
  72. -- punch player
  73. self.attack:punch(self.object, 1.0, {
  74. full_punch_interval = 1.0,
  75. damage_groups = {fleshy = self.damage}
  76. }, nil)
  77. minetest.add_particlespawner({
  78. amount = 6,
  79. time = 1,
  80. minpos = {x=p.x-0.5, y=p.y-0.5, z=p.z-0.5},
  81. maxpos = {x=p.x+0.5, y=p.y+0.5, z=p.z+0.5},
  82. minvel = {x=(s.x-p.x)*m, y=(s.y-p.y+1)*m, z=(s.z-p.z)*m},
  83. maxvel = {x=(s.x-p.x)*m, y=(s.y-p.y+1)*m, z=(s.z-p.z)*m},
  84. minacc = {x=s.x-p.x, y=s.y-p.y+1, z=s.z-p.z},
  85. maxacc = {x=s.x-p.x, y=s.y-p.y+1, z=s.z-p.z},
  86. minexptime = 0.2,
  87. maxexptime = 0.3,
  88. minsize = 2,
  89. maxsize = 3,
  90. collisiondetection = false,
  91. texture = "morparticle.png"
  92. })
  93. end
  94. end
  95. end,
  96. on_die = function(self)
  97. local pos = self.object:get_pos()
  98. self.object:remove()
  99. minetest.add_entity(pos, "nssm:mortick")
  100. end,
  101. })
  102. minetest.register_entity("nssm:mortick", {
  103. textures = {"mortick.png"},
  104. hp_min = 10000,
  105. hp_max = 10000,
  106. armor = 100,
  107. visual = "mesh",
  108. mesh = "mortick.x",
  109. visual_size = {x = 3, y = 3},
  110. --lifetime = 10,
  111. damage = 1,
  112. on_step = function(self, dtime)
  113. self.mortick_timer = self.mortick_timer or os.time()
  114. self.timer = self.timer or 0
  115. self.timer = self.timer + dtime
  116. local s = self.object:get_pos()
  117. local s1 = {x=s.x, y = s.y-1, z = s.z}
  118. --[[
  119. if (os.time()-self.mortick_timer > self.lifetime) then
  120. self.object:remove()
  121. end
  122. ]]
  123. --The mortick dies when he finds himself in the fire
  124. local name = minetest.get_node(s1).name
  125. if name == "fire:basic_flame"
  126. or name == "fire:permanent_flame" then
  127. self.object:remove()
  128. end
  129. --Find player to attack:
  130. self.attack = (self.attack or 0)
  131. local objects = minetest.get_objects_inside_radius(s, 8)
  132. for _,obj in ipairs(objects) do
  133. if (obj:is_player()) then
  134. self.attack = obj
  135. end
  136. end
  137. --If found a player follow him
  138. if self.attack ~= 0 then
  139. local p = self.attack:get_pos()
  140. -- Just incase player teleports away or leaves game
  141. if not p then
  142. self.attack = nil
  143. return
  144. end
  145. local yawp = self.attack:get_look_horizontal() + math.pi / 2
  146. local pi = math.pi
  147. p.y = p.y + 1
  148. p.x = p.x - math.cos(yawp) / 2.5
  149. p.z = p.z - math.sin(yawp) / 2.5
  150. local m = 10
  151. local v = {
  152. x = -(s.x - p.x) * m,
  153. y = -(s.y - p.y) * m,
  154. z = -(s.z - p.z) * m
  155. }
  156. local yaws = yawp + pi
  157. --stay attached to players back:
  158. self.object:set_velocity(v)
  159. self.object:set_yaw(yaws)
  160. --damage player every ten seconds:
  161. if (self.timer > 10) then
  162. self.timer = 0
  163. self.attack:set_hp(self.attack:get_hp() - self.damage)
  164. end
  165. end
  166. end
  167. })