Add a simple ammo system and fix misspelling of rifle

This commit is contained in:
stujones11 2014-06-29 21:28:09 +01:00
parent 33a2cf2933
commit 272061541a
9 changed files with 106 additions and 71 deletions

View file

@ -13,3 +13,7 @@ License Sounds: freesound.org
GUNSHOT.WAV by erkanozan - CC0 1.0 Universal (CC0 1.0) 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)

View file

@ -32,7 +32,7 @@ Pistol: [shooter:pistol]
| | M | | | M |
+---+---+ +---+---+
Riffle: [shooter:riffle] Rifle: [shooter:rifle]
+---+---+---+ +---+---+---+
| S | | | | S | | |

View file

@ -0,0 +1,2 @@
default
tnt

130
init.lua
View file

@ -1,87 +1,70 @@
dofile(minetest.get_modpath(minetest.get_current_modname()).."/shooter.lua") dofile(minetest.get_modpath(minetest.get_current_modname()).."/shooter.lua")
minetest.register_tool("shooter:pistol", { shooter:register_weapon("shooter:pistol", {
description = "Pistol", description = "Pistol",
inventory_image = "shooter_pistol.png", inventory_image = "shooter_pistol.png",
on_use = function(itemstack, user, pointed_thing) rounds = 200,
local name = user:get_player_name() spec = {
shooter:fire_weapon(user, pointed_thing, { range = 100,
name = name, step = 20,
range = 100, tool_caps = {full_punch_interval=0.5, damage_groups={fleshy=2}},
step = 20, groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3},
tool_caps = {full_punch_interval=0.5, damage_groups={fleshy=2}}, sound = "shooter_pistol",
groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3}, particle = "shooter_cap.png",
sound = "shooter_pistol", },
particle = "shooter_cap.png",
})
itemstack:add_wear(328) -- 200 Rounds
return itemstack
end,
}) })
minetest.register_tool("shooter:riffle", { shooter:register_weapon("shooter:rifle", {
description = "Riffle", description = "Rifle",
inventory_image = "shooter_riffle.png", inventory_image = "shooter_rifle.png",
on_use = function(itemstack, user, pointed_thing) rounds = 100,
local name = user:get_player_name() spec = {
shooter:fire_weapon(user, pointed_thing, { range = 200,
name = name, step = 30,
range = 200, tool_caps = {full_punch_interval=1.0, damage_groups={fleshy=3}},
step = 30, groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2},
tool_caps = {full_punch_interval=1.0, damage_groups={fleshy=3}}, sound = "shooter_rifle",
groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2}, particle = "shooter_bullet.png",
sound = "shooter_riffle", },
particle = "shooter_bullet.png",
})
itemstack:add_wear(656) -- 100 Rounds
return itemstack
end,
}) })
minetest.register_tool("shooter:shotgun", { shooter:register_weapon("shooter:shotgun", {
description = "Shotgun", description = "Shotgun",
inventory_image = "shooter_shotgun.png", inventory_image = "shooter_shotgun.png",
on_use = function(itemstack, user, pointed_thing) rounds = 50,
local name = user:get_player_name() spec = {
shooter:fire_weapon(user, pointed_thing, { range = 50,
name = name, step = 15,
range = 50, tool_caps = {full_punch_interval=1.5, damage_groups={fleshy=4}},
step = 15, groups = {cracky=3, snappy=2, crumbly=2, choppy=2, fleshy=1, oddly_breakable_by_hand=1},
tool_caps = {full_punch_interval=1.5, damage_groups={fleshy=4}}, sound = "shooter_shotgun",
groups = {cracky=3, snappy=2, crumbly=2, choppy=2, fleshy=1, oddly_breakable_by_hand=1}, particle = "smoke_puff.png",
sound = "shooter_shotgun", },
particle = "smoke_puff.png",
})
itemstack:add_wear(1311) -- 50 Rounds
return itemstack
end,
}) })
minetest.register_tool("shooter:machine_gun", { shooter:register_weapon("shooter:machine_gun", {
description = "Sub Machine Gun", description = "Sub Machine Gun",
inventory_image = "shooter_smgun.png", inventory_image = "shooter_smgun.png",
on_use = function(itemstack, user, pointed_thing) rounds = 50,
local name = user:get_player_name() shots = 4,
for i = 0, 0.45, 0.15 do spec = {
minetest.after(i, function() range = 100,
shooter:fire_weapon(user, pointed_thing, { step = 20,
name = name, tool_caps = {full_punch_interval=0.125, damage_groups={fleshy=2}},
range = 100, groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3},
step = 20, sound = "shooter_pistol",
tool_caps = {full_punch_interval=0.1, damage_groups={fleshy=2}}, particle = "shooter_cap.png",
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,
}) })
minetest.register_craftitem("shooter:ammo", {
description = "Ammo pack",
inventory_image = "shooter_ammo.png",
})
minetest.register_craft({ minetest.register_craft({
output = "shooter:pistol", output = "shooter:pistol 1 65535",
recipe = { recipe = {
{"default:steel_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot"},
{"", "default:mese_crystal"}, {"", "default:mese_crystal"},
@ -89,7 +72,7 @@ minetest.register_craft({
}) })
minetest.register_craft({ minetest.register_craft({
output = "shooter:riffle", output = "shooter:riffle 1 65535",
recipe = { recipe = {
{"default:steel_ingot", "", ""}, {"default:steel_ingot", "", ""},
{"", "default:bronze_ingot", ""}, {"", "default:bronze_ingot", ""},
@ -98,7 +81,7 @@ minetest.register_craft({
}) })
minetest.register_craft({ minetest.register_craft({
output = "shooter:shotgun", output = "shooter:shotgun 1 65535",
recipe = { recipe = {
{"default:steel_ingot", "", ""}, {"default:steel_ingot", "", ""},
{"", "default:steel_ingot", ""}, {"", "default:steel_ingot", ""},
@ -107,7 +90,7 @@ minetest.register_craft({
}) })
minetest.register_craft({ minetest.register_craft({
output = "shooter:machine_gun", output = "shooter:machine_gun 1 65535",
recipe = { recipe = {
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{"", "default:bronze_ingot", "default:mese_crystal"}, {"", "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"},
},
})

View file

@ -182,6 +182,45 @@ local function process_round(round)
end end
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) function shooter:fire_weapon(user, pointed_thing, def)
if shooter.shots[def.name] then if shooter.shots[def.name] then
if shooter.time < shooter.shots[def.name] then if shooter.time < shooter.shots[def.name] then

BIN
sounds/shooter_click.ogg Normal file

Binary file not shown.

BIN
sounds/shooter_reload.ogg Normal file

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 420 B

After

Width:  |  Height:  |  Size: 420 B