diff --git a/shooter/README.md b/shooter/README.md index 28eb383..257656f 100644 --- a/shooter/README.md +++ b/shooter/README.md @@ -103,6 +103,7 @@ API Documentation ### Methods * `shooter.register_weapon(name, definition)`: Register a shooting weapon. -- See "Weapon Definition" +* `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` * `shooter.play_node_sound(node, pos)`: Plays the registered 'dug' sound for the node at `pos` diff --git a/shooter/api.lua b/shooter/api.lua index ec310fc..184fc6d 100644 --- a/shooter/api.lua +++ b/shooter/api.lua @@ -79,7 +79,7 @@ shooter.register_weapon = function(name, def) inventory_image = def.inventory_image, on_use = function(itemstack, user, pointed_thing) if type(def.on_use) == "function" then - itemstack = def.on_use, pointed_thing) + itemstack = def.on_use(itemstack, user, pointed_thing) end local spec = table.copy(def.spec) if shooter.fire_weapon(user, itemstack, spec) then @@ -115,6 +115,21 @@ shooter.register_weapon = function(name, def) }) end +shooter.get_configuration = function(conf) + for k, v in pairs(conf) do + local setting = minetest.settings:get("shooter_"..k) + if type(v) == "number" then + setting = tonumber(setting) + elseif type(v) == "boolean" then + setting = minetest.settings:get_bool("shooter_"..k) + end + if setting ~= nil then + conf[k] = setting + end + end + return conf +end + shooter.spawn_particles = function(pos, particles) particles = particles or {} if not config.enable_particle_fx == true or particles.amount == 0 then diff --git a/shooter/init.lua b/shooter/init.lua index c5bc68d..b79ac22 100644 --- a/shooter/init.lua +++ b/shooter/init.lua @@ -50,17 +50,7 @@ end -- Load Configuration -for name, config in pairs(shooter.config) do - local setting = minetest.settings:get("shooter_"..name) - if type(config) == "number" then - setting = tonumber(setting) - elseif type(config) == "boolean" then - setting = minetest.settings:get_bool("shooter_"..name) - end - if setting ~= nil then - shooter.config[name] = setting - end -end +shooter.config = shooter.get_configuration(shooter.config) shooter.default_particles.texture = shooter.config.explosion_texture -- Legacy Entity Support diff --git a/shooter_crossbow/README.txt b/shooter_crossbow/README.txt index b76f4f2..d7d8fff 100644 --- a/shooter_crossbow/README.txt +++ b/shooter_crossbow/README.txt @@ -5,6 +5,18 @@ Depends: shooter, wool, dye Adds a crossbow with colored arrows. +Configuration +============= + +Override the following default settings by adding them to your minetest.conf file + +* `shooter_crossbow_uses = 50`: Number of crossbow uses +* `shooter_arrow_lifetime = 180`: Arrow exipiry time in seconds +* `shooter_arrow_fleshy = 2`: Arrow 'fleshy' damage level +* `shooter_arrow_object_attach = false`: Attach arrows to objects when hit + * Experimental, currently does not work well with oversized selection boxes! + + Crafting ======== diff --git a/shooter_crossbow/init.lua b/shooter_crossbow/init.lua index 049f134..a175657 100644 --- a/shooter_crossbow/init.lua +++ b/shooter_crossbow/init.lua @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., local config = { crossbow_uses = 50, arrow_lifetime = 180, + arrow_fleshy = 2, arrow_object_attach = false, } @@ -30,13 +31,13 @@ for name, _ in pairs(config) do if minetest.global_exists(global) then config[name] = _G[global] end - local setting = minetest.settings:get("shooter_"..name) - if type(setting) == "string" then - config[name] = tonumber(setting) - end end -local arrow_tool_caps = {damage_groups={fleshy=2}} +-- Load configuration + +config = shooter.get_configuration(config) + +local arrow_tool_caps = {damage_groups={fleshy=config.arrow_fleshy}} if minetest.global_exists("SHOOTER_ARROW_TOOL_CAPS") then arrow_tool_caps = table.copy(SHOOTER_ARROW_TOOL_CAPS) end