action.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. local function throw_player(e, p)
  2. local p1 = e:get_pos()
  3. local p2 = p:get_pos()
  4. p1.y = p2.y
  5. local vel = vector.subtract(p2, p1)
  6. vel = vector.normalize(vel)
  7. vel = vector.add(vel, {x=0, y=0.5, z=0})
  8. vel = vector.multiply(vel, 10)
  9. p:add_player_velocity(vel)
  10. end
  11. function pm.hurt_nearby_players(self)
  12. local pos = self.object:get_pos()
  13. local players = minetest.get_connected_players()
  14. for k, v in ipairs(players) do
  15. if vector.distance(pos, v:get_pos()) < 2 then
  16. throw_player(self.object, v)
  17. v:set_hp(v:get_hp() - 1)
  18. end
  19. end
  20. end
  21. function pm.hurt_nearby_player_or_mob_not_wisp(self)
  22. local pos = self.object:get_pos()
  23. local objects = pm.get_nearby_objects(self, pos, 2)
  24. for k, v in ipairs(objects) do
  25. if v:is_player() then
  26. throw_player(self.object, v)
  27. v:set_hp(v:get_hp() - 1)
  28. else
  29. local ent = v:get_luaentity()
  30. if ent.mob and ent.name ~= "pm:follower" then
  31. local tcaps = tooldata["sword_steel"]
  32. v:punch(v, 1.0, tcaps, nil)
  33. end
  34. end
  35. end
  36. end
  37. function pm.heal_nearby_players(self)
  38. local pos = self.object:get_pos()
  39. local players = minetest.get_connected_players()
  40. for k, v in ipairs(players) do
  41. if vector.distance(pos, v:get_pos()) < 2 then
  42. v:set_hp(v:get_hp() + 1)
  43. end
  44. end
  45. end
  46. function pm.steal_nearby_item(self, target)
  47. if target then
  48. if target:is_player() then
  49. local inv = target:get_inventory()
  50. local max = inv:get_size("main")
  51. local idx = math.random(1, max)
  52. local stack = inv:get_stack("main", idx)
  53. if not passport.is_passport(stack:get_name()) then
  54. if stack:get_count() >= 10 then
  55. local item = stack:take_item(math.random(1, 10))
  56. inv:set_stack("main", idx, stack)
  57. minetest.item_drop(item, target, self.object:get_pos())
  58. end
  59. end
  60. else
  61. local ent = target:get_luaentity()
  62. if ent.name == "__builtin:item" then
  63. target:remove()
  64. end
  65. end
  66. end
  67. end
  68. function pm.explode_nearby_target(self, target)
  69. if target then
  70. tnt.boom(self.object:get_pos(), {
  71. radius = 2,
  72. damage_radius = 3,
  73. ignore_protection = false,
  74. ignore_on_blast = false,
  75. disable_drops = true,
  76. })
  77. end
  78. end
  79. function pm.commit_arson_at_target(pos)
  80. local p = vector.round(pos)
  81. p = minetest.find_node_near(pos, 1, "air", true)
  82. if p and not minetest.test_protection(p, "") then
  83. minetest.set_node(p, {name="fire:basic_flame"})
  84. end
  85. end
  86. function pm.teleport_player_to_prior_location(target)
  87. if target and target:is_player() then
  88. local pname = target:get_player_name()
  89. local positions = ap.get_position_list(pname)
  90. if #positions > 0 then
  91. local tpos = positions[1].pos
  92. preload_tp.preload_and_teleport(pname, tpos, 8, nil, nil, nil, true)
  93. end
  94. end
  95. end