Skip to content

Commit

Permalink
Op-only mode
Browse files Browse the repository at this point in the history
Activate or authenticate as an op by doing /trigger OpControl
In op-only mode, a new menu option is also available to assign teams for other players (or pre-assign teams for players joining later)
  • Loading branch information
slicedlime committed May 23, 2021
1 parent 49326cb commit 145b3c0
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 25 deletions.
14 changes: 14 additions & 0 deletions data/mob_dash/functions/assign_teams_menu.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Show team switching menu to @s

tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 1"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=1}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 2"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=2}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 3"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=3}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 4"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=4}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 5"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=5}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 6"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=6}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 7"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=7}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 8"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=8}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign player to ", "color":"white","clickEvent":{"action":"suggest_command", "value":"/scoreboard players set PlayerName SetTeam 9"},"extra":[{"selector":"@e[type=area_effect_cloud,scores={md_team=9}]"}]},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text": "\nSelect an option and replace PlayerName on the command with the player to assign."}]

scoreboard players set @s md_ticks -1800
1 change: 1 addition & 0 deletions data/mob_dash/functions/display_menu.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function mob_dash:welcome
tellraw @s ""
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Tutorial", "color":"green","clickEvent":{"action":"run_command", "value":"/trigger md_action set 1"}},{"text":"]","color":"gold", "bold": true}]
tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Switch Teams", "color":"green","clickEvent":{"action":"run_command", "value":"/trigger md_action set 2"}},{"text":"]","color":"gold", "bold": true}]
execute if score $OpOnly md_state matches 1 run tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Assign Teams", "color":"green","clickEvent":{"action":"run_command", "value":"/trigger md_action set 7"}},{"text":"]","color":"gold", "bold": true}]
execute if score $Win md_state matches 0 run tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Win Score Limit: ", "color":"green", "extra": [{"text": "None", "color": "aqua"}],"clickEvent":{"action":"suggest_command","value":"/trigger WinScore set "}},{"text":"]","color":"gold", "bold": true}]
execute if score $Win md_state matches 1.. run tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Win Score Limit: ", "color":"green", "extra": [{"score":{"objective":"md_state","name":"$Win"}, "color": "aqua"}],"clickEvent":{"action":"suggest_command","value":"/trigger WinScore set "}},{"text":"]","color":"gold", "bold": true}]
execute if score $Timeout md_state matches 0 run tellraw @s [{"text":"- "},{"text":"[","color":"gold","bold": true},{"text":"Time Limit: ", "color":"green", "extra": [{"text": "None", "color": "aqua"}],"clickEvent":{"action":"suggest_command","value":"/trigger TimeLimit set "}},{"text":"]","color":"gold", "bold": true}]
Expand Down
7 changes: 5 additions & 2 deletions data/mob_dash/functions/join_team.mcfunction
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Join a team based on value in md_action

scoreboard players operation @s md_team = @s md_action
scoreboard players remove @s md_team 100
execute if score @s md_action matches 100.. run scoreboard players operation @s md_team = @s md_action
execute if score @s md_action matches 100.. run scoreboard players remove @s md_team 100
execute if score @s SetTeam matches 1.. run scoreboard players operation @s md_team = @s SetTeam

execute if score @s md_team matches 1 run team join red @s
execute if score @s md_team matches 2 run team join green @s
Expand All @@ -17,4 +18,6 @@ tag @s add md_current
execute as @e[type=area_effect_cloud,tag=md_team] if score @s md_team = @p[tag=md_current] md_team run tellraw @a ["", {"selector":"@p[tag=md_current]"}, {"text":" has joined "}, {"selector": "@s"}]
tag @s remove md_current

scoreboard players reset @s SetTeam

function mob_dash:display_menu
4 changes: 4 additions & 0 deletions data/mob_dash/functions/load.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ scoreboard objectives add md_ticks dummy "Mob Dash Menu Ticks"
scoreboard objectives add md_action trigger "Mob Dash Menu Actions"
scoreboard objectives add WinScore trigger "Mob Dash Win Score"
scoreboard objectives add TimeLimit trigger "Mob Dash Time Limit"
scoreboard objectives add OpControl trigger "Op-only control"
scoreboard objectives add SetTeam dummy "Set Team for player"

# Game states
scoreboard objectives add md_target dummy "Mob Dash Target ID"
Expand Down Expand Up @@ -36,6 +38,8 @@ scoreboard players add $Timeout md_state 0
scoreboard players add $Scoring md_state 0
scoreboard players add $Difficulty md_state 0

scoreboard players add $OpOnly md_state 0

execute store result score $Temp md_state run difficulty
execute if score $Temp md_state matches 1.. run scoreboard players operation $GameDifficulty md_state = $Temp md_state

Expand Down
10 changes: 3 additions & 7 deletions data/mob_dash/functions/new_player.mcfunction
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# Runs for every player on first join_team

scoreboard players set $Random md_state 0
execute if score $OpOnly md_state matches 1 run function mob_dash:welcome

function mob_dash:randomize_bit
function mob_dash:randomize_bit
function mob_dash:randomize_bit

scoreboard players add $Random md_state 101
scoreboard players operation @s md_action = $Random md_state
execute unless score @s SetTeam matches 1.. run function mob_dash:randomize_team
function mob_dash:join_team

tag @s add md_assigned
6 changes: 6 additions & 0 deletions data/mob_dash/functions/op.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Authenticate @s as an op and put the game into op-control mode

execute if score $OpOnly md_state matches 0 run tellraw @a [{"text": "The game is now in op-only mode.", "color": "gold"}]

scoreboard players set $OpOnly md_state 1
tag @s add md_op
6 changes: 6 additions & 0 deletions data/mob_dash/functions/op_auth.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Prompt to authenticate @s as an op and put the game into op-control mode

execute if score $OpOnly md_state matches 0 run tellraw @s [{"text": "Click here to place the game into op-only mode and authenticate as an operator", "color": "green", "clickEvent": {"action": "run_command", "value": "/function mob_dash:op"}}]
execute if score $OpOnly md_state matches 1 run tellraw @s [{"text": "The game is already in op-only mode. Click here to authenticate as an operator", "color": "green", "clickEvent": {"action": "run_command", "value": "/function mob_dash:op"}}]

scoreboard players reset @s OpControl
10 changes: 10 additions & 0 deletions data/mob_dash/functions/randomize_team.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Store a random team id into md_team

scoreboard players set $Random md_state 0

function mob_dash:randomize_bit
function mob_dash:randomize_bit
function mob_dash:randomize_bit

scoreboard players add $Random md_state 1
scoreboard players operation @s SetTeam = $Random md_state
43 changes: 27 additions & 16 deletions data/mob_dash/functions/tick_menu.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,46 @@ effect give @a minecraft:weakness 1 100 true
effect give @a minecraft:mining_fatigue 1 100 true
effect give @a minecraft:saturation 1 1 true

# Op-only mode

scoreboard players enable @a OpControl
execute as @a[scores={OpControl=1}] run function mob_dash:op_auth

# Menu handling

tag @a remove md_menu
execute if score $OpOnly md_state matches 0 run tag @a add md_menu
execute if score $OpOnly md_state matches 1 run tag @a[tag=md_op] add md_menu

scoreboard players add @a md_ticks 0
execute as @a[tag=!md_assigned] run function mob_dash:new_player

scoreboard players add @a md_ticks 1

scoreboard players enable @a md_action
scoreboard players enable @a[tag=md_menu] md_action

execute as @a[scores={md_ticks=600..},tag=!md_tutorial] run function mob_dash:push_menu
execute as @a[scores={md_ticks=600..},tag=!md_tutorial,tag=md_menu] run function mob_dash:push_menu
execute as @a[tag=md_tutorial] run function mob_dash:tick_tutorial

execute as @a[scores={WinScore=-2147483647..2147483647}] run function mob_dash:set_win_score
scoreboard players enable @a WinScore
scoreboard players set @a WinScore -2147483648
execute as @a[scores={WinScore=-2147483647..2147483647},tag=md_menu] run function mob_dash:set_win_score
scoreboard players enable @a[tag=md_menu] WinScore
scoreboard players set @a[tag=md_menu] WinScore -2147483648

execute as @a[scores={TimeLimit=-2147483647..2147483647}] run function mob_dash:set_time_limit
scoreboard players enable @a TimeLimit
scoreboard players set @a TimeLimit -2147483648
execute as @a[scores={TimeLimit=-2147483647..2147483647},tag=md_menu] run function mob_dash:set_time_limit
scoreboard players enable @a[tag=md_menu] TimeLimit
scoreboard players set @a[tag=md_menu] TimeLimit -2147483648

# React to menu action clicks

execute as @a[scores={md_action=1}] run function mob_dash:trigger_tutorial
execute as @a[scores={md_action=2}] run function mob_dash:display_teams_menu
execute as @a[scores={md_action=3}] if entity @p[scores={md_team=1..8}] run function mob_dash:start_game
execute as @a[scores={md_action=3}] unless entity @p[scores={md_team=1..8}] run tellraw @s [{"text": "No players on any team, cannot start", "color": "red"}]
execute as @a[scores={md_action=4}] run function mob_dash:cycle_scoring
execute as @a[scores={md_action=5}] run function mob_dash:cycle_difficulty
execute as @a[scores={md_action=6}] run function mob_dash:cancel_tutorial
execute as @a[scores={md_action=101..109}] run function mob_dash:join_team
execute as @a[scores={md_action=1},tag=md_menu] run function mob_dash:trigger_tutorial
execute as @a[scores={md_action=2},tag=md_menu] run function mob_dash:display_teams_menu
execute as @a[scores={md_action=3},tag=md_menu] if entity @p[scores={md_team=1..8}] run function mob_dash:start_game
execute as @a[scores={md_action=3},tag=md_menu] unless entity @p[scores={md_team=1..8}] run tellraw @s [{"text": "No players on any team, cannot start", "color": "red"}]
execute as @a[scores={md_action=4},tag=md_menu] run function mob_dash:cycle_scoring
execute as @a[scores={md_action=5},tag=md_menu] run function mob_dash:cycle_difficulty
execute as @a[scores={md_action=6},tag=md_menu] run function mob_dash:cancel_tutorial
execute as @a[scores={md_action=7},tag=md_menu] run function mob_dash:assign_teams_menu
execute as @a[scores={md_action=101..109},tag=md_menu] run function mob_dash:join_team
execute as @a[scores={SetTeam=1..9},tag=md_menu] run function mob_dash:join_team

scoreboard players set @a md_action 0

0 comments on commit 145b3c0

Please sign in to comment.