From e67f8cc2f1cae0f20bc1d28495ce7064be55ede3 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Thu, 22 Nov 2018 17:36:23 -0800 Subject: [PATCH] Flashbangs only flash you if you are looking at the explosion pos. May be buggy --- grenades.lua | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/grenades.lua b/grenades.lua index 9da9814..c7e39bc 100644 --- a/grenades.lua +++ b/grenades.lua @@ -39,20 +39,25 @@ if settings:get_bool("enable_flashbang_grenade") then 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 + for k, v in ipairs(minetest.get_objects_inside_radius(pos, 15)) 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} - }) + local playerdir = vector.floor(vector.normalize(v:get_look_dir())) + local grenadedir = vector.floor(vector.normalize(vector.direction(v:get_pos(), pos))) - minetest.after(4*i, function() v:hud_remove(key) end) + if playerdir.x == grenadedir.x and playerdir.z == grenadedir.z 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