stomp.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. local stomp_radius = 1.5
  2. local function boast(stomper, target)
  3. local pname = stomper:get_player_name()
  4. if spam.test_key("stomper" .. pname .. "9353") then
  5. return
  6. end
  7. spam.mark_key("stomper" .. pname .. "9353", 30)
  8. if target:is_player() then
  9. local tname = target:get_player_name()
  10. minetest.chat_send_all("# Server: <" .. rename.gpn(pname) .. "> stomped on <" .. rename.gpn(tname) .. ">'s head.")
  11. else
  12. minetest.chat_send_all("# Server: <" .. rename.gpn(pname) .. "> stomped on a mob's head.")
  13. end
  14. end
  15. local function stomp_em(stomper, target, damage)
  16. -- Ignore dead players.
  17. if target:is_player() and target:get_hp() == 0 then
  18. return
  19. end
  20. target:punch(stomper, 1.0, {
  21. full_punch_interval = 1.0,
  22. damage_groups = {crush = damage, from_stomp = 0},
  23. }, nil)--{x=0, y=0.01, z=0})
  24. --minetest.log('stomping! ' .. target:get_player_name() .. ": " .. damage)
  25. if target:is_player() and target:get_hp() == 0 then
  26. boast(stomper, target)
  27. end
  28. end
  29. local function do_stomp(pname, pos, damage)
  30. local stomper = minetest.get_player_by_name(pname)
  31. if not stomper then
  32. return
  33. end
  34. local objs = minetest.get_objects_inside_radius(pos, stomp_radius)
  35. for k, v in ipairs(objs) do
  36. if v:is_player() and v:get_player_name() ~= pname then
  37. stomp_em(stomper, v, damage)
  38. else
  39. local ent = v:get_luaentity()
  40. if ent and ent.mob then
  41. stomp_em(stomper, v, damage)
  42. end
  43. end
  44. end
  45. end
  46. function armor.stomp_at(stomper, pos, damage)
  47. local pname = stomper:get_player_name()
  48. local objs = minetest.get_objects_inside_radius(pos, stomp_radius)
  49. local stomped = false
  50. -- Check if we're going to stomp anybody.
  51. for k, v in ipairs(objs) do
  52. if v:is_player() and v:get_player_name() ~= pname then
  53. -- Ignore the dead ones.
  54. if v:get_hp() > 0 then
  55. stomped = true
  56. end
  57. else
  58. local ent = v:get_luaentity()
  59. if ent and ent.mob then
  60. stomped = true
  61. end
  62. end
  63. end
  64. -- Must execute on the next server step, to avoid conflict with currently
  65. -- running armor/hp-change code.
  66. minetest.after(0, function() do_stomp(pname, pos, damage) end)
  67. return stomped
  68. end