Include shot origin in returned gunspec

This commit is contained in:
stujones11 2019-03-23 17:47:31 +00:00
parent e76fa31ae3
commit adb8e476f9
2 changed files with 10 additions and 3 deletions

View file

@ -151,6 +151,12 @@ Used by `shooter.register_weapon`
on_hit = function(pointed_thing, spec, dir) on_hit = function(pointed_thing, spec, dir)
-- May be used for arbitary shot effects like knock-back, etc. -- May be used for arbitary shot effects like knock-back, etc.
-- Return `true` to override built-in damage effects -- 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, end,
spec = { spec = {
-- Weapon specifications -- Weapon specifications

View file

@ -259,6 +259,9 @@ local function fire_weapon(player, itemstack, spec, extended)
return return
end end
pos.y = pos.y + config.camera_height 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}) minetest.sound_play(spec.sound, {object=player})
if spec.bullet_image then if spec.bullet_image then
minetest.add_particle({ minetest.add_particle({
@ -272,7 +275,7 @@ local function fire_weapon(player, itemstack, spec, extended)
end end
process_round({ process_round({
spec = spec, spec = spec,
pos = vector.add(pos, dir), pos = vector.new(spec.origin),
dir = dir, dir = dir,
dist = 0, dist = 0,
}) })
@ -288,8 +291,6 @@ local function fire_weapon(player, itemstack, spec, extended)
if not spec.automatic or not shooting[spec.user] then if not spec.automatic or not shooting[spec.user] then
return return
end end
local interval = spec.tool_caps.full_punch_interval
shots[spec.user] = minetest.get_us_time() / 1000000 + interval
minetest.after(interval, function(...) minetest.after(interval, function(...)
if shooting[spec.user] then if shooting[spec.user] then
local arg = {...} local arg = {...}