From 32513fb3beb4dc59e3fb8b303b8fe18c81d48419 Mon Sep 17 00:00:00 2001 From: Moesh Date: Thu, 22 Apr 2021 22:35:23 +0200 Subject: [PATCH] Arena selection now has a 3 second cooldown --- .../calamity/assets/calamity/lang/en_us.json | 3 ++- .../load/setup_scoreboards.mcfunction | 20 +++++++++++-------- .../functions/player/trigger_arena.mcfunction | 12 +++++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/resourcepacks/calamity/assets/calamity/lang/en_us.json b/resourcepacks/calamity/assets/calamity/lang/en_us.json index 2603b435..710d7e49 100644 --- a/resourcepacks/calamity/assets/calamity/lang/en_us.json +++ b/resourcepacks/calamity/assets/calamity/lang/en_us.json @@ -7,7 +7,8 @@ "arena.shattering.name": "Shattering", "book.pageIndicator": "\u00a7ov5.0.0", "by.author": "by %s", - "calamity.arena.error.sameArena": "This arena is already selected.", + "calamity.arena.error.sameArena": "This arena is already selected", + "calamity.arena.error.cooldown": "Arena selection is on cooldown", "calamity.book.cancelStart": "Cancel", "calamity.book.forfeit": "Forfeit", "calamity.book.hover.cancel": "Cancel match start", diff --git a/saves/calamity/datapacks/calamity/data/calamity/functions/load/setup_scoreboards.mcfunction b/saves/calamity/datapacks/calamity/data/calamity/functions/load/setup_scoreboards.mcfunction index 21f04980..bc629fd0 100644 --- a/saves/calamity/datapacks/calamity/data/calamity/functions/load/setup_scoreboards.mcfunction +++ b/saves/calamity/datapacks/calamity/data/calamity/functions/load/setup_scoreboards.mcfunction @@ -286,18 +286,22 @@ scoreboard objectives add craftedObjItem32 minecraft.crafted:minecraft.tripwire_ # This objective is removed and reset after each round to ensure no hanky panky has occurred. scoreboard objectives remove gameVariable scoreboard objectives add gameVariable dummy - scoreboard players set TimeToStartMatch gameVariable 300 + # Setup visible variables + scoreboard players set ArenaSelectCooldown gameVariable 0 scoreboard players set BluePoints gameVariable 0 - scoreboard players set RedPoints gameVariable 0 - scoreboard players set ReadyBlue gameVariable 0 - scoreboard players set ReadyRed gameVariable 0 # oreLeft is polled from calamity:player/update_displays scoreboard players set OreLeft gameVariable 0 - scoreboard players set #tableCandle gameVariable 0 - scoreboard players set #tableCandleSmoke gameVariable 0 + scoreboard players set ReadyBlue gameVariable 0 + scoreboard players set ReadyRed gameVariable 0 + scoreboard players set RedPoints gameVariable 0 + scoreboard players set TimeToStartMatch gameVariable 300 + # Setup hidden variables scoreboard players set #arenaAction gameVariable 0 - scoreboard players set #selectedArena gameVariable 0 scoreboard players set #currentArena gameVariable 1 + scoreboard players set #currentArena gameVariable 1 + scoreboard players set #selectedArena gameVariable 0 + scoreboard players set #tableCandle gameVariable 0 + scoreboard players set #tableCandleSmoke gameVariable 0 # Game starts in lobby mode by default. scoreboard players set GameState gameVariable 0 @@ -309,4 +313,4 @@ scoreboard players set GameState gameVariable 0 # Used to determine whether or not the game has started. # This variable is accessed from calamity:tick, calamity:game_state/start_match, # calamity:player/trigger_cancel_start, and calamity:player/trigger_start_match -scoreboard players set StartingMatch gameVariable 0 +scoreboard players set StartingMatch gameVariable 0 \ No newline at end of file diff --git a/saves/calamity/datapacks/calamity/data/calamity/functions/player/trigger_arena.mcfunction b/saves/calamity/datapacks/calamity/data/calamity/functions/player/trigger_arena.mcfunction index fb2ebbfd..e904835c 100644 --- a/saves/calamity/datapacks/calamity/data/calamity/functions/player/trigger_arena.mcfunction +++ b/saves/calamity/datapacks/calamity/data/calamity/functions/player/trigger_arena.mcfunction @@ -4,6 +4,14 @@ #> Purpose: A player has tried to use the /trigger arena command. #>-------------------------------------------------------------------------------------------------- +# If an arena was recently switched, continue the cooldown timer +execute if score ArenaSelectCooldown gameVariable matches 1.. run scoreboard players remove ArenaSelectCooldown gameVariable 1 + +# Check if the arena has been switched recently and is still on cooldown +execute if entity @a[scores={arena=1..},limit=1] if score ArenaSelectCooldown gameVariable matches 1.. run tellraw @a {"translate":"system.message","color": "red","with":[{"translate":"calamity.arena.error.cooldown"}]} +execute if entity @a[scores={arena=1..},limit=1] if score ArenaSelectCooldown gameVariable matches 1.. run scoreboard players reset @a arena +execute if entity @a[scores={arena=1..},limit=1] if score ArenaSelectCooldown gameVariable matches 1.. run scoreboard players enable @a arena + # If the #currentArena gameVariable matches trigger number, the current arena is already selected. # Advise the player that they've made a mistake execute if score @a[scores={arena=1..},limit=1] arena = #currentArena gameVariable run tellraw @a[scores={arena=1..}] {"translate":"system.message","color":"red","with":[{"translate": "calamity.arena.error.sameArena"}]} @@ -21,6 +29,10 @@ scoreboard players enable @a arena execute if score #selectedArena gameVariable matches 1.. run scoreboard players set #arenaAction gameVariable 1 execute if score #selectedArena gameVariable matches 1.. run function calamity:arena/handler +# Switching arenas too quickly can cause a crash because of how many blocks are loading and +# unloading. Let's limit this to every 5 seconds and advise the player. +execute if score #selectedArena gameVariable matches 1.. run scoreboard players set ArenaSelectCooldown gameVariable 60 + # Calamity's arena makers must load and unload their own levels. The default action for the arena # handler is to load the level, so we will not need to define #actionAction gameVariable for # this action to run correctly.