-
Notifications
You must be signed in to change notification settings - Fork 6
libraries
乱数を取得します
execute store result ... run function lib:random/
乱数として生成される値は
0~65535までの範囲です。
注: このライブラリはもやんのせいでfunction内以外から実行すると6しか取得できません。function内で実行する分には問題ないからバグ報告しないでね☆
# 25%の確率で「excellent!」,50%の確率で「great」,25%の確率で「miss」と出力するコマンド
# 疑似乱数取得
execute store result score $Random Temporary run function lib:random/
# ほしい範囲に剰余算
scoreboard players operation $Random Temporary %= $100 Const
# メッセージ出力
execute if score $Random Temporary matches 00..24 run say excellent!
execute if score $Random Temporary matches 25..74 run say great
execute if score $Random Temporary matches 75..99 run say miss
# リセット
scoreboard players reset $Random Temporary指定した確率でtrueを返すpredicateです。
execute if predicate lib:random_pass_per/<確率>
@a[predicate=lib:random_pass_per/<確率>
確率に指定可能な値は
1~99までの範囲です。
# 30%の確率で「pass!」と出力するコマンド
execute if predicate lib:random_pass_per/30 run say pass!そのtickにそのプレイヤーを攻撃したEntityを特定する実装です。
使用可能な個所にて@e[type=#lib:living,type=!player,tag=Attacker]
そのtickにそのプレイヤーが攻撃したEntityを特定する実装です。
使用可能な個所にて@e[type=#lib:living,type=!player,tag=Victim]
天候が指定した天候の場合trueを返すpredicateです。
execute if predicate lib:weather/is_<sunny|raining|thundering>
# 天候が雨の場合のみ「rain!」と出力するコマンド
execute if predicate lib:weather/is_raining run say rain!Work In Progress...
実行Entity(type=!player)に実行方向の$VectorMagnitude*0.01Block分のMotionを付与します。
at,rotatedと併用してください
function lib:motion/
# 5m以内のEntityに1Block分の視点方向のMotionをかけるコマンド
scoreboard players set $VectorMagnitude 100
execute as @e[type=!player,distance=..5] at @s run function lib:motion/
# 5m以内のEntityが自分めがけて飛んでくるコマンド
scoreboard players set $VectorMagnitude 500
execute as @e[type=!player,distance=..5] at @s facing entity @p feet run function lib:motion/汎用Entity(0-0-0-0-0)を実行方向のランダムな位置に移動させます。
| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| Argument.Distance | o | double | 実行位置からどのくらい離すか | - |
| Argument.Spread | o | double | 離れた位置でどのくらい拡散するか | - |
note: Spreadの値が-4.634~4.634の範囲を出る場合、内部処理でオーバーフローし正常に動作しなくなります。
function lib:forward_spreader/<square|circle>
# 10mで2.5mのブレが発生する矢を放つコマンド
# 0-0-0-0-0を視点10m先の2.5m以内のランダムな位置に移動させる
data modify storage lib: Argument.Distance set value 10.0
data modify storage lib: Argument.Spread set value 2.5
function lib:forward_spreader/circle
# 矢を召喚して飛ばす
execute anchor eyes run summon arrow ^ ^ ^ {Tags:[ArrowInit]}
scoreboard players set $VectorMagnitude 250
execute as @e[type=arrow,tag=ArrowInit,distance=..2] at @s facing entity 0-0-0-0-0 feet run function lib:motion/
# リセット
tag @e[type=arrow,tag=ArrowInit,distance=..2] remove ArrowInit