mirror of
https://github.com/LoneWolfHT/grenades.git
synced 2024-11-22 06:43:45 +01:00
Update!
This commit is contained in:
parent
f2ab183daa
commit
b43885841d
4
API.md
4
API.md
@ -4,7 +4,7 @@ Still WIP. Please suggest new features here: https://forum.minetest.net/viewtopi
|
|||||||
|
|
||||||
##API
|
##API
|
||||||
|
|
||||||
`grenades.register_grenade("name", { -- Name of the grenade (Like 'smoke' or 'flashbang')
|
grenades.register_grenade("name", { -- Name of the grenade (Like 'smoke' or 'flashbang')
|
||||||
description = "", -- A short description of the grenade.
|
description = "", -- A short description of the grenade.
|
||||||
image = "", -- The name of the grenade's texture
|
image = "", -- The name of the grenade's texture
|
||||||
on_explode = function(pos, name)
|
on_explode = function(pos, name)
|
||||||
@ -21,4 +21,4 @@ Still WIP. Please suggest new features here: https://forum.minetest.net/viewtopi
|
|||||||
glow = 0, -- Brightens the texture in darkness
|
glow = 0, -- Brightens the texture in darkness
|
||||||
interval = 5, -- How long it takes before a particle can be added
|
interval = 5, -- How long it takes before a particle can be added
|
||||||
}
|
}
|
||||||
})`
|
})
|
||||||
|
89
grenades.lua
89
grenades.lua
@ -9,22 +9,26 @@ local smoke = settings:get_bool("enable_smoke_grenade")
|
|||||||
|
|
||||||
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 = "Regular grenade (Kills anyone near blast)",
|
||||||
image = "grenades_regular.png",
|
image = "grenades_regular.png",
|
||||||
on_explode = function(pos, name)
|
on_explode = function(pos, name)
|
||||||
|
if not name or not pos then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
|
|
||||||
local radius = 3
|
local radius = 6
|
||||||
|
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = 20,
|
amount = 20,
|
||||||
time = 0.5,
|
time = 0.5,
|
||||||
minpos = vector.subtract(pos, radius),
|
minpos = vector.subtract(pos, radius),
|
||||||
maxpos = vector.add(pos, radius),
|
maxpos = vector.add(pos, radius),
|
||||||
minvel = {x=0, y=5, z=0},
|
minvel = {x = 0, y = 5, z = 0},
|
||||||
maxvel = {x=0, y=7, z=0},
|
maxvel = {x = 0, y = 7, z = 0},
|
||||||
minacc = {x=0, y=1, z=0},
|
minacc = {x = 0, y = 1, z = 0},
|
||||||
maxacc = {x=0, y=1, z=0},
|
maxacc = {x = 0, y = 1, z = 0},
|
||||||
minexptime = 0.3,
|
minexptime = 0.3,
|
||||||
maxexptime = 0.6,
|
maxexptime = 0.6,
|
||||||
minsize = 7,
|
minsize = 7,
|
||||||
@ -35,9 +39,15 @@ if not regular or regular == true then
|
|||||||
texture = "grenades_smoke.png",
|
texture = "grenades_smoke.png",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.sound_play("boom", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1.0,
|
||||||
|
max_hear_distance = 32,
|
||||||
|
})
|
||||||
|
|
||||||
for k, v in ipairs(minetest.get_objects_inside_radius(pos, radius)) do
|
for k, v in ipairs(minetest.get_objects_inside_radius(pos, radius)) do
|
||||||
if v:is_player() and v:get_hp() > 0 then
|
if v:is_player() and v:get_hp() > 0 then
|
||||||
v:punch(player, 2, {damage_groups = {fleshy = 20-vector.distance(pos, v:get_pos())}}, nil)
|
v:punch(player, 2, {damage_groups = {fleshy = 24 - (vector.distance(pos, v:get_pos()) * 2)}}, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@ -48,28 +58,34 @@ end
|
|||||||
|
|
||||||
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 = "Flashbang grenade (Blinds all who look at blast)",
|
||||||
image = "grenades_flashbang.png",
|
image = "grenades_flashbang.png",
|
||||||
on_explode = function(pos, name)
|
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, 20)) 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 pname = v:get_player_name()
|
local pname = v:get_player_name()
|
||||||
|
|
||||||
if playerdir.x == grenadedir.x and playerdir.z == grenadedir.z then
|
minetest.sound_play("glasslike_break", {
|
||||||
for i = 1, 3, 1 do
|
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({
|
local key = v:hud_add({
|
||||||
hud_elem_type = "image",
|
hud_elem_type = "image",
|
||||||
position = {x=0, 0},
|
position = {x = 0, y = 0},
|
||||||
name = "death_list_hud",
|
name = "flashbang hud "..pname,
|
||||||
scale = {x=1000, y=1000},
|
scale = {x = -200, y = -200},
|
||||||
text = "grenades_white_"..tostring(i)..".png",
|
text = "grenades_white.png^[opacity:"..tostring(255 - (i * 13)),
|
||||||
alignment = {x=0, y=0},
|
alignment = {x = 0, y = 0},
|
||||||
offset = {x=0, y=0}
|
offset = {x = 0, y = 0}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.after(1.6*i, function()
|
minetest.after(2 * i, function()
|
||||||
if minetest.get_player_by_name(pname) then
|
if minetest.get_player_by_name(pname) then
|
||||||
minetest.get_player_by_name(pname):hud_remove(key)
|
minetest.get_player_by_name(pname):hud_remove(key)
|
||||||
end
|
end
|
||||||
@ -87,22 +103,35 @@ end
|
|||||||
|
|
||||||
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 = "Smoke grenade (Generates smoke around blast site)",
|
||||||
image = "grenades_smoke_grenade.png",
|
image = "grenades_smoke_grenade.png",
|
||||||
on_explode = function(pos, name)
|
on_explode = function(pos, name)
|
||||||
|
|
||||||
|
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
|
for i = 0, 5, 1 do
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = 100,
|
amount = 30,
|
||||||
time = 10,
|
time = 11,
|
||||||
minpos = vector.subtract(pos, 3.5),
|
minpos = vector.subtract(pos, 3),
|
||||||
maxpos = vector.add(pos, 3.5),
|
maxpos = vector.add(pos, 3),
|
||||||
minvel = {x=0, y=2, z=0},
|
minvel = {x = 0, y = 2, z = 0},
|
||||||
maxvel = {x=0, y=3, z=0},
|
maxvel = {x = 0, y = 3, z = 0},
|
||||||
minacc = {x=1, y=0.2, z=1},
|
minacc = {x = 1, y = 0.2, z = 1},
|
||||||
maxacc = {x=1, y=0.2, z=1},
|
maxacc = {x = 1, y = 0.2, z = 1},
|
||||||
minexptime = 0.3,
|
minexptime = 0.3,
|
||||||
maxexptime = 1,
|
maxexptime = 0.5,
|
||||||
minsize = 100,
|
minsize = 90,
|
||||||
maxsize = 100,
|
maxsize = 100,
|
||||||
collisiondetection = false,
|
collisiondetection = false,
|
||||||
collision_removal = false,
|
collision_removal = false,
|
||||||
@ -181,4 +210,4 @@ if not settings:get_bool("enable_grenade_recipes") or settings:get_bool("enable_
|
|||||||
output = "grenades:gun_powder",
|
output = "grenades:gun_powder",
|
||||||
recipe = {"default:coal_lump", "default:coal_lump", "default:coal_lump", "default:coal_lump"},
|
recipe = {"default:coal_lump", "default:coal_lump", "default:coal_lump", "default:coal_lump"},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
203
init.lua
203
init.lua
@ -1,127 +1,120 @@
|
|||||||
grenades = {}
|
grenades = {}
|
||||||
|
|
||||||
local function throw_grenade(name, player)
|
local function throw_grenade(name, player)
|
||||||
local dir = player:get_look_dir()
|
local dir = player:get_look_dir()
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local obj = minetest.add_entity({x=pos.x+dir.x, y=pos.y+1.3, z=pos.z+dir.z}, name)
|
local obj = minetest.add_entity({x = pos.x + dir.x, y = pos.y + 1.6, z = pos.z + dir.z}, name)
|
||||||
local yaw = player:get_look_yaw()
|
|
||||||
|
|
||||||
obj:setvelocity({x=dir.x * 16, y=dir.y * 16, z=dir.z * 16})
|
obj:set_velocity({x = dir.x * 40, y = dir.y * 40, z = dir.z * 40})
|
||||||
obj:setacceleration({x=dir.x * -3, y=-17, z=dir.z * -3})
|
obj:set_acceleration({x = dir.x * -12, y = -41, z = dir.z * -12})
|
||||||
obj:setyaw(yaw + math.pi)
|
|
||||||
|
|
||||||
return(obj:get_luaentity())
|
return(obj:get_luaentity())
|
||||||
end
|
end
|
||||||
|
|
||||||
function grenades.register_grenade(name, def)
|
function grenades.register_grenade(name, def)
|
||||||
if not def.timeout then def.timeout = 5 end
|
if not def.timeout then
|
||||||
|
def.timeout = 5
|
||||||
|
end
|
||||||
|
|
||||||
local grenade_entity = {
|
local grenade_entity = {
|
||||||
physical = true,
|
physical = false,
|
||||||
timer = 0,
|
collide_with_objects = true,
|
||||||
visual = "sprite",
|
timer = 0,
|
||||||
visual_size = {x=1, y=1, z=1},
|
visual = "sprite",
|
||||||
textures = {def.image},
|
visual_size = {x = 1, y = 1, z = 1},
|
||||||
collisionbox = {1, 1, 1, 1, 1, 1},
|
textures = {def.image},
|
||||||
on_step = function(self, dtime)
|
collisionbox = {1, 1, 1, 1, 1, 1},
|
||||||
local pos = self.object:getpos()
|
on_step = function(self, dtime)
|
||||||
local node = minetest.get_node(pos)
|
local obj = self.object
|
||||||
local obj = self.object
|
local pos = obj:get_pos()
|
||||||
|
local node = minetest.get_node(vector.add(pos, vector.normalize(obj:get_velocity())))
|
||||||
|
|
||||||
if self.particle == nil then
|
if self.particle == nil then
|
||||||
self.particle = 0
|
self.particle = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.timer then
|
if self.timer then
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
else
|
else
|
||||||
self.timer = dtime
|
self.timer = dtime
|
||||||
end
|
end
|
||||||
|
|
||||||
if def.particle and self.particle >= 4 then
|
if def.particle and self.particle >= 4 then
|
||||||
self.particle = 0
|
self.particle = 0
|
||||||
|
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
pos = obj:get_pos(),
|
pos = obj:get_pos(),
|
||||||
velocity = vector.divide(obj:get_velocity(), 2),
|
velocity = vector.divide(obj:get_velocity(), 2),
|
||||||
acceleration = vector.divide(obj:get_acceleration(), -5),
|
acceleration = vector.divide(obj:get_acceleration(), -5),
|
||||||
expirationtime = def.particle.life,
|
expirationtime = def.particle.life,
|
||||||
size = def.particle.size,
|
size = def.particle.size,
|
||||||
collisiondetection = true,
|
collisiondetection = true,
|
||||||
collision_removal = true,
|
collision_removal = true,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
texture = def.particle.image,
|
texture = def.particle.image,
|
||||||
glow = def.particle.glow
|
glow = def.particle.glow
|
||||||
})
|
})
|
||||||
elseif def.particle and self.particle < def.particle.interval then
|
elseif def.particle and self.particle < def.particle.interval then
|
||||||
self.particle = self.particle + 1
|
self.particle = self.particle + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.timer > def.timeout or node.name ~= "air" then
|
if self.timer > def.timeout or node.name ~= "air" then
|
||||||
def.on_explode(pos, self.thrower_name)
|
if self.thrower_name then
|
||||||
|
minetest.log("[Grenades] A grenade thrown by "..self.thrower_name..
|
||||||
obj:remove()
|
" is exploding at "..minetest.pos_to_string(pos))
|
||||||
end
|
def.on_explode(pos, self.thrower_name)
|
||||||
end
|
else
|
||||||
}
|
minetest.chat_send_all(minetest.colorize("red", "[Error] self.thrower_name on line 62"..
|
||||||
|
" (grenades/init.lua) was nil. Removing grenade"))
|
||||||
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
minetest.log("[Error] self.thrower_name on line 62 (grenades/init.lua) was nil. Removing grenade")
|
||||||
|
|
||||||
if def.placeable == true then
|
|
||||||
minetest.register_node("grenades:grenade_"..name, {
|
|
||||||
description = def.description,
|
|
||||||
stack_max = 1,
|
|
||||||
range = 4,
|
|
||||||
paramtype = "light",
|
|
||||||
sunlight_propagates = true,
|
|
||||||
walkable = false,
|
|
||||||
drawtype = "plantlike",
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3},
|
|
||||||
},
|
|
||||||
tiles = {def.image},
|
|
||||||
inventory_image = def.image,
|
|
||||||
groups = {oddly_breakable_by_hand = 2},
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
|
||||||
local player_name = user:get_player_name()
|
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
|
||||||
local grenade = throw_grenade("grenades:grenade_"..name, user)
|
|
||||||
grenade.timer = 0
|
|
||||||
grenade.thrower_name = player_name
|
|
||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
|
||||||
itemstack = ""
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return itemstack
|
obj:remove()
|
||||||
end
|
end
|
||||||
})
|
end
|
||||||
else
|
}
|
||||||
minetest.register_craftitem("grenades:grenade_"..name, {
|
|
||||||
description = def.description,
|
|
||||||
stack_max = 1,
|
|
||||||
range = 4,
|
|
||||||
inventory_image = def.image,
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
|
||||||
local player_name = user:get_player_name()
|
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
||||||
local grenade = throw_grenade("grenades:grenade_"..name, user)
|
|
||||||
grenade.timer = 0
|
|
||||||
grenade.thrower_name = player_name
|
|
||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
local newdef = {}
|
||||||
itemstack = ""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return itemstack
|
newdef.description = def.description
|
||||||
end
|
newdef.stack_max = 1
|
||||||
})
|
newdef.range = 4
|
||||||
end
|
newdef.inventory_image = def.image
|
||||||
|
newdef.on_use = function(itemstack, user, pointed_thing)
|
||||||
|
local player_name = user:get_player_name()
|
||||||
|
|
||||||
|
if pointed_thing.type ~= "node" then
|
||||||
|
local grenade = throw_grenade("grenades:grenade_"..name, user)
|
||||||
|
grenade.timer = 0
|
||||||
|
grenade.thrower_name = player_name
|
||||||
|
|
||||||
|
if not minetest.settings:get_bool("creative_mode") then
|
||||||
|
itemstack = ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
if def.placeable == true then
|
||||||
|
|
||||||
|
newdef.tiles = {def.image}
|
||||||
|
newdef.selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3},
|
||||||
|
}
|
||||||
|
newdef.groups = {oddly_breakable_by_hand = 2}
|
||||||
|
newdef.paramtype = "light"
|
||||||
|
newdef.sunlight_propagates = true
|
||||||
|
newdef.walkable = false
|
||||||
|
newdef.drawtype = "plantlike"
|
||||||
|
|
||||||
|
minetest.register_node("grenades:grenade_"..name, newdef)
|
||||||
|
else
|
||||||
|
minetest.register_craftitem("grenades:grenade_"..name, newdef)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(minetest.get_modpath("grenades").."/grenades.lua")
|
dofile(minetest.get_modpath("grenades").."/grenades.lua")
|
||||||
|
BIN
sounds/boom.ogg
Normal file
BIN
sounds/boom.ogg
Normal file
Binary file not shown.
BIN
sounds/glasslike_break.ogg
Normal file
BIN
sounds/glasslike_break.ogg
Normal file
Binary file not shown.
BIN
sounds/hiss.ogg
Normal file
BIN
sounds/hiss.ogg
Normal file
Binary file not shown.
Before Width: | Height: | Size: 102 B After Width: | Height: | Size: 102 B |
Binary file not shown.
Before Width: | Height: | Size: 102 B |
Binary file not shown.
Before Width: | Height: | Size: 102 B |
Loading…
Reference in New Issue
Block a user