From 2f5d0464721eebe38a868be876f2ffbc5fc1f17c Mon Sep 17 00:00:00 2001 From: stujones11 Date: Fri, 22 Mar 2019 20:46:47 +0000 Subject: [PATCH] Allow on_hit to override builtin damage --- shooter/README.md | 1 + shooter/api.lua | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/shooter/README.md b/shooter/README.md index 7916d2e..760ed55 100644 --- a/shooter/README.md +++ b/shooter/README.md @@ -150,6 +150,7 @@ Used by `shooter.register_weapon` }, on_hit = function(pointed_thing, spec, dir) -- May be used for arbitary shot effects like knock-back, etc. + -- Return `true` to override built-in damage effects end, spec = { -- Weapon specifications diff --git a/shooter/api.lua b/shooter/api.lua index 02c5780..4f63590 100644 --- a/shooter/api.lua +++ b/shooter/api.lua @@ -206,6 +206,12 @@ shooter.is_valid_object = function(object) end local function process_hit(pointed_thing, spec, dir) + local def = minetest.registered_items[spec.name] or {} + if type(def.on_hit) == "function" then + if def.on_hit(pointed_thing, spec, dir) == true then + return + end + end if pointed_thing.type == "node" and config.allow_nodes == true then local pos = minetest.get_pointed_thing_position(pointed_thing, false) shooter.punch_node(pos, spec) @@ -223,10 +229,6 @@ local function process_hit(pointed_thing, spec, dir) end end end - local def = minetest.registered_items[spec.name] or {} - if type(def.on_hit) == "function" then - return def.on_hit(pointed_thing, spec, dir) - end end local function process_round(round)