From 73c788b1d7aae4096c0b12c59faeae8d40c714cf Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Thu, 22 Nov 2018 11:58:20 -0800 Subject: [PATCH] Add unfinished API and two grenades --- grenades.lua | 62 +++++++++++++++++++++++++ init.lua | 79 ++++++++++++++++++++++++++++++++ mod.conf | 1 + models/grenade_regular.mtl | 10 ++++ models/grenade_regular.obj | 40 ++++++++++++++++ settingtypes.txt | 5 ++ textures/grenades_flashbang.png | Bin 0 -> 213 bytes textures/grenades_regular.png | Bin 0 -> 225 bytes textures/grenades_smoke.png | Bin 0 -> 161 bytes textures/grenades_white.png | Bin 0 -> 102 bytes textures/grenades_white_1.png | Bin 0 -> 102 bytes textures/grenades_white_2.png | Bin 0 -> 102 bytes textures/grenades_white_3.png | Bin 0 -> 102 bytes 13 files changed, 197 insertions(+) create mode 100644 grenades.lua create mode 100644 init.lua create mode 100644 mod.conf create mode 100644 models/grenade_regular.mtl create mode 100644 models/grenade_regular.obj create mode 100644 settingtypes.txt create mode 100644 textures/grenades_flashbang.png create mode 100644 textures/grenades_regular.png create mode 100755 textures/grenades_smoke.png create mode 100644 textures/grenades_white.png create mode 100644 textures/grenades_white_1.png create mode 100644 textures/grenades_white_2.png create mode 100644 textures/grenades_white_3.png diff --git a/grenades.lua b/grenades.lua new file mode 100644 index 0000000..beb60c7 --- /dev/null +++ b/grenades.lua @@ -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 diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..45c278e --- /dev/null +++ b/init.lua @@ -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") diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..e2b506a --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = grenades \ No newline at end of file diff --git a/models/grenade_regular.mtl b/models/grenade_regular.mtl new file mode 100644 index 0000000..70d3ba1 --- /dev/null +++ b/models/grenade_regular.mtl @@ -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 diff --git a/models/grenade_regular.obj b/models/grenade_regular.obj new file mode 100644 index 0000000..b8e3c0f --- /dev/null +++ b/models/grenade_regular.obj @@ -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 diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..b6a9899 --- /dev/null +++ b/settingtypes.txt @@ -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 \ No newline at end of file diff --git a/textures/grenades_flashbang.png b/textures/grenades_flashbang.png new file mode 100644 index 0000000000000000000000000000000000000000..28166866eb80d7a5c8acdf933df7877dc04009c5 GIT binary patch literal 213 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf8|DyFWJxc`B%3j-VdbxJ%>77%AzTFk^{5I33>x|yFGmH!!Csyqd6A)bSYH`4f z#>sPEIIWj;X*uJ%tMw=6Dyh6j_jP}K5tU;NV`TDVySe^1t9s=!E18KlS$BZ$V(@hJ Kb6Mw<&;$StS5Ni; literal 0 HcmV?d00001 diff --git a/textures/grenades_regular.png b/textures/grenades_regular.png new file mode 100644 index 0000000000000000000000000000000000000000..5de47958a8081fe9b2bccc44c6c81db440eade68 GIT binary patch literal 225 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf5f z3$`xt7L!XkxtObkecGOSu00xD$iboFyt=akR{07umsJpcdz literal 0 HcmV?d00001 diff --git a/textures/grenades_white_1.png b/textures/grenades_white_1.png new file mode 100644 index 0000000000000000000000000000000000000000..bf205ed4b62532e3d29c6aae09d05343e07e89b3 GIT binary patch literal 102 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf0xD$iboFyt=akR{07umsJpcdz literal 0 HcmV?d00001 diff --git a/textures/grenades_white_2.png b/textures/grenades_white_2.png new file mode 100644 index 0000000000000000000000000000000000000000..1a962f768776ef1acfd4f69d51143bcf04a8a9a2 GIT binary patch literal 102 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#VfFVdQ&MBb@06&5mw*UYD literal 0 HcmV?d00001 diff --git a/textures/grenades_white_3.png b/textures/grenades_white_3.png new file mode 100644 index 0000000000000000000000000000000000000000..5df02fef289a4024f77899d8ff20899ce0e064c3 GIT binary patch literal 102 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#VfbO7lW|sEO%ZB(}XJx2U8dr4jyLyG