mirror of
https://github.com/LoneWolfHT/grenades.git
synced 2024-11-22 06:43:45 +01:00
Add API.md and a few other things
This commit is contained in:
parent
0494e8088e
commit
f8c09f12de
18
.luacheckrc
Normal file
18
.luacheckrc
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
unused_args = false
|
||||||
|
allow_defined_top = true
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
"minetest",
|
||||||
|
}
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
string = {fields = {"split"}},
|
||||||
|
table = {fields = {"copy", "getn"}},
|
||||||
|
|
||||||
|
-- Builtin
|
||||||
|
"vector", "ItemStack",
|
||||||
|
"dump", "DIR_DELIM", "VoxelArea", "Settings",
|
||||||
|
|
||||||
|
-- MTG
|
||||||
|
"default", "sfinv", "creative",
|
||||||
|
}
|
23
API.md
Normal file
23
API.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#Grenades API
|
||||||
|
|
||||||
|
Still WIP. Please suggest new features here: https://forum.minetest.net/viewtopic.php?f=9&t=21466
|
||||||
|
|
||||||
|
##API
|
||||||
|
|
||||||
|
`grenades.register_grenade("name", { -- Name of the grenade (Like 'smoke' or 'flashbang')
|
||||||
|
description = "", -- A short description of the grenade.
|
||||||
|
image = "", -- The name of the grenade's texture
|
||||||
|
on_explode = function(pos, name)
|
||||||
|
-- This function is called when the grenade 'explodes'
|
||||||
|
-- <pos> the place the grenade 'exploded' at
|
||||||
|
-- <name> the name of the player that threw the grenade
|
||||||
|
end,
|
||||||
|
placeable = false, -- Optional, default is false
|
||||||
|
timeout = 5, -- Optional, default is 5
|
||||||
|
particle = { -- Adds particles in the grenade's trail
|
||||||
|
image = "grenades_smoke.png", -- The particle's image
|
||||||
|
life = 1, -- How long (seconds) it takes for the particle to disappear
|
||||||
|
size = 4, -- Size of the particle
|
||||||
|
glow = 0, -- brightens the texture in darkness
|
||||||
|
}
|
||||||
|
})`
|
115
grenades.lua
115
grenades.lua
@ -4,22 +4,16 @@ local regular = settings:get_bool("enable_regular_grenade")
|
|||||||
local flash = settings:get_bool("enable_flashbang_grenade")
|
local flash = settings:get_bool("enable_flashbang_grenade")
|
||||||
local smoke = settings:get_bool("enable_smoke_grenade")
|
local smoke = settings:get_bool("enable_smoke_grenade")
|
||||||
|
|
||||||
minetest.register_craftitem("grenades:gun_powder", {
|
|
||||||
description = "A dark powder used for crafting smoke grenades",
|
|
||||||
inventory_image = "grenades_gun_powder.png"
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
-- Regular Grenade
|
||||||
type = "shapeless",
|
|
||||||
output = "grenades:gun_powder",
|
|
||||||
recipe = {"default:coal_lump", "default:coal_lump", "default:coal_lump", "default:coal_lump"},
|
|
||||||
})
|
|
||||||
|
|
||||||
if not regular or regular == true then
|
if not regular or regular == true then
|
||||||
grenades.register_grenade("regular", {
|
grenades.register_grenade("regular", {
|
||||||
description = "A regular grenade (Kills anyone near where it explodes)",
|
description = "A regular grenade (Kills anyone near where it explodes)",
|
||||||
image = "grenades_regular.png",
|
image = "grenades_regular.png",
|
||||||
on_explode = function(pos, player, self)
|
on_explode = function(pos, name)
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
|
||||||
local radius = 3
|
local radius = 3
|
||||||
|
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
@ -47,25 +41,21 @@ if not regular or regular == true then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
recipe = {
|
|
||||||
{"", "default:steel_ingot", ""},
|
|
||||||
{"default:steel_ingot", "default:coal_lump", "default:steel_ingot"},
|
|
||||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
|
|
||||||
},
|
|
||||||
timeout = 3
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Flashbang Grenade
|
||||||
|
|
||||||
if not flash or flash == true then
|
if not flash or flash == true then
|
||||||
grenades.register_grenade("flashbang", {
|
grenades.register_grenade("flashbang", {
|
||||||
description = "A flashbang grenade (Blinds all who look at the explosion)",
|
description = "A flashbang grenade (Blinds all who look at the explosion)",
|
||||||
image = "grenades_flashbang.png",
|
image = "grenades_flashbang.png",
|
||||||
on_explode = function(pos, player, self)
|
on_explode = function(pos, name)
|
||||||
for k, v in ipairs(minetest.get_objects_inside_radius(pos, 15)) do
|
for k, v in ipairs(minetest.get_objects_inside_radius(pos, 15)) do
|
||||||
if v:is_player() and v:get_hp() > 0 then
|
if v:is_player() and v:get_hp() > 0 then
|
||||||
local playerdir = vector.round(v:get_look_dir())
|
local playerdir = vector.round(v:get_look_dir())
|
||||||
local grenadedir = vector.round(vector.direction(v:get_pos(), pos))
|
local grenadedir = vector.round(vector.direction(v:get_pos(), pos))
|
||||||
local name = v:get_player_name()
|
local pname = v:get_player_name()
|
||||||
|
|
||||||
if playerdir.x == grenadedir.x and playerdir.z == grenadedir.z then
|
if playerdir.x == grenadedir.x and playerdir.z == grenadedir.z then
|
||||||
for i = 1, 3, 1 do
|
for i = 1, 3, 1 do
|
||||||
@ -80,29 +70,26 @@ if not flash or flash == true then
|
|||||||
})
|
})
|
||||||
|
|
||||||
minetest.after(1.6*i, function()
|
minetest.after(1.6*i, function()
|
||||||
if minetest.get_player_by_name(name) then
|
if minetest.get_player_by_name(pname) then
|
||||||
minetest.get_player_by_name(name):hud_remove(key)
|
minetest.get_player_by_name(pname):hud_remove(key)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
recipe = {
|
|
||||||
{"", "default:steel_ingot", ""},
|
|
||||||
{"default:steel_ingot", "default:torch", "default:steel_ingot"},
|
|
||||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
|
|
||||||
},
|
|
||||||
timeout = 3
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Smoke Grenade
|
||||||
|
|
||||||
if not smoke or smoke == true then
|
if not smoke or smoke == true then
|
||||||
grenades.register_grenade("smoke", {
|
grenades.register_grenade("smoke", {
|
||||||
description = "A smoke grenade (Generates a lot of smoke around the detonation area)",
|
description = "A smoke grenade (Generates a lot of smoke around the detonation area)",
|
||||||
image = "grenades_smoke_grenade.png",
|
image = "grenades_smoke_grenade.png",
|
||||||
on_explode = function(pos, player, self)
|
on_explode = function(pos, name)
|
||||||
for i = 0, 5, 1 do
|
for i = 0, 5, 1 do
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = 100,
|
amount = 100,
|
||||||
@ -124,11 +111,73 @@ if not smoke or smoke == true then
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
recipe = {
|
particle = {
|
||||||
{"", "default:steel_ingot", ""},
|
image = "grenades_smoke.png",
|
||||||
{"default:steel_ingot", "grenades:gun_powder", "default:steel_ingot"},
|
life = 1,
|
||||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
|
size = 4,
|
||||||
},
|
glow = 0,
|
||||||
timeout = 3
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- 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 = "shapeless",
|
||||||
|
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 = "shapeless",
|
||||||
|
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 = "shapeless",
|
||||||
|
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"},
|
||||||
|
})
|
||||||
|
end
|
44
init.lua
44
init.lua
@ -1,5 +1,3 @@
|
|||||||
local settings = minetest.settings
|
|
||||||
|
|
||||||
grenades = {}
|
grenades = {}
|
||||||
|
|
||||||
local function throw_grenade(name, player)
|
local function throw_grenade(name, player)
|
||||||
@ -16,7 +14,7 @@ local function throw_grenade(name, player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function grenades.register_grenade(name, def)
|
function grenades.register_grenade(name, def)
|
||||||
if not def.type then def.type = "shaped" end
|
if not def.timeout then def.timeout = 5 end
|
||||||
|
|
||||||
local grenade_entity = {
|
local grenade_entity = {
|
||||||
physical = true,
|
physical = true,
|
||||||
@ -28,7 +26,7 @@ function grenades.register_grenade(name, def)
|
|||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local player
|
local obj = self.object
|
||||||
|
|
||||||
if self.timer then
|
if self.timer then
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
@ -36,20 +34,29 @@ function grenades.register_grenade(name, def)
|
|||||||
self.timer = dtime
|
self.timer = dtime
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.thrower_name then
|
if def.particle then
|
||||||
player = minetest.get_player_by_name(self.thrower_name)
|
minetest.add_particle({
|
||||||
|
pos = obj:get_pos(),
|
||||||
|
velocity = vector.divide(obj:get_velocity(), 2),
|
||||||
|
acceleration = vector.divide(obj:get_acceleration(), -5),
|
||||||
|
expirationtime = def.particle.life,
|
||||||
|
size = def.particle.size,
|
||||||
|
collisiondetection = true,
|
||||||
|
collision_removal = true,
|
||||||
|
vertical = false,
|
||||||
|
texture = def.particle.image,
|
||||||
|
glow = def.particle.glow
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
if player and (self.timer > def.timeout or node.name ~= "air") then
|
|
||||||
def.on_explode(pos, player, self)
|
|
||||||
|
|
||||||
self.object:remove()
|
if self.timer > def.timeout or node.name ~= "air" then
|
||||||
elseif self.timer > def.timeout or node.name ~= "air" then
|
def.on_explode(pos, self.thrower_name)
|
||||||
self.object:remove()
|
|
||||||
|
obj:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
||||||
|
|
||||||
if def.placeable == true then
|
if def.placeable == true then
|
||||||
@ -70,7 +77,6 @@ function grenades.register_grenade(name, def)
|
|||||||
groups = {oddly_breakable_by_hand = 2},
|
groups = {oddly_breakable_by_hand = 2},
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local player_name = user:get_player_name()
|
local player_name = user:get_player_name()
|
||||||
local inv = user:get_inventory()
|
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
local grenade = throw_grenade("grenades:grenade_"..name, user)
|
local grenade = throw_grenade("grenades:grenade_"..name, user)
|
||||||
@ -93,7 +99,6 @@ function grenades.register_grenade(name, def)
|
|||||||
inventory_image = def.image,
|
inventory_image = def.image,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local player_name = user:get_player_name()
|
local player_name = user:get_player_name()
|
||||||
local inv = user:get_inventory()
|
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
local grenade = throw_grenade("grenades:grenade_"..name, user)
|
local grenade = throw_grenade("grenades:grenade_"..name, user)
|
||||||
@ -109,15 +114,6 @@ function grenades.register_grenade(name, def)
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
if def.recipe and (not settings:get_bool("enable_grenade_recipes") or
|
|
||||||
settings:get_bool("enable_grenade_recipes") == true) then
|
|
||||||
minetest.register_craft({
|
|
||||||
type = def.type,
|
|
||||||
output = "grenades:grenade_"..name,
|
|
||||||
recipe = def.recipe
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(minetest.get_modpath("grenades").."/grenades.lua")
|
dofile(minetest.get_modpath("grenades").."/grenades.lua")
|
||||||
|
Loading…
Reference in New Issue
Block a user