javelin - Copy.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. minetest.register_craftitem("rangedweapons:thrown_javelin", {
  2. wield_scale = {x=2.0,y=2.0,z=1.0},
  3. inventory_image = "rangedweapons_thrown_javelin.png",
  4. })
  5. minetest.register_craftitem("rangedweapons:javelin", {
  6. description = "" ..core.colorize("#35cdff","Javelin\n") ..core.colorize("#FFFFFF", "Mele damage: 9\n") ..core.colorize("#FFFFFF", "Mele range: 5\n")..core.colorize("#FFFFFF", "Full punch interval: 1.25\n") ..core.colorize("#FFFFFF", "Ranged damage: 4-16\n") ..core.colorize("#FFFFFF", "Accuracy: 100%\n") ..core.colorize("#FFFFFF", "Mob knockback: 10\n") ..core.colorize("#FFFFFF", "Critical chance: 15%\n") ..core.colorize("#FFFFFF", "Critical damage: 25-45\n") ..core.colorize("#FFFFFF", "javelin survival rate: 95%\n")..core.colorize("#FFFFFF", "Projectile gravity: 4\n") ..core.colorize("#FFFFFF", "Projectile velocity: 20\n")..core.colorize("#ffc000", "Right-click to throw, Left-click to stab") ,
  7. wield_scale = {x=2.0,y=2.0,z=1.0},
  8. range = 5,
  9. stack_max= 10,
  10. inventory_image = "rangedweapons_javelin.png",
  11. on_secondary_use = function(itemstack, user, pointed_thing)
  12. if not minetest.setting_getbool("creative_mode") then itemstack:take_item()
  13. end
  14. if pointed_thing.type ~= "nothing" then
  15. local pointed = minetest.get_pointed_thing_position(pointed_thing)
  16. if vector.distance(user:getpos(), pointed) < 8 then
  17. return itemstack
  18. end
  19. end
  20. local pos = user:getpos()
  21. local dir = user:get_look_dir()
  22. local yaw = user:get_look_yaw()
  23. if pos and dir then
  24. pos.y = pos.y + 1.5
  25. local obj = minetest.add_entity(pos, "rangedweapons:javelin")
  26. if obj then
  27. minetest.sound_play("rangedweapons_throw", {object=obj})
  28. obj:setvelocity({x=dir.x * 20, y=dir.y * 20, z=dir.z * 20})
  29. obj:setacceleration({x=dir.x * -1, y=-4, z=dir.z * -1})
  30. obj:setyaw(yaw + math.pi)
  31. local ent = obj:get_luaentity()
  32. if ent then
  33. ent.player = ent.player or user
  34. end
  35. end
  36. end
  37. return itemstack
  38. end,
  39. tool_capabilities = {
  40. full_punch_interval = 1.25,
  41. max_drop_level = 0,
  42. groupcaps = {
  43. stabby = {times={[1]=0.25, [2]=0.50, [3]=0.75}, uses=0, maxlevel=1},
  44. },
  45. damage_groups = {fleshy=9,knockback=10},
  46. }
  47. })
  48. local rangedweapons_javelin = {
  49. physical = false,
  50. timer = 0,
  51. visual = "wielditem",
  52. visual_size = {x=0.5, y=0.5,},
  53. textures = {"rangedweapons:thrown_javelin"},
  54. lastpos= {},
  55. collisionbox = {0, 0, 0, 0, 0, 0},
  56. }
  57. rangedweapons_javelin.on_step = function(self, dtime)
  58. self.timer = self.timer + dtime
  59. local pos = self.object:getpos()
  60. local node = minetest.get_node(pos)
  61. if self.timer > 0.15 then
  62. local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1)
  63. for k, obj in pairs(objs) do
  64. if obj:get_luaentity() ~= nil then
  65. if obj:get_luaentity().name ~= "rangedweapons:javelin" and obj:get_luaentity().name ~= "__builtin:item" then
  66. if math.random(1, 100) <= 15 then
  67. local damage = math.random(25,45)
  68. obj:punch(self.object, 1.0, {
  69. full_punch_interval = 1.0,
  70. damage_groups= {fleshy = damage, knockback=20},
  71. }, nil)
  72. minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8})
  73. self.object:remove()
  74. if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
  75. minetest.add_item(self.lastpos, "rangedweapons:javelin")
  76. end
  77. else
  78. local damage = math.random(4,16)
  79. obj:punch(self.object, 1.0, {
  80. full_punch_interval = 1.0,
  81. damage_groups= {fleshy = damage, knockback=10},
  82. }, nil)
  83. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  84. self.object:remove()
  85. if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
  86. minetest.add_item(self.lastpos, "rangedweapons:javelin")
  87. end
  88. end
  89. end
  90. else
  91. if math.random(1, 100) <= 15 then
  92. local damage = math.random(25,45)
  93. obj:punch(self.object, 1.0, {
  94. full_punch_interval = 1.0,
  95. damage_groups= {fleshy = damage},
  96. }, nil)
  97. minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8})
  98. self.object:remove()
  99. if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
  100. minetest.add_item(self.lastpos, "rangedweapons:javelin")
  101. end
  102. else
  103. local damage = math.random(4,16)
  104. obj:punch(self.object, 1.0, {
  105. full_punch_interval = 1.0,
  106. damage_groups= {fleshy = damage},
  107. }, nil)
  108. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  109. self.object:remove()
  110. if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
  111. minetest.add_item(self.lastpos, "rangedweapons:javelin")
  112. end
  113. end
  114. end
  115. end
  116. end
  117. if self.lastpos.x ~= nil then
  118. if minetest.registered_nodes[node.name].walkable then
  119. if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
  120. minetest.add_item(self.lastpos, "rangedweapons:javelin")
  121. end
  122. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  123. self.object:remove()
  124. end
  125. end
  126. self.lastpos= {x = pos.x, y = pos.y, z = pos.z}
  127. end
  128. minetest.register_entity("rangedweapons:javelin", rangedweapons_javelin)