Add a simple ammo system and fix misspelling of rifle
This commit is contained in:
parent
33a2cf2933
commit
272061541a
9 changed files with 106 additions and 71 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ Pistol: [shooter:pistol]
|
|||
| | M |
|
||||
+---+---+
|
||||
|
||||
Riffle: [shooter:riffle]
|
||||
Rifle: [shooter:rifle]
|
||||
|
||||
+---+---+---+
|
||||
| S | | |
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
default
|
||||
tnt
|
130
init.lua
130
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"},
|
||||
},
|
||||
})
|
||||
|
||||
|
|
39
shooter.lua
39
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
|
||||
|
|
BIN
sounds/shooter_click.ogg
Normal file
BIN
sounds/shooter_click.ogg
Normal file
Binary file not shown.
BIN
sounds/shooter_reload.ogg
Normal file
BIN
sounds/shooter_reload.ogg
Normal file
Binary file not shown.
Before Width: | Height: | Size: 420 B After Width: | Height: | Size: 420 B |
Loading…
Reference in a new issue