mirror of
https://github.com/LoneWolfHT/grenades.git
synced 2024-11-25 08:13: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
|
||||
|
||||
`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.
|
||||
image = "", -- The name of the grenade's texture
|
||||
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
|
||||
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
|
||||
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",
|
||||
on_explode = function(pos, name)
|
||||
if not name or not pos then
|
||||
return
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
local radius = 3
|
||||
local radius = 6
|
||||
|
||||
minetest.add_particlespawner({
|
||||
amount = 20,
|
||||
time = 0.5,
|
||||
minpos = vector.subtract(pos, radius),
|
||||
maxpos = vector.add(pos, radius),
|
||||
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},
|
||||
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},
|
||||
minexptime = 0.3,
|
||||
maxexptime = 0.6,
|
||||
minsize = 7,
|
||||
@ -35,9 +39,15 @@ if not regular or regular == true then
|
||||
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
|
||||
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,
|
||||
@ -48,28 +58,34 @@ end
|
||||
|
||||
if not flash or flash == true then
|
||||
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",
|
||||
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
|
||||
local playerdir = vector.round(v:get_look_dir())
|
||||
local grenadedir = vector.round(vector.direction(v:get_pos(), pos))
|
||||
local pname = v:get_player_name()
|
||||
|
||||
if playerdir.x == grenadedir.x and playerdir.z == grenadedir.z then
|
||||
for i = 1, 3, 1 do
|
||||
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",
|
||||
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}
|
||||
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(1.6*i, function()
|
||||
minetest.after(2 * i, function()
|
||||
if minetest.get_player_by_name(pname) then
|
||||
minetest.get_player_by_name(pname):hud_remove(key)
|
||||
end
|
||||
@ -87,22 +103,35 @@ end
|
||||
|
||||
if not smoke or smoke == true then
|
||||
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",
|
||||
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
|
||||
minetest.add_particlespawner({
|
||||
amount = 100,
|
||||
time = 10,
|
||||
minpos = vector.subtract(pos, 3.5),
|
||||
maxpos = vector.add(pos, 3.5),
|
||||
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},
|
||||
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,
|
||||
maxexptime = 1,
|
||||
minsize = 100,
|
||||
maxexptime = 0.5,
|
||||
minsize = 90,
|
||||
maxsize = 100,
|
||||
collisiondetection = 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",
|
||||
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 = {}
|
||||
|
||||
local function throw_grenade(name, player)
|
||||
local dir = player:get_look_dir()
|
||||
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 yaw = player:get_look_yaw()
|
||||
local dir = player:get_look_dir()
|
||||
local pos = player:get_pos()
|
||||
local obj = minetest.add_entity({x = pos.x + dir.x, y = pos.y + 1.6, z = pos.z + dir.z}, name)
|
||||
|
||||
obj:setvelocity({x=dir.x * 16, y=dir.y * 16, z=dir.z * 16})
|
||||
obj:setacceleration({x=dir.x * -3, y=-17, z=dir.z * -3})
|
||||
obj:setyaw(yaw + math.pi)
|
||||
obj:set_velocity({x = dir.x * 40, y = dir.y * 40, z = dir.z * 40})
|
||||
obj:set_acceleration({x = dir.x * -12, y = -41, z = dir.z * -12})
|
||||
|
||||
return(obj:get_luaentity())
|
||||
return(obj:get_luaentity())
|
||||
end
|
||||
|
||||
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 = {
|
||||
physical = true,
|
||||
timer = 0,
|
||||
visual = "sprite",
|
||||
visual_size = {x=1, y=1, z=1},
|
||||
textures = {def.image},
|
||||
collisionbox = {1, 1, 1, 1, 1, 1},
|
||||
on_step = function(self, dtime)
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.get_node(pos)
|
||||
local obj = self.object
|
||||
local grenade_entity = {
|
||||
physical = false,
|
||||
collide_with_objects = true,
|
||||
timer = 0,
|
||||
visual = "sprite",
|
||||
visual_size = {x = 1, y = 1, z = 1},
|
||||
textures = {def.image},
|
||||
collisionbox = {1, 1, 1, 1, 1, 1},
|
||||
on_step = function(self, dtime)
|
||||
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
|
||||
self.particle = 0
|
||||
end
|
||||
if self.particle == nil then
|
||||
self.particle = 0
|
||||
end
|
||||
|
||||
if self.timer then
|
||||
self.timer = self.timer + dtime
|
||||
else
|
||||
self.timer = dtime
|
||||
end
|
||||
if self.timer then
|
||||
self.timer = self.timer + dtime
|
||||
else
|
||||
self.timer = dtime
|
||||
end
|
||||
|
||||
if def.particle and self.particle >= 4 then
|
||||
self.particle = 0
|
||||
if def.particle and self.particle >= 4 then
|
||||
self.particle = 0
|
||||
|
||||
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
|
||||
})
|
||||
elseif def.particle and self.particle < def.particle.interval then
|
||||
self.particle = self.particle + 1
|
||||
end
|
||||
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
|
||||
})
|
||||
elseif def.particle and self.particle < def.particle.interval then
|
||||
self.particle = self.particle + 1
|
||||
end
|
||||
|
||||
if self.timer > def.timeout or node.name ~= "air" then
|
||||
def.on_explode(pos, self.thrower_name)
|
||||
|
||||
obj:remove()
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
||||
|
||||
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
|
||||
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)
|
||||
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
|
||||
|
||||
return itemstack
|
||||
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()
|
||||
obj:remove()
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
if pointed_thing.type ~= "node" then
|
||||
local grenade = throw_grenade("grenades:grenade_"..name, user)
|
||||
grenade.timer = 0
|
||||
grenade.thrower_name = player_name
|
||||
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
||||
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
itemstack = ""
|
||||
end
|
||||
end
|
||||
local newdef = {}
|
||||
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
end
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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