Add unfinished API and two grenades
62
grenades.lua
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
local settings = minetest.settings
|
||||||
|
|
||||||
|
if settings:get_bool("enable_regular_grenade") then
|
||||||
|
grenades.register_grenade("regular", {
|
||||||
|
description = "A regular grenade (Kills anyone near where it explodes)",
|
||||||
|
image = "grenades_regular.png",
|
||||||
|
on_explode = function(pos, player, self)
|
||||||
|
minetest.add_particlespawner({
|
||||||
|
amount = 20,
|
||||||
|
time = 0.5,
|
||||||
|
minpos = vector.subtract(pos, 2.3),
|
||||||
|
maxpos = vector.add(pos, 2.3),
|
||||||
|
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 = 5,
|
||||||
|
maxsize = 7,
|
||||||
|
collisiondetection = false,
|
||||||
|
collision_removal = false,
|
||||||
|
vertical = false,
|
||||||
|
texture = "grenades_smoke.png",
|
||||||
|
})
|
||||||
|
|
||||||
|
for k, v in ipairs(minetest.get_objects_inside_radius(pos, 2.3)) do
|
||||||
|
if v:is_player() and v:get_hp() > 0 then
|
||||||
|
v:punch(player, 2, {damage_groups = {fleshy = 20}}, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
timeout = 3
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
if settings:get_bool("enable_flashbang_grenade") then
|
||||||
|
grenades.register_grenade("flashbang", {
|
||||||
|
description = "A flashbang grenade (Blinds all who look at the explosion)",
|
||||||
|
image = "grenades_flashbang.png",
|
||||||
|
on_explode = function(pos, player, self)
|
||||||
|
for k, v in ipairs(minetest.get_objects_inside_radius(pos, 6)) do
|
||||||
|
if v:is_player() and v:get_hp() > 0 then
|
||||||
|
for i = 1, 3, 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}
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.after(4*i, function() v:hud_remove(key) end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
timeout = 3
|
||||||
|
})
|
||||||
|
end
|
79
init.lua
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
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()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
return(obj:get_luaentity())
|
||||||
|
end
|
||||||
|
|
||||||
|
function grenades.register_grenade(name, def)
|
||||||
|
minetest.log("\n\n\nREGISTERING "..name.."\n\n\n\n")
|
||||||
|
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 player
|
||||||
|
|
||||||
|
if self.timer then
|
||||||
|
self.timer = self.timer + dtime
|
||||||
|
else
|
||||||
|
self.timer = dtime
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.thrower_name then
|
||||||
|
player = minetest.get_player_by_name(self.thrower_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
if player and (self.timer > def.timeout or node.name ~= "air") then
|
||||||
|
def.on_explode(pos, player, self)
|
||||||
|
|
||||||
|
self.object:remove()
|
||||||
|
elseif self.timer > def.timeout or node.name ~= "air" then
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
minetest.register_entity("grenades:grenade_"..name, grenade_entity)
|
||||||
|
|
||||||
|
minetest.register_node("grenades:grenade_"..name, {
|
||||||
|
description = def.description,
|
||||||
|
stack_max = 1,
|
||||||
|
range = 4,
|
||||||
|
paramtype = "light",
|
||||||
|
sunlight_propagates = true,
|
||||||
|
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 = 1},
|
||||||
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
local player_name = user:get_player_name()
|
||||||
|
local inv = user:get_inventory()
|
||||||
|
|
||||||
|
grenade = throw_grenade("grenades:grenade_"..name, user)
|
||||||
|
grenade.timer = 0
|
||||||
|
grenade.thrower_name = player_name
|
||||||
|
|
||||||
|
inv:remove_item("main", "grenades:grenade_"..name)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
dofile(minetest.get_modpath("grenades").."/grenades.lua")
|
1
mod.conf
Normal file
@ -0,0 +1 @@
|
|||||||
|
name = grenades
|
10
models/grenade_regular.mtl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl None
|
||||||
|
Ns 0
|
||||||
|
Ka 0.000000 0.000000 0.000000
|
||||||
|
Kd 0.8 0.8 0.8
|
||||||
|
Ks 0.8 0.8 0.8
|
||||||
|
d 1
|
||||||
|
illum 2
|
40
models/grenade_regular.obj
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# Blender v2.79 (sub 0) OBJ File: ''
|
||||||
|
# www.blender.org
|
||||||
|
mtllib grenade_regular.mtl
|
||||||
|
o Cube_Cube.001
|
||||||
|
v -0.202887 -0.445911 -0.202887
|
||||||
|
v -0.202887 0.179806 -0.202887
|
||||||
|
v 0.202887 -0.445911 -0.202887
|
||||||
|
v 0.202887 0.179806 -0.202887
|
||||||
|
v -0.202887 -0.445911 0.202887
|
||||||
|
v -0.202887 0.179806 0.202887
|
||||||
|
v 0.202887 -0.445911 0.202887
|
||||||
|
v 0.202887 0.179806 0.202887
|
||||||
|
v -0.033569 0.125949 -0.310149
|
||||||
|
v -0.033569 0.314819 -0.310149
|
||||||
|
v 0.053858 0.125949 -0.310149
|
||||||
|
v 0.053858 0.314819 -0.310149
|
||||||
|
v -0.033569 0.125949 -0.121278
|
||||||
|
v -0.033569 0.314819 -0.121278
|
||||||
|
v 0.053858 0.125949 -0.121278
|
||||||
|
v 0.053858 0.314819 -0.121278
|
||||||
|
vn 0.0000 0.0000 -1.0000
|
||||||
|
vn 1.0000 0.0000 0.0000
|
||||||
|
vn 0.0000 0.0000 1.0000
|
||||||
|
vn -1.0000 0.0000 0.0000
|
||||||
|
vn 0.0000 -1.0000 0.0000
|
||||||
|
vn 0.0000 1.0000 0.0000
|
||||||
|
usemtl None
|
||||||
|
s off
|
||||||
|
f 1//1 2//1 4//1 3//1
|
||||||
|
f 3//2 4//2 8//2 7//2
|
||||||
|
f 7//3 8//3 6//3 5//3
|
||||||
|
f 5//4 6//4 2//4 1//4
|
||||||
|
f 3//5 7//5 5//5 1//5
|
||||||
|
f 8//6 4//6 2//6 6//6
|
||||||
|
f 9//1 10//1 12//1 11//1
|
||||||
|
f 11//2 12//2 16//2 15//2
|
||||||
|
f 15//3 16//3 14//3 13//3
|
||||||
|
f 13//4 14//4 10//4 9//4
|
||||||
|
f 11//5 15//5 13//5 9//5
|
||||||
|
f 16//6 12//6 10//6 14//6
|
5
settingtypes.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#Add a regular grenade to the world
|
||||||
|
enable_regular_grenade (Add a regular grenade to the world) bool false
|
||||||
|
|
||||||
|
#Add a flashbang grenade to the world
|
||||||
|
enable_flashbang_grenade (Add a flashbang grenade to the world) bool false
|
BIN
textures/grenades_flashbang.png
Normal file
After Width: | Height: | Size: 213 B |
BIN
textures/grenades_regular.png
Normal file
After Width: | Height: | Size: 225 B |
BIN
textures/grenades_smoke.png
Executable file
After Width: | Height: | Size: 161 B |
BIN
textures/grenades_white.png
Normal file
After Width: | Height: | Size: 102 B |
BIN
textures/grenades_white_1.png
Normal file
After Width: | Height: | Size: 102 B |
BIN
textures/grenades_white_2.png
Normal file
After Width: | Height: | Size: 102 B |
BIN
textures/grenades_white_3.png
Normal file
After Width: | Height: | Size: 102 B |