Add sniper_rifles mod (#453)

This commit is contained in:
ANAND 2020-04-22 07:31:27 +05:30 committed by GitHub
parent a417e857ef
commit e68fe87ea2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 203 additions and 0 deletions

View file

@ -45,6 +45,8 @@ ctf_classes.register("shooter", {
"shooter_guns:rifle", "shooter_guns:rifle",
"shooter_guns:machine_gun", "shooter_guns:machine_gun",
"shooter_guns:shotgun", "shooter_guns:shotgun",
"sniper_rifles:rifle_762",
"sniper_rifles:rifle_magnum"
}, },
shooter_multipliers = { shooter_multipliers = {

View file

@ -150,6 +150,24 @@ crafting.register_recipe({
level = 1, level = 1,
}) })
-- 7.62mm sniper rifle (unloaded)
crafting.register_recipe({
type = "inv",
output = "sniper_rifles:rifle_762",
items = { "default:steelblock", "default:bronze_ingot 5", "default:mese_crystal", "default:wood" },
always_known = true,
level = 1
})
-- Magnum sniper rifle (unloaded)
crafting.register_recipe({
type = "inv",
output = "sniper_rifles:rifle_magnum",
items = { "default:steelblock", "default:bronzeblock", "default:diamond", "default:wood" },
always_known = true,
level = 1,
})
-- Wooden ladder x4 -- Wooden ladder x4
crafting.register_recipe({ crafting.register_recipe({
type = "inv", type = "inv",

View file

@ -24,6 +24,9 @@ function ctf_treasure.get_default_treasures()
{ "shooter:ammo", 0.3, 2, { 1, 10 } }, { "shooter:ammo", 0.3, 2, { 1, 10 } },
{ "shooter:arrow_white", 0.5, 2, { 2, 18 } }, { "shooter:arrow_white", 0.5, 2, { 2, 18 } },
{ "sniper_rifles:rifle_762_loaded", 0.1, 2, 1 },
{ "sniper_rifles:rifle_magnum_loaded", 0.01, 2, 1 },
{ "medkits:medkit", 0.8, 5, 2 }, { "medkits:medkit", 0.8, 5, 2 },
} }
end end

View file

@ -77,6 +77,7 @@ function random_messages.read_messages()
"Change your class in your base by right clicking the home flag or typing /class.", "Change your class in your base by right clicking the home flag or typing /class.",
"Medics cause troops within 10 metres to regenerate health faster.", "Medics cause troops within 10 metres to regenerate health faster.",
"Hitting your enemy does more damage than not hitting them.", "Hitting your enemy does more damage than not hitting them.",
"Press right mouse button or double-tap the screen to activate scope while wielding a sniper rifle."
} }
end end

View file

@ -0,0 +1,22 @@
MIT License
Code : Copyright (c) 2019 Anand S, ClobberXD
Textures: Copyright (c) 2020 LoneWolfHT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,13 @@
# Sniper Rifles
This mod adds sniper rifles which behave like over-powered rifles, with the addition of the ability to toggle scoping using RMB (by default).
## Licenses
- Code license: MIT
- Media license: CC0 1.0
### Attributions
- `sniper_rifles_rifle.ogg` (`CC0 1.0`)
- Converted from [Battle Rifle.wav](https://freesound.org/people/morganpurkis/sounds/391725/) by [morganpurkis](https://freesound.org/people/morganpurkishttps://freesound.org/people/morganpurkis/sounds/391725/).

View file

@ -0,0 +1,104 @@
------------------
-- Private data --
------------------
-- Keep track of players who are scoping in, and their wielded item
local scoped = {}
-- Timer for scope-check globalstep
local timer = 0.2
-------------
-- Helpers --
-------------
local function show_scope(name, item_name, fov_mult)
local player = minetest.get_player_by_name(name)
if not player then
return
end
scoped[name] = item_name
-- e.g. if fov_mult == 8, then FOV = 1/8 * current_FOV, a.k.a 8x zoom
player:set_fov(1 / fov_mult, true)
player:hud_set_flags({ wielditem = false })
end
local function hide_scope(name)
local player = minetest.get_player_by_name(name)
if not player then
return
end
scoped[name] = nil
player:set_fov(0)
player:hud_set_flags({ wielditem = true })
end
local function on_rclick(item, placer, pointed_thing)
if pointed_thing.type == "object" then
return
end
local name = placer:get_player_name()
if scoped[name] then
hide_scope(name)
else
-- Remove _loaded suffix added to item name by shooter
local item_name = item:get_name():gsub("_loaded", "")
local fov_mult = shooter.registered_weapons[item_name].fov_mult
show_scope(name, item_name, fov_mult)
end
end
------------------
-- Sccope-check --
------------------
-- Hide scope if currently wielded item is not the same item
-- player wielded when scoping
local time = 0
minetest.register_globalstep(function(dtime)
time = time + dtime
if time < timer then
return
end
time = 0
for name, original_item in pairs(scoped) do
local player = minetest.get_player_by_name(name)
if not player then
scoped[name] = nil
else
local wielded_item = player:get_wielded_item():get_name():gsub("_loaded", "")
if wielded_item ~= original_item then
hide_scope(name)
end
end
end
end)
----------------------------
-- Rifle registration API --
----------------------------
sniper_rifles = {}
function sniper_rifles.register_rifle(name, def)
assert(def.fov_mult, "Rifle definition must contain FOV multiplier (fov_mult)!")
shooter.register_weapon(name, def)
-- Manually add extra fields to itemdef that shooter doesn't allow
-- Also modify the _loaded variant
local overrides = {
on_secondary_use = on_rclick,
wield_scale = vector.new(2, 2, 1.5)
}
minetest.override_item(name, overrides)
minetest.override_item(name .. "_loaded", overrides)
end
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/rifles.lua")

View file

@ -0,0 +1,3 @@
name = sniper_rifles
depends = shooter
description = This mod adds a couple of sniper rifles that make use of the zoom_fov player property to scope in.

View file

@ -0,0 +1,37 @@
-- Basic 7.62mm rifle
sniper_rifles.register_rifle("sniper_rifles:rifle_762", {
description = "Sniper rifle (7.62mm)",
inventory_image = "sniper_rifles_rifle_762.png",
fov_mult = 4,
spec = {
rounds = 30,
range = 300,
step = 30,
tool_caps = { full_punch_interval = 1.5, damage_groups = { fleshy = 12 } },
sounds = { shot = "sniper_rifles_rifle" },
particle = "shooter_bullet.png",
groups = {
cracky = 3, snappy = 2, crumbly = 2, choppy = 2,
fleshy = 1, oddly_breakable_by_hand = 1
}
}
})
-- Magnum rifle
sniper_rifles.register_rifle("sniper_rifles:rifle_magnum", {
description = "Sniper rifle (Magnum)",
inventory_image = "sniper_rifles_rifle_magnum.png",
fov_mult = 8,
spec = {
rounds = 20,
range = 400,
step = 30,
tool_caps = { full_punch_interval = 2, damage_groups = { fleshy = 16 } },
sounds = { shot = "sniper_rifles_rifle" },
particle = "shooter_bullet.png",
groups = {
cracky = 2, snappy = 1, crumbly = 1, choppy = 1,
fleshy = 1, oddly_breakable_by_hand = 1
}
}
})

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB