From 98928211f604b756dc384f446570e29ceebc0c4d Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Wed, 2 Dec 2020 16:31:22 -0800 Subject: [PATCH] Improve Smoke Grenades --- mods/ctf/ctf_classes/api.lua | 4 +- mods/pvp/grenades/grenades.lua | 160 ++++++++++-------- .../textures/grenades_smoke_grenade.png | Bin 126 -> 109 bytes 3 files changed, 88 insertions(+), 76 deletions(-) diff --git a/mods/ctf/ctf_classes/api.lua b/mods/ctf/ctf_classes/api.lua index 538ea22..3e323ce 100644 --- a/mods/ctf/ctf_classes/api.lua +++ b/mods/ctf/ctf_classes/api.lua @@ -140,7 +140,7 @@ local function sqdist(a, b) return x*x + y*y + z*z end -local function get_flag_pos(player) +function ctf_classes.get_flag_pos(player) local tplayer = ctf.player(player:get_player_name()) if not tplayer or not tplayer.team then return nil @@ -162,7 +162,7 @@ function ctf_classes.can_change(player) return false, "You need to wait to change classes again!" end - local flag_pos = get_flag_pos(player) + local flag_pos = ctf_classes.get_flag_pos(player) if flag_pos then return sqdist(player:get_pos(), flag_pos) < 25, "Move closer to the flag to change classes!" diff --git a/mods/pvp/grenades/grenades.lua b/mods/pvp/grenades/grenades.lua index a97a186..63f32ca 100644 --- a/mods/pvp/grenades/grenades.lua +++ b/mods/pvp/grenades/grenades.lua @@ -82,86 +82,25 @@ end grenades.register_grenade("grenades:frag", table.copy(fragdef)) --grenades.register_grenade("grenades:frag_sticky", fragdef) --- Flashbang Grenade - --- local flash_huds = {} - --- grenades.register_grenade("grenades:flashbang", { --- description = "Flashbang grenade (Blinds all who look at blast)", --- image = "grenades_flashbang.png", --- clock = 4, --- on_explode = function(pos) --- for _, v in ipairs(minetest.get_objects_inside_radius(pos, 20)) do --- local hit = minetest.raycast(pos, v:get_pos(), true, true):next() - --- if hit and v:is_player() and v:get_hp() > 0 and not flash_huds[v:get_player_name()] and hit.type == "object" and --- hit.ref:is_player() and hit.ref:get_player_name() == v:get_player_name() 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() - --- minetest.sound_play("glasslike_break", { --- pos = pos, --- gain = 1.0, --- max_hear_distance = 32, --- }) - --- if math.acos(playerdir.x*grenadedir.x + playerdir.y*grenadedir.y + playerdir.z*grenadedir.z) <= math.pi/4 then --- flash_huds[pname] = {} - --- 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 = "default_cloud.png^[colorize:white:255^[opacity:"..tostring(255 - (i * 20)), --- alignment = {x = 0, y = 0}, --- offset = {x = 0, y = 0} --- }) - --- flash_huds[pname][i+1] = key - --- minetest.after(2 * i, function() --- if minetest.get_player_by_name(pname) then --- minetest.get_player_by_name(pname):hud_remove(key) - --- if flash_huds[pname] then --- table.remove(flash_huds[pname], 1) --- end - --- if i == 5 then --- flash_huds[pname] = nil --- end --- end --- end) --- end --- end - --- end --- end --- end, --- }) - --- minetest.register_on_dieplayer(function(player) --- local name = player:get_player_name() - --- if flash_huds[name] then --- for _, v in ipairs(flash_huds[name]) do --- player:hud_remove(v) --- end - --- flash_huds[name] = nil --- end --- end) - -- Smoke Grenade local SMOKE_GRENADE_TIME = 30 grenades.register_grenade("grenades:smoke", { description = "Smoke grenade (Generates smoke around blast site)", image = "grenades_smoke_grenade.png", - on_explode = function(pos) + on_collide = function(obj) + return true + end, + on_explode = function(pos, pname) + local player = minetest.get_player_by_name(pname) + if not player or not pos then return end + + if vector.distance(pos, ctf_classes.get_flag_pos(player)) <= 15 then + minetest.chat_send_player(pname, "You can't explode smoke grenades so close to your flag!") + player:get_inventory():add_item("main", "grenades:smoke") + return + end + minetest.sound_play("grenades_glasslike_break", { pos = pos, gain = 1.0, @@ -206,3 +145,76 @@ grenades.register_grenade("grenades:smoke", { interval = 0.3, } }) + +-- Flashbang Grenade + +--[[ local flash_huds = {} + +grenades.register_grenade("grenades:flashbang", { + description = "Flashbang grenade (Blinds all who look at blast)", + image = "grenades_flashbang.png", + clock = 4, + on_explode = function(pos) + for _, v in ipairs(minetest.get_objects_inside_radius(pos, 20)) do + local hit = minetest.raycast(pos, v:get_pos(), true, true):next() + + if hit and v:is_player() and v:get_hp() > 0 and not flash_huds[v:get_player_name()] and hit.type == "object" and + hit.ref:is_player() and hit.ref:get_player_name() == v:get_player_name() 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() + + minetest.sound_play("glasslike_break", { + pos = pos, + gain = 1.0, + max_hear_distance = 32, + }) + + if math.acos(playerdir.x*grenadedir.x + playerdir.y*grenadedir.y + playerdir.z*grenadedir.z) <= math.pi/4 then + flash_huds[pname] = {} + + 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 = "default_cloud.png^[colorize:white:255^[opacity:"..tostring(255 - (i * 20)), + alignment = {x = 0, y = 0}, + offset = {x = 0, y = 0} + }) + + flash_huds[pname][i+1] = key + + minetest.after(2 * i, function() + if minetest.get_player_by_name(pname) then + minetest.get_player_by_name(pname):hud_remove(key) + + if flash_huds[pname] then + table.remove(flash_huds[pname], 1) + end + + if i == 5 then + flash_huds[pname] = nil + end + end + end) + end + end + + end + end + end, +}) + +minetest.register_on_dieplayer(function(player) + local name = player:get_player_name() + + if flash_huds[name] then + for _, v in ipairs(flash_huds[name]) do + player:hud_remove(v) + end + + flash_huds[name] = nil + end +end) ]] diff --git a/mods/pvp/grenades/textures/grenades_smoke_grenade.png b/mods/pvp/grenades/textures/grenades_smoke_grenade.png index af82497b8a7e27a3224e0c956f6c9d6bd34b0843..6db9eb6545f72ad0f7cbb7e6abc754e74dbb036a 100644 GIT binary patch delta 90 zcmb=+ogfj)$jrdNplX||1f&>?gWR1M)}51i3FI&b_=LE!vM|S7$?gZql?3?(GdMiE lkp|>&d%8G=aL6Vr2m(0<42)dQJw$*k22WQ%mvv4FO#qjH6g~g| delta 107 zcmd0;n;?GAso@k2@VYVcoi10dlcxh39Y(Vpwy(Wa4S<18-p+(yYrHhWjjDRJzf1=);T3K F0RZ;L9k2iZ