Sword marker: Decrease cooldowns, fix trivial bug (#826)

* Improve sword markers

* Fix timer

* checks every 2 seconds

* Edit string sent to chat

* Clean up and increase sword special cooldown

Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com>
This commit is contained in:
-sniper- 2021-03-12 18:02:30 +01:00 committed by GitHub
parent 6fb0510b73
commit 723301dd12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,12 +29,12 @@ end, true)
local sword_special_timer = {}
local SWORD_SPECIAL_COOLDOWN = 40
local SWORD_SPECIAL_COOLDOWN = 20
local function sword_special_timer_func(pname, timeleft)
sword_special_timer[pname] = timeleft
if timeleft - 10 >= 0 then
minetest.after(10, sword_special_timer_func, pname, timeleft - 10)
if timeleft - 2 >= 0 then
minetest.after(2, sword_special_timer_func, pname, timeleft - 2)
else
sword_special_timer[pname] = nil
end
@ -57,8 +57,8 @@ minetest.register_tool("ctf_classes:sword_bronze", {
local pname = placer:get_player_name()
if not pointed_thing then return end
if sword_special_timer[pname] then
minetest.chat_send_player(pname, "You can't place a marker yet (>"..sword_special_timer[pname].."s left)")
if sword_special_timer[pname] and placer:get_player_control().sneak then
minetest.chat_send_player(pname, "You have to wait "..sword_special_timer[pname].."s to place marker again")
if pointed_thing.type == "node" then
return minetest.item_place(itemstack, placer, pointed_thing)
@ -102,8 +102,8 @@ minetest.register_tool("ctf_classes:sword_bronze", {
-- Check if player is sneaking before placing marker
if not placer:get_player_control().sneak then return end
sword_special_timer[pname] = 20
sword_special_timer_func(pname, 20)
sword_special_timer[pname] = 4
sword_special_timer_func(pname, 4)
minetest.registered_chatcommands["m"].func(pname, "placed with sword")
end,