From 0bdc630241d276887d27c89251eee823a66ab9b3 Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Tue, 20 Apr 2021 19:28:51 +0500 Subject: [PATCH 01/12] slow player down while holding loaded rocket --- shooter_rocket/init.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index bda2aa3..c42c1a9 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -135,9 +135,26 @@ if shooter.config.enable_crafting == true then }) end +local timer = 0 +minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer >= 0.1 then + for _, player in ipairs(minetest.get_connected_players()) do + local name = player and player:get_player_name() + local wielditem = player:get_wielded_item() + if wielditem:get_name() == "shooter_rocket:rocket_gun_loaded" then + local wielditem = player:get_wielded_item() + player:set_physics_override({ + speed = 0.7 + }) + timer = 0 + end + end + end +end) + --Backwards compatibility minetest.register_alias("shooter:rocket", "shooter_rocket:rocket") minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun") minetest.register_alias("shooter:rocket_gun_loaded", "shooter_rocket:rocket_gun_loaded") - From a97d88bf0838fdecbcb487a7c8e8cbd44680fbcc Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Tue, 20 Apr 2021 19:52:07 +0500 Subject: [PATCH 02/12] Update init.lua --- shooter_rocket/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index c42c1a9..7cbad3f 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -138,7 +138,8 @@ end local timer = 0 minetest.register_globalstep(function(dtime) timer = timer + dtime - if timer >= 0.1 then + if timer >= 1 then + timer = 0 for _, player in ipairs(minetest.get_connected_players()) do local name = player and player:get_player_name() local wielditem = player:get_wielded_item() @@ -147,7 +148,6 @@ minetest.register_globalstep(function(dtime) player:set_physics_override({ speed = 0.7 }) - timer = 0 end end end From a76b52247a60f9ebef974bab1cae1a092ffa5ada Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Tue, 20 Apr 2021 20:32:25 +0500 Subject: [PATCH 03/12] Update init.lua --- shooter_rocket/init.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index 7cbad3f..d4f6297 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -139,20 +139,23 @@ local timer = 0 minetest.register_globalstep(function(dtime) timer = timer + dtime if timer >= 1 then - timer = 0 + timer = 0 for _, player in ipairs(minetest.get_connected_players()) do local name = player and player:get_player_name() local wielditem = player:get_wielded_item() if wielditem:get_name() == "shooter_rocket:rocket_gun_loaded" then local wielditem = player:get_wielded_item() - player:set_physics_override({ - speed = 0.7 - }) - end + physics.set(name, "shooter_rocket:physics", { + speed = 0.7 + }) + else + physics.remove(name, "shooter_rocket:physics") + end end end end) + --Backwards compatibility minetest.register_alias("shooter:rocket", "shooter_rocket:rocket") minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun") From 8b0900ac82d91be3ee6550a6574cbc369f9e15af Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Tue, 20 Apr 2021 20:34:11 +0500 Subject: [PATCH 04/12] clean up --- shooter_rocket/init.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index d4f6297..57e9059 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -137,25 +137,24 @@ end local timer = 0 minetest.register_globalstep(function(dtime) - timer = timer + dtime - if timer >= 1 then + timer = timer + dtime + if timer >= 1 then timer = 0 - for _, player in ipairs(minetest.get_connected_players()) do - local name = player and player:get_player_name() - local wielditem = player:get_wielded_item() - if wielditem:get_name() == "shooter_rocket:rocket_gun_loaded" then - local wielditem = player:get_wielded_item() + for _, player in ipairs(minetest.get_connected_players()) do + local name = player and player:get_player_name() + local wielditem = player:get_wielded_item() + if wielditem:get_name() == "shooter_rocket:rocket_gun_loaded" then + local wielditem = player:get_wielded_item() physics.set(name, "shooter_rocket:physics", { speed = 0.7 }) - else + else physics.remove(name, "shooter_rocket:physics") end - end - end + end + end end) - --Backwards compatibility minetest.register_alias("shooter:rocket", "shooter_rocket:rocket") minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun") From 1a42bcd1e08881c64d2dc29f60ef603c1185c838 Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Wed, 21 Apr 2021 12:50:15 +0500 Subject: [PATCH 05/12] Update init.lua --- shooter_rocket/init.lua | 70 ++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index 57e9059..50bc4bc 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -17,6 +17,17 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ]]-- +local plcooldown = {} +local COOLDOWN = 5 + +minetest.register_on_joinplayer(function(player) + plcooldown[player:get_player_name()] = 0 +end) + +minetest.register_on_leaveplayer(function(player) + plcooldown[player:get_player_name()] = nil +end) + minetest.register_craftitem("shooter_rocket:rocket", { description = "Rocket", stack_max = 1, @@ -70,33 +81,43 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", { inventory_image = "shooter_rocket_gun_loaded.png", groups = {not_in_creative_inventory=1}, on_use = function(itemstack, user, pointed_thing) - if not minetest.setting_getbool("creative_mode") then - itemstack:add_wear(65535 / 50) - end - itemstack = "shooter_rocket:rocket_gun 1 "..itemstack:get_wear() - if pointed_thing.type ~= "nothing" then - local pointed = minetest.get_pointed_thing_position(pointed_thing) - if vector.distance(user:get_pos(), pointed) < 8 then - shooter.blast(pointed, 2, 50, 7) - return itemstack + if plcooldown[user:get_player_name()] ~= 0 then + minetest.chat_send_player(user:get_player_name(), "Your rocket has a cooldown!") + else + if not minetest.setting_getbool("creative_mode") then + itemstack:add_wear(65535 / 50) end - end - local pos = user:get_pos() - local dir = user:get_look_dir() - local yaw = user:get_look_horizontal() - if pos and dir and yaw then - pos.y = pos.y + user:get_properties().eye_height - local obj = minetest.add_entity(pos, "shooter_rocket:rocket_entity") - if obj then - minetest.sound_play("shooter_rocket_fire", {object=obj}) - obj:set_velocity(vector.multiply(dir, 20)) - obj:set_acceleration({x=dir.x * -3, y=-10, z=dir.z * -3}) - obj:set_yaw(yaw + math.pi / 2) - local ent = obj:get_luaentity() - if ent then - ent.user = user:get_player_name() + itemstack = "shooter_rocket:rocket_gun 1 "..itemstack:get_wear() + if pointed_thing.type ~= "nothing" then + local pointed = minetest.get_pointed_thing_position(pointed_thing) + if vector.distance(user:get_pos(), pointed) < 8 then + shooter.blast(pointed, 2, 50, 7) + return itemstack end end + local pos = user:get_pos() + local dir = user:get_look_dir() + local yaw = user:get_look_horizontal() + if pos and dir and yaw then + pos.y = pos.y + user:get_properties().eye_height + local obj = minetest.add_entity(pos, "shooter_rocket:rocket_entity") + if obj then + minetest.sound_play("shooter_rocket_fire", {object=obj}) + obj:set_velocity(vector.multiply(dir, 20)) + obj:set_acceleration({x=dir.x * -3, y=-10, z=dir.z * -3}) + obj:set_yaw(yaw + math.pi / 2) + local ent = obj:get_luaentity() + if ent then + ent.user = user:get_player_name() + end + end + end + plcooldown[user:get_player_name()] = COOLDOWN + minetest.after(COOLDOWN, function(user) + if plcooldown[user:get_player_name()] then + plcooldown[user:get_player_name()] = 0 + end + end, user) end return itemstack end, @@ -159,4 +180,3 @@ end) minetest.register_alias("shooter:rocket", "shooter_rocket:rocket") minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun") minetest.register_alias("shooter:rocket_gun_loaded", "shooter_rocket:rocket_gun_loaded") - From 8667bb31c097a3a914da2051f8ca1e846639ba47 Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Thu, 22 Apr 2021 05:26:39 +0500 Subject: [PATCH 06/12] Update shooter_rocket/init.lua Co-authored-by: David Leal --- shooter_rocket/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index 50bc4bc..3a74152 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -84,7 +84,7 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", { if plcooldown[user:get_player_name()] ~= 0 then minetest.chat_send_player(user:get_player_name(), "Your rocket has a cooldown!") else - if not minetest.setting_getbool("creative_mode") then + if not minetest.settings:get_bool("creative_mode") then itemstack:add_wear(65535 / 50) end itemstack = "shooter_rocket:rocket_gun 1 "..itemstack:get_wear() From 2050ebc1d70b83f94243326540ef38344232fe21 Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Thu, 22 Apr 2021 05:40:16 +0500 Subject: [PATCH 07/12] use HUD instead of sending a message --- shooter_rocket/init.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index 3a74152..b29cc0a 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -82,7 +82,11 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", { groups = {not_in_creative_inventory=1}, on_use = function(itemstack, user, pointed_thing) if plcooldown[user:get_player_name()] ~= 0 then - minetest.chat_send_player(user:get_player_name(), "Your rocket has a cooldown!") + hud_event.new(user:get_player_name(), { + name = "shooter_rocket:cooldown", + color = "0xC1FF44", + value = "Your rocket has a cooldown!" + }) else if not minetest.settings:get_bool("creative_mode") then itemstack:add_wear(65535 / 50) From bb4195efa68cff05ce191b598fd1cccfbf3d9ba2 Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Thu, 22 Apr 2021 05:47:51 +0500 Subject: [PATCH 08/12] add hud_event to depends --- shooter_rocket/mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shooter_rocket/mod.conf b/shooter_rocket/mod.conf index 3a2c75b..024ff1f 100644 --- a/shooter_rocket/mod.conf +++ b/shooter_rocket/mod.conf @@ -1,3 +1,3 @@ name = shooter_rocket description = Adds rocket missiles and launching gun -depends = shooter +depends = shooter, hud_events From 5354ef82db730f4c9b84aa548da75cfc23573911 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Thu, 22 Apr 2021 07:55:52 -0700 Subject: [PATCH 09/12] Update mod.conf --- shooter_rocket/mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shooter_rocket/mod.conf b/shooter_rocket/mod.conf index 024ff1f..05bfe5d 100644 --- a/shooter_rocket/mod.conf +++ b/shooter_rocket/mod.conf @@ -1,3 +1,3 @@ name = shooter_rocket description = Adds rocket missiles and launching gun -depends = shooter, hud_events +depends = shooter, hud_events, physics From fc5c6dc502dd9ff737db9abde18f90f9324a493c Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Thu, 22 Apr 2021 21:20:06 +0500 Subject: [PATCH 10/12] Update shooter_rocket/init.lua Co-authored-by: LoneWolfHT --- shooter_rocket/init.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index b29cc0a..ddffa10 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -20,9 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc., local plcooldown = {} local COOLDOWN = 5 -minetest.register_on_joinplayer(function(player) - plcooldown[player:get_player_name()] = 0 -end) minetest.register_on_leaveplayer(function(player) plcooldown[player:get_player_name()] = nil From 13e981799ed81f7a5a6c404d70cd694af500f1b1 Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Thu, 22 Apr 2021 21:20:32 +0500 Subject: [PATCH 11/12] Update shooter_rocket/init.lua Co-authored-by: LoneWolfHT --- shooter_rocket/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index ddffa10..84bd21b 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -116,7 +116,7 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", { plcooldown[user:get_player_name()] = COOLDOWN minetest.after(COOLDOWN, function(user) if plcooldown[user:get_player_name()] then - plcooldown[user:get_player_name()] = 0 + plcooldown[user:get_player_name()] = nil end end, user) end From 38bab6ea3821e6675b669fa541f832f243bd301b Mon Sep 17 00:00:00 2001 From: olliy <55839810+olliy1or@users.noreply.github.com> Date: Thu, 22 Apr 2021 21:21:58 +0500 Subject: [PATCH 12/12] UpDaTe --- shooter_rocket/init.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/shooter_rocket/init.lua b/shooter_rocket/init.lua index 84bd21b..fb871fb 100644 --- a/shooter_rocket/init.lua +++ b/shooter_rocket/init.lua @@ -20,7 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc., local plcooldown = {} local COOLDOWN = 5 - minetest.register_on_leaveplayer(function(player) plcooldown[player:get_player_name()] = nil end) @@ -78,14 +77,14 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", { inventory_image = "shooter_rocket_gun_loaded.png", groups = {not_in_creative_inventory=1}, on_use = function(itemstack, user, pointed_thing) - if plcooldown[user:get_player_name()] ~= 0 then + if plcooldown[user:get_player_name()] then hud_event.new(user:get_player_name(), { name = "shooter_rocket:cooldown", color = "0xC1FF44", value = "Your rocket has a cooldown!" }) else - if not minetest.settings:get_bool("creative_mode") then + if not minetest.setting_getbool("creative_mode") then itemstack:add_wear(65535 / 50) end itemstack = "shooter_rocket:rocket_gun 1 "..itemstack:get_wear() @@ -99,6 +98,7 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", { local pos = user:get_pos() local dir = user:get_look_dir() local yaw = user:get_look_horizontal() + local username = user:get_player_name() if pos and dir and yaw then pos.y = pos.y + user:get_properties().eye_height local obj = minetest.add_entity(pos, "shooter_rocket:rocket_entity") @@ -109,14 +109,14 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", { obj:set_yaw(yaw + math.pi / 2) local ent = obj:get_luaentity() if ent then - ent.user = user:get_player_name() + ent.user = username end end end - plcooldown[user:get_player_name()] = COOLDOWN + plcooldown[username] = COOLDOWN minetest.after(COOLDOWN, function(user) - if plcooldown[user:get_player_name()] then - plcooldown[user:get_player_name()] = nil + if plcooldown[username] then + plcooldown[username] = nil end end, user) end @@ -181,3 +181,4 @@ end) minetest.register_alias("shooter:rocket", "shooter_rocket:rocket") minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun") minetest.register_alias("shooter:rocket_gun_loaded", "shooter_rocket:rocket_gun_loaded") +