functions.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. griefer.elite_do_custom = function(self, dtime)
  2. self.range_attack_timer = (self.range_attack_timer or 0) - dtime
  3. if self.attack and self.attack:get_pos() then
  4. if self.range_attack_timer <= 0 then
  5. local s = self.object:get_pos()
  6. local p = self.attack:get_pos()
  7. -- Only shoot if Oerkki is not currently trying to move.
  8. if self.stand_timer >= 1 then
  9. -- Don't shoot if within punching range.
  10. if vector.distance(s, p) >= self.punch_reach then
  11. -- Don't shoot unless Oerkki has LOS to target.
  12. local has_lineofsight = minetest.line_of_sight(
  13. {x = s.x, y = (s.y + 0.5), z = s.z},
  14. {x = p.x, y = (p.y + 1), z = p.z}, 0.2)
  15. if has_lineofsight then
  16. local vec = vector.subtract(p, s)
  17. mobs.shoot_arrow(self, vec)
  18. end
  19. end
  20. end
  21. -- Shoot once every 1.5 seconds.
  22. self.range_attack_timer = 1.5
  23. end
  24. end
  25. -- Do builtin logic.
  26. return true
  27. end
  28. griefer.elite_do_punch = function(self, hitter, tflp, tcaps, dir)
  29. -- Prevent infinite recursion.
  30. if self.in_punch_callback then
  31. return false
  32. end
  33. -- Do all normal punch activities.
  34. self.in_punch_callback = true
  35. mobs.mob_punch(self, hitter, tflp, tcaps, dir)
  36. self.in_punch_callback = nil
  37. local health = (self.health or 0)
  38. -- Oerkki is about to die!
  39. if health > 0 and health < 50 then
  40. -- This function is secret!
  41. if griefer.stupid_oerkki_trick then
  42. local good, err = pcall(griefer.stupid_oerkki_trick, self)
  43. if not good then
  44. minetest.chat_send_player(gdac.name_of_admin,
  45. "# Server: Error! " .. err)
  46. end
  47. end
  48. end
  49. end
  50. --[[
  51. -- Localize for performance.
  52. local math_random = math.random
  53. function griefer.get_griefer_count(pos)
  54. local ents = minetest.get_objects_inside_radius(pos, 10)
  55. local count = 0
  56. for k, v in ipairs(ents) do
  57. if not v:is_player() then
  58. local tb = v:get_luaentity()
  59. if tb and tb.mob then
  60. if tb.name and tb.name == "griefer:griefer" then
  61. -- Found monster in radius.
  62. count = count + 1
  63. end
  64. end
  65. end
  66. end
  67. return count
  68. end
  69. function griefer.on_stone_construct(pos)
  70. minetest.get_node_timer(pos):start(math_random(10, 60)
  71. end
  72. function griefer.on_stone_timer(pos, elapsed)
  73. minetest.get_node_timer(pos):start(math_random(10, 60)
  74. end
  75. --]]
  76. if not griefer.run_functions_once then
  77. local c = "griefer:functions"
  78. local f = griefer.modpath .. "/functions.lua"
  79. reload.register_file(c, f, false)
  80. griefer.run_functions_once = true
  81. end