Make get_weapon_spec a little more robust

This commit is contained in:
stujones11 2019-03-26 18:41:29 +00:00
parent 35ddb6c038
commit 4d8aa37f72

View file

@ -83,7 +83,8 @@ shooter.register_weapon = function(name, def)
itemstack = def.on_use(itemstack, user, pointed_thing) itemstack = def.on_use(itemstack, user, pointed_thing)
end end
if itemstack then if itemstack then
local spec = shooter.get_weapon_spec(nil, name) local spec = shooter.get_weapon_spec(nil, name) or
table.copy(def.spec)
if shooter.fire_weapon(user, itemstack, spec) then if shooter.fire_weapon(user, itemstack, spec) then
itemstack:add_wear(def.spec.wear) itemstack:add_wear(def.spec.wear)
if itemstack:get_count() == 0 then if itemstack:get_count() == 0 then
@ -120,10 +121,9 @@ end
shooter.get_weapon_spec = function(_, name) shooter.get_weapon_spec = function(_, name)
local def = shooter.registered_weapons[name] local def = shooter.registered_weapons[name]
if not def then if def then
return nil
end
return table.copy(def.spec) return table.copy(def.spec)
end
end end
shooter.get_configuration = function(conf) shooter.get_configuration = function(conf)