汎用カウンタ
名前の通り
ただ汎用性を最強にしたかっただけです
その分大変面倒ですが…
まず、objectiveを作成します。
/scoreboard objectives add <objective> dummy <objective>
上記のコマンドにおいて、<objective>に以下の値をそれぞれ代入し、実行してください。
①パラメータのインプットに用いるもの
initialValue: カウンタの初期値
addedValue: カウンタの加算値
endValue: カウンタの終了値
dalayInTicks: ティックの遅延
②内部的な計算に用いるもの
currentValue: 現在のカウンタの値
delayManager: ティックの遅延を管理
stopManager: カウンタの停止を管理
次に、カウンタのパラメータを設定します。
全エンティティで共通して使用されるデフォルトパラメータを設定するには、
/scoreboard players set default <objective> <value>
を使用します。
また、各エンティティに固有のパラメータを設定するには、
/scoreboard players set <object> <objective> <value>
を使用します。
前者は、そのエンティティに固有なパラメータが存在しない時に使用されます。
後者は、デフォルトパラメータよりも優先して使用されます。
なお、パラメータを設定できるのは、上記objectiveのうち①のみです。
カウンタの初期化には、以下のコマンドを使用します。
/execute as <object> if score @s initialValue = @s initialValue run scoreboard players operation @s currentValue = @s initialValue
/execute as <object> unless score @s initialValue = @s initialValue run scoreboard players operation @s currentValue = default initialValue
/scoreboard players set <object> delayManager 0
/scoreboard players set <object> stopManager 0
カウンタの実行には、以下のコマンドを使用します。
/execute as <object> if @s endValue = @s endValue run scoreboard players operation @s stopManager = @s endValue
/execute as <object> unless @s endValue = @s endValue run scoreboard players operation @s stopManager = default endValue
/execute as <object> run scoreboard players operation @s stopManager -= @s currentValue
/execute as <object> if @s addedValue = @s addedValue run scoreboard players operation @s stopManager *= @s addedValue
/execute as <object> unless @s addedValue = @s addedValue run scoreboard players operation @s stopManager *= default addedValue
/scoreboard players add <object>[scores={stopManager=1..}] delayManager 1
/execute as <object>[scores={stopManager=1..}] if score @s delayInTick = @s delayInTick if score @s delayManager >= @s delayInTick run scoreboard players set @s delayManager 0
/execute as <object>[scores={stopManager=1..}] unless score @s delayInTick = @s delayInTick if score @s delayManager >= default delayInTick run scoreboard players set @s delayManager 0
/execute as <object>[scores={stopManager=1..,delayManager=0}] if score @s addedValue = @s addedValue run scoreboard players operation @s currentValue += @s addedValue
/execute as <object>[scores={stopManager=1..,delayManager=0}] unless score @s addedValue = @s addedValue run scoreboard players operation @s currentValue += default addedValue
機能
対象のエンティティに対し、カウンタ用スコアを付与します
カウンタの詳細は全体設定と個人設定の両方から設定することができます
初期値は設定したinitialValueに等しくなります
カウンタに対する値の加算は設定したdelayInTicks(単位:tick)ごとに行われます
ただし、0以下にした場合は1と同じものとして扱われます
加算値はaddedValueを参照します
カウンタの値がendValueを跨いだ場合、加算が停止します
また、stopManagerを1以上にした場合も停止します
用途
タイマー
クールダウン
等々
各個人ごとに加算速度や終了値を個別設定できるのが強みです
逆に個別設定が必要ないなら全体でまとめて設定できるのも強み