# 小游戏初始化 execute if score $mini_type mem matches 1 run function mini:parkour/game_init execute if score $mini_type mem matches 2 run function mini:tntrun/game_init execute if score $mini_type mem matches 3 run function mini:hotpm/game_init execute if score $mini_type mem matches 4 run function mini:colormatch/game_init execute if score $mini_type mem matches 5 run function mini:phantom/game_init ## 下面一行是你新添加的 execute if score $mini_type mem matches 6 run function mini:koth/game_init
execute if score $mini_type mem matches 201 run function mini:ass/game_init execute if score $mini_type mem matches 101 run function mini:iron/game_init execute if score $mini_type mem matches 102 run function mini:trade/game_init
## 设置游戏结束后排名显示中是否显示玩家所获得的小游戏内分数。这里山丘之王小游戏的排名是依照 HUD 右侧计分板显示的能量值排序的,因此游戏结束后可以对所有玩家显示分数(能量值)。若你的游戏为竞速类、死亡淘汰类或者其他不使用自定义分数排名的小游戏,请将该值设为0 scoreboard players set $show_score mem 1 ## 重置奖励物品生成的冷却时间 scoreboard players set $new_item_cd mem 0 ## 这是一个冒险模式小游戏,因此生存模式的值为0。如果你做的是一个生存模式小游戏,请将该值设为1,以防止系统锁定第九格物品栏。 scoreboard players set $survival mem 0 ## 重置每0.1秒减少1的计时器,这条命令仅在你的游戏不需要使用这类计时器的情况下添加 scoreboard players set $countdown_fast mem 0 ## 是否启用与遗迹寻宝小游戏中类似的节奏方块,如果你的场景中没有这类方块可以不写该命令 scoreboard players set $tempo_enable mem 0
# 游戏结束倒计时,我这里为120秒 scoreboard players set $countdown mem 120
# HUD,通常为玩家所看到的游戏相关信息 scoreboard objectives setdisplay list power_count scoreboard objectives setdisplay belowName power_count scoreboard objectives setdisplay sidebar power_count ## boss栏颜色,1,2,3,4分别代表红、黄、绿、蓝,0代表按照每个玩家在bossbar_color的计分项内的分数对每个玩家显示不同颜色的boss栏(例如炸弹狂魔里面获得炸弹与未获得炸弹的玩家看到的boss栏不一样) scoreboard players set $bossbar_color mem 4 ## boss栏倒计时的最大值 scoreboard players set $countdown_max mem 120 ## boss栏类型,0,1,2分别代表关闭boss栏、显示快速倒计时(0.1秒减少1单位)和显示标准倒计时(1秒减少1单位) scoreboard players set $bossbar_type mem 2 ## 调用显示boss栏方法 function lib:bossbar/show ## 更改每种颜色的boss栏的名字 bossbar set mini:red name "剩余时间" bossbar set mini:yellow name "剩余时间" bossbar set mini:blue name "剩余时间"
# 如果是旁观者或局号不对头:开始旁观 execute if entity @s[team=!playing] run function ltw:main/player_enter_watcher execute if entity @s[team=playing] unless score @s game_id = $ game_id run function ltw:main/player_enter_watcher # 如果不是旁观且局号正确:游戏中掉线 execute if entity @s[team=playing] if score @s game_id = $ game_id run function ltw:main/player_enter_rejoin
# 显示倒计时 execute if score $countdown mem matches ..10 run title @a times 3 14 2 execute if score $countdown mem matches ..10 run title @a subtitle {"score":{"name":"$countdown","objective":"mem"}} execute if score $countdown mem matches ..10 run title @a title [""] execute if score $countdown mem matches ..10 as @a at @s run function lib:sounds/hit2
# 90s:双倍提示 execute if score $countdown mem matches 90 run title @a subtitle {"text":"⚠ 双倍能量将在三十秒后开启! ⚠","color":"yellow"} execute if score $countdown mem matches 90 run title @a times 1 90 3 execute if score $countdown mem matches 90 run title @a title "" ## 更改bossbar颜色为黄色,下同 execute if score $countdown mem matches 90 run scoreboard players set $bossbar_color mem 2 ## bossbar颜色更改需要重新调用show方法,下同 execute if score $countdown mem matches 90 run function lib:bossbar/show
# 60s:双倍开启 ## 这里不直接调整能量值的给予量,给予1点还是2点能量值会在tick5里面判定 ## 更改BGM execute if score $countdown mem matches 61 as @a run function lib:sounds/music/mini_fast execute if score $countdown mem matches 60 run title @a subtitle {"text":"⚠ 双倍能量已开启! ⚠","color":"red"} execute if score $countdown mem matches 60 run title @a times 1 120 3 execute if score $countdown mem matches 60 run title @a title "" execute if score $countdown mem matches 60 run scoreboard players set $bossbar_color mem 1 execute if score $countdown mem matches 60 run function lib:bossbar/show ## 播放音效 execute if score $countdown mem matches 60 run playsound minecraft:entity.ender_dragon.growl player @a 0 900000 0 900000 1.5
# 0s:游戏结束 execute if score $countdown mem matches 0 run function mini:main/game_end
如果你的游戏还有别的倒计时事件,需要一并在该函数里加上。
C. 能量值的给予
每0.25秒给予游戏内的玩家1点(双倍能量时为2点)能量值。
data/mini/functions/koth/tick5.mcfunction:
1 2 3
# 给予红区玩家能量值 execute if score $countdown mem matches 61.. as @a[team=playing,tag=mini_running] at @s if block ~ 9 ~ red_mushroom_block run scoreboard players add @s power_count 1 execute if score $countdown mem matches ..60 as @a[team=playing,tag=mini_running] at @s if block ~ 9 ~ red_mushroom_block run scoreboard players add @s power_count 2
# 给予击退鱼 execute as @a[tag=mini_running] at @s if block ~ 9 ~ red_mushroom_block unless data entity @s Inventory[{Slot:8b,id:"minecraft:cod",tag:{game_item:1b,powerful:0b}}] run function mini:koth/game/give_fish execute as @a[tag=mini_running] at @s unless block ~ 9 ~ red_mushroom_block unless data entity @s Inventory[{Slot:8b,id:"minecraft:cod",tag:{game_item:1b,powerful:1b}}] run function mini:koth/game/give_fish
# 返还格子上的物品 ## 此处设定需要返还的物品栏位,快捷栏第九格为8 execute if data entity @s Inventory[{Slot: 8b}] run scoreboard players set @s item_slot 8 ## 此处调用返还物品方法,没有物品时不会返还任何东西 execute if data entity @s Inventory[{Slot: 8b}] at @s run function item:pop_slot/return_item
# 判断是否符合刷出新物品的条件:0 为可以,其他为不可以 scoreboard players set #new_item mem 0
# 当前场地上没有物品 execute if entity @e[tag=bonus_item,x=985.0,y=4.0,z=8985.0,dx=32,dy=32,dz=32] run scoreboard players set #new_item mem 1
# 如果没有物品,则计算冷却 execute if score #new_item mem matches 0 run scoreboard players add $new_item_cd mem 1 # 已经超过 15s 冷却时间 execute if score $new_item_cd mem matches ..14 run scoreboard players set #new_item mem 1
# 如果上述条件均满足,则刷出新物品 execute if score #new_item mem matches 0 run function mini:koth/game/new_item
# 重置冷却时间 scoreboard players set $new_item_cd mem 0
# 随机选择生成组 scoreboard players set $random_min mem 0 scoreboard players set $random_max mem 1 function lib:random
# 生成物资 execute if score $random mem matches 0 positioned 1014.5 16 8987.5 run function item:bonus_item/gameparty/auto/low execute if score $random mem matches 0 positioned 987.5 16 9014.5 run function item:bonus_item/gameparty/auto/low execute if score $random mem matches 1 positioned 1014.5 16 9014.5 run function item:bonus_item/gameparty/auto/low execute if score $random mem matches 1 positioned 987.5 16 8987.5 run function item:bonus_item/gameparty/auto/low execute as @e[tag=bonus_item] run data modify entity @s NoGravity set value 0b
# 显示提示 title @a subtitle {"text":"❇ 奖励物资已在空中部署 ❇","color":"aqua"} title @a times 1 60 3 title @a title "" tellraw @a ["",{"text": ">> ","color":"aqua","bold": true},{"text":"奖励物资:","color":"aqua"},{"selector": "@e[tag=bonus_item]"}] playsound minecraft:entity.player.levelup player @a 0 1000000 0 1000000 2
# 调整物品:仅在纵向速度 < -0.015 且 y > 12 时,才将 NoGravity 设置为 false execute as @e[tag=bonus_item] store result score @s temp run data get entity @s Motion[1] 1000 execute as @e[tag=bonus_item] if entity @s[x=985.0,y=12.0,z=8985.0,dx=32,dy=32,dz=32,scores={temp=-15..}] run data merge entity @s {NoGravity: 0b} execute as @e[tag=bonus_item] unless entity @s[x=985.0,y=12.0,z=8985.0,dx=32,dy=32,dz=32,scores={temp=-15..}] run data merge entity @s {NoGravity: 1b}
# 测试用:快速开始山丘之王 team join playing @a[team=watching] clear @a[team=!debugging] function ltw:state/0/start_game scoreboard players set $round mem 5 scoreboard players set $mini_type mem 6 function mini:main/game_init function ltw:state/4/state_enter say 已开始单个测试游戏!
schedule function test:countdown/quick 20t
先别急着在服务器里输入/reload命令!因为游艺街内置一个游戏结束判定,即人数等于1时游戏会自动结束(遗迹寻宝除外)。因此如果你是在一个人测试这个新游戏,那么游戏就会在开始之后的一瞬间结束!为了防止这种现象的发生,我们需要更改游戏结束的判定代码。在原有的run前面加上一句unless score $mini_type mem matches 6,这样你的游戏就不会自动结束了。
function mini:main/update_player_count execute if score $state mem matches 5 if score $player_alive mem matches ..1 unless score $mini_type mem matches 1 unless score $mini_type mem matches 6 run function mini:main/game_end
# 常量与变量初始化 ## 把这里的5改成6 scoreboard players set #mini_total mem 6 scoreboard players set #-1 mem -1 scoreboard players set #0 mem 0 scoreboard players set #1 mem 1 scoreboard players set #2 mem 2
# 前置/后置小游戏 # 如果为第 1 轮,则有一半概率选用刺客,一半概率不变 # 如果为第 5 轮,则有一半概率选用钢铁,一半概率选用贸易 scoreboard players set $random_max mem 1 scoreboard players set $random_min mem 0 function lib:random execute if score $round mem matches 1 if score $random mem matches 0 run scoreboard players set $mini_type mem 201 execute if score $round mem matches 5 if score $random mem matches 0 run scoreboard players set $mini_type mem 101 execute if score $round mem matches 5 if score $random mem matches 1 run scoreboard players set $mini_type mem 102
# 前置/后置小游戏 # 如果为第 1 轮,则有 40% 概率选用刺客,40% 概率选用掘战,20% 概率不变 # 如果为第 6 轮,则有 20% 概率选用钢铁,20% 概率选用钻石,20% 概率选用贸易,40% 概率选用富翁之路 scoreboard players set $random_max mem 5 scoreboard players set $random_min mem 1 function lib:random execute if score $round mem matches 1 if score $random mem matches 1..2 run scoreboard players set $mini_type mem 201 execute if score $round mem matches 1 if score $random mem matches 2..3 run scoreboard players set $mini_type mem 202 execute if score $round mem matches 6 if score $random mem matches 1 run scoreboard players set $mini_type mem 101 execute if score $round mem matches 6 if score $random mem matches 2 run scoreboard players set $mini_type mem 102 execute if score $round mem matches 6 if score $random mem matches 3 run scoreboard players set $mini_type mem 103 execute if score $round mem matches 6 if score $random mem matches 4..5 run scoreboard players set $mini_type mem 104
# 给予进度 advancement grant @a[team=playing,scores={power_count=100..}] only ltw:vs/koth1 advancement grant @a[team=playing,scores={power_count=180..}] only ltw:vs/koth2 advancement grant @a[team=playing,scores={power_count=250..}] only ltw:vs/koth3 advancement grant @a[team=playing,scores={power_count=320..}] only ltw:vs/koth4