items.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. local stick_knockback = 30 --multiplier for how hard the stick hits
  2. local stick_vault_reach = 3 -- how close to the pointed node must the player be to vault
  3. local stick_vault_timeout = 1 -- int timer for how long the vault cannot be used after it is used
  4. local allow_swap_distance = 4 -- if an opponent is within this distance, then if the player uses the pushstick with the shift key pressed, the players switch positions.
  5. minetest.register_craftitem("sumo:pushstick", {
  6. description = "Push Stick",
  7. inventory_image = "default_stick.png",
  8. stack_max = 1,
  9. wield_scale = {x = 2, y = 2, z = 2},
  10. on_drop = function() end,
  11. on_use = function(itemstack, user, pointed_thing)
  12. local sound = 'swish'..math.random(1,4)
  13. minetest.sound_play(sound, {
  14. pos = user:get_pos(),
  15. max_hear_distance = 5,
  16. gain = 10.0,
  17. })
  18. if pointed_thing == nil then return end
  19. if pointed_thing.type == 'object' then
  20. if minetest.is_player(pointed_thing.ref) == true then
  21. local dir = user:get_look_dir()
  22. local keys = user:get_player_control()
  23. local swap = false
  24. local hitted_pos = pointed_thing.ref:get_pos()
  25. local hitter_pos = user:get_pos()
  26. if keys.sneak and vector.distance(hitted_pos,hitter_pos) < allow_swap_distance then
  27. swap = true
  28. user:move_to(hitted_pos, true)
  29. pointed_thing.ref:move_to(hitter_pos, true)
  30. pointed_thing.ref:add_player_velocity(vector.multiply({x = -dir.x, y = dir.y, z= -dir.z}, stick_knockback/2))
  31. else
  32. pointed_thing.ref:add_player_velocity(vector.multiply(dir, stick_knockback))
  33. if not swap then
  34. local sound = 'thwack'..math.random(1,3)
  35. minetest.sound_play(sound, {
  36. pos = user:get_pos(),
  37. max_hear_distance = 10,
  38. gain = 10.0,
  39. })
  40. local sound = 'hurt'..math.random(1,2)
  41. minetest.sound_play(sound, {
  42. to_player = pointed_thing.ref:get_player_name(),
  43. pos = user:get_pos(),
  44. gain = 10.0,
  45. })
  46. end
  47. end
  48. end
  49. end
  50. end,
  51. on_place = function(itemstack, placer, pointed_thing)
  52. if pointed_thing == nil then return end
  53. if pointed_thing.type == 'node' then
  54. if vector.distance(pointed_thing.under, placer:get_pos()) < stick_vault_reach then
  55. local first_use = false
  56. local imeta = itemstack:get_meta()
  57. local old_time = imeta:get_int('old_time')
  58. local current_time = minetest.get_gametime()
  59. if old_time == 0 or old_time == nil then
  60. first_use = true
  61. end
  62. if first_use or current_time > old_time + stick_vault_timeout then
  63. local lookvect = placer:get_look_dir()
  64. local pushvect = vector.normalize( {x=lookvect.x, z=lookvect.z, y= math.sqrt(1-(lookvect.y*lookvect.y))})
  65. --gives a unit vector that is 90 deg offset in the vert direction
  66. local force = 10 * vector.length(vector.normalize( {x=lookvect.x, z=lookvect.z, y= 0}))
  67. placer:add_player_velocity(vector.multiply(pushvect, force))
  68. --update the staff time for next check
  69. local sound = 'jump'..math.random(1,2)
  70. minetest.sound_play(sound, {
  71. pos = placer:get_pos(),
  72. max_hear_distance = 10,
  73. gain = 10.0,
  74. })
  75. imeta:set_int('old_time', current_time)
  76. return itemstack
  77. end
  78. end
  79. end
  80. end,
  81. })