1
0
Fork 0

Make arrows damage players, update API documentation, fix several crashes that occurred when arrows hit a player

This commit is contained in:
teknomunk 2024-09-08 07:06:00 -05:00
parent e212f3dd08
commit 29bfd6ce21
3 changed files with 19 additions and 17 deletions

View File

@ -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,

View File

@ -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)`.

View File

@ -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)