unggoy.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. defense_mob_api.register_mob("mob_unggoy:unggoy", {
  2. hp_max = 11,
  3. collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.3, 0.4},
  4. mesh = "mob_unggoy_unggoy.b3d",
  5. textures = {"mob_unggoy_unggoy.png"},
  6. makes_footstep_sound = true,
  7. animation = {
  8. idle = {a=0, b=39, rate=30},
  9. jump = {a=40, b=49, rate=15},
  10. fall = {a=50, b=64, rate=20},
  11. attack = {a=65, b=72, rate=15},
  12. move = {a=75, b=99, rate=40},
  13. move_attack = {a=100, b=113, rate=20},
  14. },
  15. smart_path = false,
  16. smart_path_for = 0, --initializing to 0 >= 0 means it's going to switch on and off
  17. swarm = true,
  18. mass = 4,
  19. move_speed = 5,
  20. jump_height = 2,
  21. armor = 0,
  22. attack_damage = 1,
  23. attack_range = 1.5,
  24. attack_interval = 0.6,
  25. wander = false,
  26. on_activate = function(self, staticdata)
  27. self.swarm:signup(self)
  28. defense_mob_api.default_prototype.on_activate(self, staticdata)
  29. staticdata = minetest.deserialize(staticdata) or {}
  30. if staticdata.spawn_with_bombs
  31. then
  32. local bombref = minetest.add_entity(
  33. self.object:get_pos(),
  34. "gunpowder_barrels:barrel_entity")
  35. if bombref
  36. then
  37. bombref:set_attach(
  38. self.object,
  39. "",
  40. {x = 0, y = 15, z = 0},
  41. {x = 0, y = 0, z = 0})
  42. bombref:get_luaentity():start_fuse(math.random() * 400 + 200)
  43. end
  44. end
  45. -- Some monkeys can jump higher
  46. if math.random() < 0.1
  47. then
  48. self.jump_height = self.jump_height + math.random() * 2
  49. end
  50. end,
  51. on_step = function(self, dtime)
  52. defense_mob_api.default_prototype.on_step(self, dtime)
  53. if self.wander
  54. then
  55. local g = vector.add(
  56. self.object:get_pos(),
  57. {x = math.random(-12, 12) + 4, y = 0, z = math.random(-12, 12) + 4}
  58. )
  59. local node = minetest.get_node_or_nil(g)
  60. node = minetest.registered_nodes[node] or {walkable = true}
  61. if not node.walkable
  62. then
  63. self.destination = g
  64. end
  65. self.wander = false
  66. elseif math.random() < 0.006
  67. then
  68. self.wander = true
  69. end
  70. self:hunt()
  71. end,
  72. is_standing = function(self)
  73. -- Able to stand on top of others
  74. if defense_mob_api.default_prototype.is_standing(self)
  75. then
  76. return true
  77. else
  78. local vel = self.object:getvelocity()
  79. if math.abs(vel.y) > 0.2
  80. then
  81. return false
  82. end
  83. local pos = self.object:get_pos()
  84. pos.y = pos.y - 1
  85. for _,o in ipairs(minetest.get_objects_inside_radius(pos, 1))
  86. do
  87. if o ~= self.object
  88. then
  89. local e = o:get_luaentity()
  90. if e and e.name == self.name
  91. then
  92. return true
  93. end
  94. end
  95. end
  96. return false
  97. end
  98. end,
  99. --[[
  100. on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
  101. defense_mob_api.default_prototype.on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
  102. self.swarm:alert(self.object:get_pos(), 3,
  103. function(selfobj, dist)
  104. selfobj:remove()
  105. end)
  106. end,
  107. ]]
  108. })
  109. minetest.register_alias("unggoy", "mob_unggoy:unggoy")