mirror of
https://github.com/LoneWolfHT/grenades.git
synced 2024-11-22 14:53:46 +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
|
||||||
}
|
}
|
||||||
})`
|
})
|
||||||
|
91
grenades.lua
91
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,
|
||||||
local key = v:hud_add({
|
gain = 1.0,
|
||||||
hud_elem_type = "image",
|
max_hear_distance = 32,
|
||||||
position = {x=0, 0},
|
|
||||||
name = "death_list_hud",
|
|
||||||
scale = {x=1000, y=1000},
|
|
||||||
text = "grenades_white_"..tostring(i)..".png",
|
|
||||||
alignment = {x=0, y=0},
|
|
||||||
offset = {x=0, y=0}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.after(1.6*i, function()
|
if vector.equals(playerdir, grenadedir) then
|
||||||
|
for i = 0, 5, 1 do
|
||||||
|
local key = v:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
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}
|
||||||
|
})
|
||||||
|
|
||||||
|
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,
|
||||||
|
111
init.lua
111
init.lua
@ -3,30 +3,31 @@ 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,
|
||||||
|
collide_with_objects = true,
|
||||||
timer = 0,
|
timer = 0,
|
||||||
visual = "sprite",
|
visual = "sprite",
|
||||||
visual_size = {x=1, y=1, z=1},
|
visual_size = {x = 1, y = 1, z = 1},
|
||||||
textures = {def.image},
|
textures = {def.image},
|
||||||
collisionbox = {1, 1, 1, 1, 1, 1},
|
collisionbox = {1, 1, 1, 1, 1, 1},
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local pos = self.object:getpos()
|
|
||||||
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
|
||||||
@ -58,7 +59,15 @@ function grenades.register_grenade(name, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self.timer > def.timeout or node.name ~= "air" then
|
if self.timer > def.timeout or node.name ~= "air" then
|
||||||
|
if self.thrower_name then
|
||||||
|
minetest.log("[Grenades] A grenade thrown by "..self.thrower_name..
|
||||||
|
" is exploding at "..minetest.pos_to_string(pos))
|
||||||
def.on_explode(pos, self.thrower_name)
|
def.on_explode(pos, self.thrower_name)
|
||||||
|
else
|
||||||
|
minetest.chat_send_all(minetest.colorize("red", "[Error] self.thrower_name on line 62"..
|
||||||
|
" (grenades/init.lua) was nil. Removing grenade"))
|
||||||
|
minetest.log("[Error] self.thrower_name on line 62 (grenades/init.lua) was nil. Removing grenade")
|
||||||
|
end
|
||||||
|
|
||||||
obj:remove()
|
obj:remove()
|
||||||
end
|
end
|
||||||
@ -67,60 +76,44 @@ function grenades.register_grenade(name, def)
|
|||||||
|
|
||||||
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
||||||
|
|
||||||
|
local newdef = {}
|
||||||
|
|
||||||
|
newdef.description = def.description
|
||||||
|
newdef.stack_max = 1
|
||||||
|
newdef.range = 4
|
||||||
|
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
|
if def.placeable == true then
|
||||||
minetest.register_node("grenades:grenade_"..name, {
|
|
||||||
description = def.description,
|
newdef.tiles = {def.image}
|
||||||
stack_max = 1,
|
newdef.selection_box = {
|
||||||
range = 4,
|
|
||||||
paramtype = "light",
|
|
||||||
sunlight_propagates = true,
|
|
||||||
walkable = false,
|
|
||||||
drawtype = "plantlike",
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3},
|
fixed = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3},
|
||||||
},
|
}
|
||||||
tiles = {def.image},
|
newdef.groups = {oddly_breakable_by_hand = 2}
|
||||||
inventory_image = def.image,
|
newdef.paramtype = "light"
|
||||||
groups = {oddly_breakable_by_hand = 2},
|
newdef.sunlight_propagates = true
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
newdef.walkable = false
|
||||||
local player_name = user:get_player_name()
|
newdef.drawtype = "plantlike"
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
minetest.register_node("grenades:grenade_"..name, newdef)
|
||||||
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
|
|
||||||
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
})
|
|
||||||
else
|
else
|
||||||
minetest.register_craftitem("grenades:grenade_"..name, {
|
minetest.register_craftitem("grenades:grenade_"..name, newdef)
|
||||||
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
|
|
||||||
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
|
|
||||||
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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