Create shooter.get_weapon_spec(player, weapon_name) as a Lua hook
This commit is contained in:
parent
e24279e205
commit
182f50daa8
2 changed files with 12 additions and 1 deletions
|
@ -122,6 +122,8 @@ API Documentation
|
||||||
### Methods
|
### Methods
|
||||||
|
|
||||||
* `shooter.register_weapon(name, definition)`: Register a shooting weapon. -- See "Weapon Definition"
|
* `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.get_configuration(config)`: Loads matching config settings into a table ref `config`
|
||||||
* `shooter.spawn_particles(pos, particles)`: Adds particles at the specified position
|
* `shooter.spawn_particles(pos, particles)`: Adds particles at the specified position
|
||||||
* `particles` is an optional table of overrides for `shooter.default_particles`
|
* `particles` is an optional table of overrides for `shooter.default_particles`
|
||||||
|
|
|
@ -83,7 +83,7 @@ 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 = table.copy(def.spec)
|
local spec = shooter.get_weapon_spec(name)
|
||||||
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
|
||||||
|
@ -118,6 +118,15 @@ shooter.register_weapon = function(name, def)
|
||||||
})
|
})
|
||||||
end
|
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)
|
shooter.get_configuration = function(conf)
|
||||||
for k, v in pairs(conf) do
|
for k, v in pairs(conf) do
|
||||||
local setting = minetest.settings:get("shooter_"..k)
|
local setting = minetest.settings:get("shooter_"..k)
|
||||||
|
|
Loading…
Reference in a new issue