Create shooter.get_weapon_spec(player, weapon_name) as a Lua hook

This commit is contained in:
rubenwardy 2019-03-24 18:15:39 +00:00 committed by stujones11
parent e24279e205
commit 182f50daa8
2 changed files with 12 additions and 1 deletions

View file

@ -122,6 +122,8 @@ API Documentation
### Methods
* `shooter.register_weapon(name, definition)`: Register a shooting weapon. -- See "Weapon Definition"
* `shooter.get_weapon_spec(player, weaponname)`: Gets the spec for a particular weapon.
Override to add support for per-player specs.
* `shooter.get_configuration(config)`: Loads matching config settings into a table ref `config`
* `shooter.spawn_particles(pos, particles)`: Adds particles at the specified position
* `particles` is an optional table of overrides for `shooter.default_particles`

View file

@ -83,7 +83,7 @@ shooter.register_weapon = function(name, def)
itemstack = def.on_use(itemstack, user, pointed_thing)
end
if itemstack then
local spec = table.copy(def.spec)
local spec = shooter.get_weapon_spec(name)
if shooter.fire_weapon(user, itemstack, spec) then
itemstack:add_wear(def.spec.wear)
if itemstack:get_count() == 0 then
@ -118,6 +118,15 @@ shooter.register_weapon = function(name, def)
})
end
shooter.get_weapon_spec = function(_, name)
local def = shooter.registered_weapons[name]
if not def then
return nil
end
return table.copy(def.spec)
end
shooter.get_configuration = function(conf)
for k, v in pairs(conf) do
local setting = minetest.settings:get("shooter_"..k)