diff --git a/LICENSE.txt b/LICENSE.txt index 6b0af2d..55a2b42 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -13,3 +13,7 @@ License Sounds: freesound.org GUNSHOT.WAV by erkanozan - CC0 1.0 Universal (CC0 1.0) + winchester-rifle-cock-reload.wav by MentalSanityOff - CC0 1.0 Universal (CC0 1.0) + + trigger-with-hammer-fall.wav by Nanashi - CC0 1.0 Universal (CC0 1.0) + diff --git a/README.txt b/README.txt index 8c114a3..54e397a 100644 --- a/README.txt +++ b/README.txt @@ -32,7 +32,7 @@ Pistol: [shooter:pistol] | | M | +---+---+ -Riffle: [shooter:riffle] +Rifle: [shooter:rifle] +---+---+---+ | S | | | diff --git a/depends.txt b/depends.txt index e69de29..845d8d2 100644 --- a/depends.txt +++ b/depends.txt @@ -0,0 +1,2 @@ +default +tnt diff --git a/init.lua b/init.lua index f1eb1a7..7464baf 100644 --- a/init.lua +++ b/init.lua @@ -1,87 +1,70 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/shooter.lua") -minetest.register_tool("shooter:pistol", { +shooter:register_weapon("shooter:pistol", { description = "Pistol", inventory_image = "shooter_pistol.png", - on_use = function(itemstack, user, pointed_thing) - local name = user:get_player_name() - shooter:fire_weapon(user, pointed_thing, { - name = name, - range = 100, - step = 20, - tool_caps = {full_punch_interval=0.5, damage_groups={fleshy=2}}, - groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3}, - sound = "shooter_pistol", - particle = "shooter_cap.png", - }) - itemstack:add_wear(328) -- 200 Rounds - return itemstack - end, + rounds = 200, + spec = { + range = 100, + step = 20, + tool_caps = {full_punch_interval=0.5, damage_groups={fleshy=2}}, + groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3}, + sound = "shooter_pistol", + particle = "shooter_cap.png", + }, }) -minetest.register_tool("shooter:riffle", { - description = "Riffle", - inventory_image = "shooter_riffle.png", - on_use = function(itemstack, user, pointed_thing) - local name = user:get_player_name() - shooter:fire_weapon(user, pointed_thing, { - name = name, - range = 200, - step = 30, - tool_caps = {full_punch_interval=1.0, damage_groups={fleshy=3}}, - groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2}, - sound = "shooter_riffle", - particle = "shooter_bullet.png", - }) - itemstack:add_wear(656) -- 100 Rounds - return itemstack - end, +shooter:register_weapon("shooter:rifle", { + description = "Rifle", + inventory_image = "shooter_rifle.png", + rounds = 100, + spec = { + range = 200, + step = 30, + tool_caps = {full_punch_interval=1.0, damage_groups={fleshy=3}}, + groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2}, + sound = "shooter_rifle", + particle = "shooter_bullet.png", + }, }) -minetest.register_tool("shooter:shotgun", { +shooter:register_weapon("shooter:shotgun", { description = "Shotgun", inventory_image = "shooter_shotgun.png", - on_use = function(itemstack, user, pointed_thing) - local name = user:get_player_name() - shooter:fire_weapon(user, pointed_thing, { - name = name, - range = 50, - step = 15, - tool_caps = {full_punch_interval=1.5, damage_groups={fleshy=4}}, - groups = {cracky=3, snappy=2, crumbly=2, choppy=2, fleshy=1, oddly_breakable_by_hand=1}, - sound = "shooter_shotgun", - particle = "smoke_puff.png", - }) - itemstack:add_wear(1311) -- 50 Rounds - return itemstack - end, + rounds = 50, + spec = { + range = 50, + step = 15, + tool_caps = {full_punch_interval=1.5, damage_groups={fleshy=4}}, + groups = {cracky=3, snappy=2, crumbly=2, choppy=2, fleshy=1, oddly_breakable_by_hand=1}, + sound = "shooter_shotgun", + particle = "smoke_puff.png", + }, }) -minetest.register_tool("shooter:machine_gun", { +shooter:register_weapon("shooter:machine_gun", { description = "Sub Machine Gun", inventory_image = "shooter_smgun.png", - on_use = function(itemstack, user, pointed_thing) - local name = user:get_player_name() - for i = 0, 0.45, 0.15 do - minetest.after(i, function() - shooter:fire_weapon(user, pointed_thing, { - name = name, - range = 100, - step = 20, - tool_caps = {full_punch_interval=0.1, damage_groups={fleshy=2}}, - groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3}, - sound = "shooter_pistol", - particle = "shooter_cap.png", - }) - end) - end - itemstack:add_wear(328) -- 4 x 200 Rounds - return itemstack - end, + rounds = 50, + shots = 4, + spec = { + range = 100, + step = 20, + tool_caps = {full_punch_interval=0.125, damage_groups={fleshy=2}}, + groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3}, + sound = "shooter_pistol", + particle = "shooter_cap.png", + }, }) +minetest.register_craftitem("shooter:ammo", { + description = "Ammo pack", + inventory_image = "shooter_ammo.png", +}) + + minetest.register_craft({ - output = "shooter:pistol", + output = "shooter:pistol 1 65535", recipe = { {"default:steel_ingot", "default:steel_ingot"}, {"", "default:mese_crystal"}, @@ -89,7 +72,7 @@ minetest.register_craft({ }) minetest.register_craft({ - output = "shooter:riffle", + output = "shooter:riffle 1 65535", recipe = { {"default:steel_ingot", "", ""}, {"", "default:bronze_ingot", ""}, @@ -98,7 +81,7 @@ minetest.register_craft({ }) minetest.register_craft({ - output = "shooter:shotgun", + output = "shooter:shotgun 1 65535", recipe = { {"default:steel_ingot", "", ""}, {"", "default:steel_ingot", ""}, @@ -107,7 +90,7 @@ minetest.register_craft({ }) minetest.register_craft({ - output = "shooter:machine_gun", + output = "shooter:machine_gun 1 65535", recipe = { {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, {"", "default:bronze_ingot", "default:mese_crystal"}, @@ -115,3 +98,10 @@ minetest.register_craft({ }, }) +minetest.register_craft({ + output = "shooter:ammo", + recipe = { + {"tnt:gunpowder", "default:bronze_ingot"}, + }, +}) + diff --git a/shooter.lua b/shooter.lua index 77a7ab0..bb991c8 100644 --- a/shooter.lua +++ b/shooter.lua @@ -182,6 +182,45 @@ local function process_round(round) end end +function shooter:register_weapon(name, def) + local shots = def.shots or 1 + local wear = math.ceil(65534 / def.rounds) + local max_wear = (def.rounds - 1) * wear + minetest.register_tool(name, { + description = def.description, + inventory_image = def.inventory_image, + on_use = function(itemstack, user, pointed_thing) + if itemstack:get_wear() < max_wear then + def.spec.name = user:get_player_name() + if shots > 1 then + local step = def.spec.tool_caps.full_punch_interval + for i = 0, step * (shots), step do + minetest.after(i, function() + shooter:fire_weapon(user, pointed_thing, def.spec) + end) + end + else + shooter:fire_weapon(user, pointed_thing, def.spec) + end + itemstack:add_wear(wear) + else + local inv = user:get_inventory() + if inv then + local stack = "shooter:ammo 1" + if inv:contains_item("main", stack) then + minetest.sound_play("shooter_reload", {object=user}) + inv:remove_item("main", stack) + itemstack:replace(name.." 1 1") + else + minetest.sound_play("shooter_click", {object=user}) + end + end + end + return itemstack + end, + }) +end + function shooter:fire_weapon(user, pointed_thing, def) if shooter.shots[def.name] then if shooter.time < shooter.shots[def.name] then diff --git a/sounds/shooter_click.ogg b/sounds/shooter_click.ogg new file mode 100644 index 0000000..8e60db8 Binary files /dev/null and b/sounds/shooter_click.ogg differ diff --git a/sounds/shooter_reload.ogg b/sounds/shooter_reload.ogg new file mode 100644 index 0000000..47f7245 Binary files /dev/null and b/sounds/shooter_reload.ogg differ diff --git a/sounds/shooter_riffle.ogg b/sounds/shooter_rifle.ogg similarity index 100% rename from sounds/shooter_riffle.ogg rename to sounds/shooter_rifle.ogg diff --git a/textures/shooter_riffle.png b/textures/shooter_rifle.png similarity index 100% rename from textures/shooter_riffle.png rename to textures/shooter_rifle.png