Change rocket mechanics

This commit is contained in:
philipmi 2022-07-01 23:24:56 +02:00
parent 4733f7e6c7
commit bb8775c3bb

View file

@ -17,15 +17,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
]]-- ]]--
local plcooldown = {} local ROCKET_COOLDOWN = 6
local COOLDOWN = 5 local RELOAD_TIME = 2
minetest.register_on_leaveplayer(function(player)
plcooldown[player:get_player_name()] = nil
end)
minetest.register_craftitem("shooter_rocket:rocket", { minetest.register_craftitem("shooter_rocket:rocket", {
description = "Rocket", description = "Single-use Rocket",
stack_max = 1, stack_max = 1,
inventory_image = "shooter_rocket_inv.png", inventory_image = "shooter_rocket_inv.png",
}) })
@ -77,24 +73,15 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
inventory_image = "shooter_rocket_gun_loaded.png", inventory_image = "shooter_rocket_gun_loaded.png",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if plcooldown[user:get_player_name()] then if pointed_thing.type == "nothing" then
hud_event.new(user:get_player_name(), { itemstack = "shooter_rocket:rocket_gun 1 "..(65535 - 6000)
name = "shooter_rocket:cooldown", ctf_classes.update_wear.start_update(
color = "0xC1FF44", user:get_player_name(),
value = "Your rocket has a cooldown!" "shooter_rocket:rocket_gun",
}) 65535/RELOAD_TIME,
else true
if not minetest.settings:get_bool("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
end
end
local pos = user:get_pos() local pos = user:get_pos()
local dir = user:get_look_dir() local dir = user:get_look_dir()
local yaw = user:get_look_horizontal() local yaw = user:get_look_horizontal()
@ -113,12 +100,6 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
end end
end end
end end
plcooldown[username] = COOLDOWN
minetest.after(COOLDOWN, function(user)
if plcooldown[username] then
plcooldown[username] = nil
end
end, user)
end end
return itemstack return itemstack
end, end,
@ -129,12 +110,29 @@ minetest.register_tool("shooter_rocket:rocket_gun", {
inventory_image = "shooter_rocket_gun.png", inventory_image = "shooter_rocket_gun.png",
on_use = function(itemstack, user) on_use = function(itemstack, user)
local inv = user:get_inventory() local inv = user:get_inventory()
if inv:contains_item("main", "shooter_rocket:rocket") then local pos, stack = ctf_classes.update_wear.find_item(inv, "ctf_classes:rocket")
if itemstack:get_wear() ~= 0 then
return
elseif pos and stack:get_wear() == 0 then
minetest.sound_play("shooter_reload", {object=user})
stack:set_wear(65535 - 6000)
inv:set_stack("main", pos, stack)
ctf_classes.update_wear.start_update(
user:get_player_name(),
"ctf_classes:rocket",
65535/ROCKET_COOLDOWN,
true
)
itemstack = "shooter_rocket:rocket_gun_loaded 1 "
elseif inv:contains_item("main", "shooter_rocket:rocket") then
minetest.sound_play("shooter_reload", {object=user}) minetest.sound_play("shooter_reload", {object=user})
if not minetest.settings:get_bool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
inv:remove_item("main", "shooter_rocket:rocket 1") inv:remove_item("main", "shooter_rocket:rocket 1")
end end
itemstack = "shooter_rocket:rocket_gun_loaded 1 "..itemstack:get_wear() itemstack = "shooter_rocket:rocket_gun_loaded 1 "
else else
minetest.sound_play("shooter_click", {object=user}) minetest.sound_play("shooter_click", {object=user})
end end