diff --git a/shooter/README.md b/shooter/README.md index 760ed55..7fce1e2 100644 --- a/shooter/README.md +++ b/shooter/README.md @@ -151,6 +151,12 @@ 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 + -- `pointed_thing`: Returned by `minetest.raycast()` + -- `spec`: Gunspec of the weapon used including addition fields + -- `name`: Name of the weapon item, eg. `shooter_guns:rifle` + -- `user`: Name of the player that fired the weapon + -- `origin`: Initial starting position of the shot + -- `dir`: Direction of the virtual shot before impact end, spec = { -- Weapon specifications diff --git a/shooter/api.lua b/shooter/api.lua index 4f63590..ac0f034 100644 --- a/shooter/api.lua +++ b/shooter/api.lua @@ -259,6 +259,9 @@ local function fire_weapon(player, itemstack, spec, extended) return end pos.y = pos.y + config.camera_height + spec.origin = vector.add(pos, dir) + shots[spec.user] = minetest.get_us_time() / 1000000 + + spec.tool_caps.full_punch_interval minetest.sound_play(spec.sound, {object=player}) if spec.bullet_image then minetest.add_particle({ @@ -272,7 +275,7 @@ local function fire_weapon(player, itemstack, spec, extended) end process_round({ spec = spec, - pos = vector.add(pos, dir), + pos = vector.new(spec.origin), dir = dir, dist = 0, }) @@ -288,8 +291,6 @@ local function fire_weapon(player, itemstack, spec, extended) if not spec.automatic or not shooting[spec.user] then return end - local interval = spec.tool_caps.full_punch_interval - shots[spec.user] = minetest.get_us_time() / 1000000 + interval minetest.after(interval, function(...) if shooting[spec.user] then local arg = {...}