grenades/grenades.lua

214 lines
7.0 KiB
Lua
Raw Normal View History

2018-11-22 20:58:20 +01:00
local settings = minetest.settings
2018-11-23 16:56:44 +01:00
local regular = settings:get_bool("enable_regular_grenade")
local flash = settings:get_bool("enable_flashbang_grenade")
local smoke = settings:get_bool("enable_smoke_grenade")
2018-11-24 16:52:46 +01:00
-- Regular Grenade
2018-11-23 16:56:44 +01:00
if not regular or regular == true then
2018-11-22 20:58:20 +01:00
grenades.register_grenade("regular", {
2019-01-13 22:09:39 +01:00
description = "Regular grenade (Kills anyone near blast)",
2018-11-22 20:58:20 +01:00
image = "grenades_regular.png",
2018-11-24 16:52:46 +01:00
on_explode = function(pos, name)
2019-01-13 22:09:39 +01:00
if not name or not pos then
return
end
2018-11-24 16:52:46 +01:00
local player = minetest.get_player_by_name(name)
2019-01-13 22:09:39 +01:00
local radius = 6
2018-11-23 16:56:44 +01:00
2018-11-22 20:58:20 +01:00
minetest.add_particlespawner({
amount = 20,
time = 0.5,
2018-11-23 16:56:44 +01:00
minpos = vector.subtract(pos, radius),
maxpos = vector.add(pos, radius),
2019-01-13 22:09:39 +01:00
minvel = {x = 0, y = 5, z = 0},
maxvel = {x = 0, y = 7, z = 0},
minacc = {x = 0, y = 1, z = 0},
maxacc = {x = 0, y = 1, z = 0},
2018-11-22 20:58:20 +01:00
minexptime = 0.3,
maxexptime = 0.6,
2018-11-23 16:56:44 +01:00
minsize = 7,
maxsize = 10,
collisiondetection = true,
2018-11-23 16:56:44 +01:00
collision_removal = false,
2018-11-22 20:58:20 +01:00
vertical = false,
texture = "grenades_smoke.png",
})
2019-01-13 22:09:39 +01:00
minetest.sound_play("boom", {
pos = pos,
gain = 1.0,
max_hear_distance = 32,
})
2018-11-23 16:56:44 +01:00
for k, v in ipairs(minetest.get_objects_inside_radius(pos, radius)) do
2018-11-22 20:58:20 +01:00
if v:is_player() and v:get_hp() > 0 then
2019-01-13 22:09:39 +01:00
v:punch(player, 2, {damage_groups = {fleshy = 24 - (vector.distance(pos, v:get_pos()) * 2)}}, nil)
2018-11-22 20:58:20 +01:00
end
end
end,
})
end
2018-11-24 16:52:46 +01:00
-- Flashbang Grenade
2018-11-23 16:56:44 +01:00
if not flash or flash == true then
2018-11-22 20:58:20 +01:00
grenades.register_grenade("flashbang", {
2019-01-13 22:09:39 +01:00
description = "Flashbang grenade (Blinds all who look at blast)",
2018-11-22 20:58:20 +01:00
image = "grenades_flashbang.png",
2018-11-24 16:52:46 +01:00
on_explode = function(pos, name)
2019-01-13 22:09:39 +01:00
for k, v in ipairs(minetest.get_objects_inside_radius(pos, 20)) do
2018-11-22 20:58:20 +01:00
if v:is_player() and v:get_hp() > 0 then
local playerdir = vector.round(v:get_look_dir())
local grenadedir = vector.round(vector.direction(v:get_pos(), pos))
2018-11-24 16:52:46 +01:00
local pname = v:get_player_name()
2018-11-22 20:58:20 +01:00
2019-01-13 22:09:39 +01:00
minetest.sound_play("glasslike_break", {
pos = pos,
gain = 1.0,
max_hear_distance = 32,
})
if vector.equals(playerdir, grenadedir) then
for i = 0, 5, 1 do
local key = v:hud_add({
hud_elem_type = "image",
2019-01-13 22:09:39 +01:00
position = {x = 0, y = 0},
name = "flashbang hud "..pname,
scale = {x = -200, y = -200},
text = "grenades_white.png^[opacity:"..tostring(255 - (i * 13)),
alignment = {x = 0, y = 0},
offset = {x = 0, y = 0}
})
2019-01-13 22:09:39 +01:00
minetest.after(2 * i, function()
2018-11-24 16:52:46 +01:00
if minetest.get_player_by_name(pname) then
minetest.get_player_by_name(pname):hud_remove(key)
end
end)
end
2018-11-22 20:58:20 +01:00
end
2018-11-24 16:52:46 +01:00
2018-11-22 20:58:20 +01:00
end
end
end,
})
end
2018-11-24 16:52:46 +01:00
-- Smoke Grenade
2018-11-23 16:56:44 +01:00
if not smoke or smoke == true then
grenades.register_grenade("smoke", {
2019-01-13 22:09:39 +01:00
description = "Smoke grenade (Generates smoke around blast site)",
image = "grenades_smoke_grenade.png",
2018-11-24 16:52:46 +01:00
on_explode = function(pos, name)
2019-01-13 22:09:39 +01:00
minetest.sound_play("glasslike_break", {
pos = pos,
gain = 1.0,
max_hear_distance = 32,
})
minetest.sound_play("hiss", {
pos = pos,
gain = 1.0,
max_hear_distance = 32,
})
for i = 0, 5, 1 do
minetest.add_particlespawner({
2019-01-13 22:09:39 +01:00
amount = 30,
time = 11,
minpos = vector.subtract(pos, 3),
maxpos = vector.add(pos, 3),
minvel = {x = 0, y = 2, z = 0},
maxvel = {x = 0, y = 3, z = 0},
minacc = {x = 1, y = 0.2, z = 1},
maxacc = {x = 1, y = 0.2, z = 1},
minexptime = 0.3,
2019-01-13 22:09:39 +01:00
maxexptime = 0.5,
minsize = 90,
maxsize = 100,
collisiondetection = false,
collision_removal = false,
vertical = false,
texture = "grenades_smoke.png",
})
end
end,
2018-11-24 16:52:46 +01:00
particle = {
image = "grenades_smoke.png",
life = 1,
size = 4,
glow = 0,
interval = 5,
2018-11-24 16:52:46 +01:00
}
})
end
2018-11-24 16:52:46 +01:00
--
-- Crafts
--
if not settings:get_bool("enable_grenade_recipes") or settings:get_bool("enable_grenade_recipes") == true then
-- Regular Grenade
if not regular or regular == true then
minetest.register_craft({
type = "shaped",
2018-11-24 16:52:46 +01:00
output = "grenades:grenade_regular",
recipe = {
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "default:coal_lump", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
},
})
end
-- Smoke Grenade
if not smoke or smoke == true then
minetest.register_craft({
type = "shaped",
2018-11-24 16:52:46 +01:00
output = "grenades:grenade_smoke",
recipe = {
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "grenades:gun_powder", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
}
})
end
--Flashbang Grenade
if not flash or flash == true then
minetest.register_craft({
type = "shaped",
2018-11-24 16:52:46 +01:00
output = "grenades:grenade_flashbang",
recipe = {
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "default:torch", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
},
})
end
-- Other
minetest.register_craftitem("grenades:gun_powder", {
description = "A dark powder used for crafting some grenades",
inventory_image = "grenades_gun_powder.png"
})
minetest.register_craft({
type = "shapeless",
output = "grenades:gun_powder",
recipe = {"default:coal_lump", "default:coal_lump", "default:coal_lump", "default:coal_lump"},
})
2019-01-13 22:09:39 +01:00
end