From f09cd7a37c22322a1cfcc7c97797ecd6ec94f309 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 8 Sep 2024 07:06:00 -0500 Subject: [PATCH] Make arrows damage players, update API documentation, fix several crashes that occurred when arrows hit a player --- mods/ITEMS/mcl_bows/arrow.lua | 15 +-------------- mods/ITEMS/vl_projectile/api.md | 1 + mods/ITEMS/vl_projectile/init.lua | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index cb3561cbd..93f735124 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -15,20 +15,6 @@ local STUCK_RECHECK_TIME = 5 local YAW_OFFSET = -math.pi/2 -local function random_arrow_positions(positions, placement) - if positions == "x" then - return math.random(-4, 4) - elseif positions == "y" then - return math.random(0, 10) - end - if placement == "front" and positions == "z" then - return 3 - elseif placement == "back" and positions == "z" then - return -3 - end - return 0 -end - local mod_awards = minetest.get_modpath("awards") and minetest.get_modpath("mcl_achievements") local mod_button = minetest.get_modpath("mesecons_button") @@ -143,6 +129,7 @@ local arrow_entity = { _vl_projectile = { survive_collision = true, sticks_in_players = true, + damages_players = true, damage_groups = function(self) return { fleshy = self._damage } end, diff --git a/mods/ITEMS/vl_projectile/api.md b/mods/ITEMS/vl_projectile/api.md index ed2f4484c..da0dbcfc5 100644 --- a/mods/ITEMS/vl_projectile/api.md +++ b/mods/ITEMS/vl_projectile/api.md @@ -14,6 +14,7 @@ Arguments: * `liquid_drag`: if true, apply drag from liquid nodes to the projectile * `survive_collision`: if this field is `false` or `nil`, the projectile will be removed after a collision. * `sticks_in_players`: if true, the projectile will stick into players after colliding with them. + * `damages_players`: if true, the projectile will deal damage to players. * `damage_groups`: damage group information to use for `punch()`. May be a function of type `function(projectile, entity_def, projectile_def, obj)` that returns dynamic damange group information. * `allow_punching`: will the projectile punch entities it collides with. May be a function of type `function(projectile, entity_def, projectile_def, obj)`. diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index 79da4e953..03e6da173 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -102,6 +102,20 @@ local function damage_particles(pos, is_critical) }) end end +local function random_arrow_positions(positions, placement) + if positions == "x" then + return math.random(-4, 4) + elseif positions == "y" then + return math.random(0, 10) + end + if placement == "front" and positions == "z" then + return 3 + elseif placement == "back" and positions == "z" then + return -3 + end + return 0 +end + local function random_hit_positions(positions, placement) if positions == "x" then return math.random(-4, 4) @@ -144,7 +158,7 @@ local function handle_player_sticking(self, entity_def, projectile_def, entity) end) -- Handle blocking projectiles - if mcl_shields.is_blocking(obj) then + if mcl_shields.is_blocking(entity) then self._blocked = true self.object:set_velocity(vector.multiply(self.object:get_velocity(), -0.25)) return @@ -175,7 +189,7 @@ local function handle_player_sticking(self, entity_def, projectile_def, entity) self._z_rotation = math.random(-30, 30) self._y_rotation = math.random( -30, 30) self.object:set_attach( - obj, self._attach_parent, + entity, self._attach_parent, vector.new(self._x_position, self._y_position, random_arrow_positions("z", placement)), vector.new(0, self._rotation_station + self._y_rotation, self._z_rotation) ) @@ -262,7 +276,7 @@ local function handle_entity_collision(self, entity_def, projectile_def, object) -- Apply damage -- Note: Damage blocking for shields is handled in mcl_shields with an mcl_damage modifier local do_damage = false - if object:is_player() and projectile_def.hits_players and self_vl_projectile.owner ~= hit:get_player_name() then + if object:is_player() and projectile_def.damanges_players and self_vl_projectile.owner ~= object:get_player_name() then do_damage = true handle_player_sticking(self, entity_def, projectile_def, object)