記事へ移動
NeuraCoreユーザーWiki
← この章に戻る
組み込み Python

役に立つスクリプト

短く読み切れて、実際の仕事をする 3 本です。

来た人に一度ずつ挨拶する

新しく来た人に挨拶し、同じ人に繰り返さない店番です。

import time

greeted = set()

for minute in range(10):
    for person in avatar.get_nearby_avatars():
        if person["id"] in greeted or not person["name"]:
            continue
        greeted.add(person["id"])
        avatar.send_im(person["id"], "Hello, and welcome to the shop.")
    time.sleep(60)
  • greeted は重複を受け付けない集合です。同じ人へ二度挨拶しないのはこれのおかげです。
  • 内側のループが今いる人を見て、外側が 10 分間繰り返します。
  • まだ名前が分からない人は、名無しとして挨拶せずに飛ばします。
  • インスタント メッセージの送信には send_im の許可が必要です。

記録した経路にアバターを送り出す

経路は Patrol タブで自分が歩いて記録します。スクリプトは名前で開始できます。

routes = avatar.get_patrols()
print(routes)

for route in routes:
    if route["name"] == "Garden round":
        avatar.play_patrol(patrol=route["id"], loop=True)
        break
  • get_patrols はこのアバターの経路一覧を返します。各項目に id と付けた名前があります。
  • loop=True で、止められるまで回り続けます。
  • 記録にはアバターごとに 1 本の Individual、または 100 本の Business が必要です。再生に制限はありません。

この環境のライセンスを確認する

動かしっぱなしにするスクリプトの冒頭に置くと役立ちます。

licence = avatar.get_licence_state()

print(licence["tier"])
print(licence["licensed"])

for slot in licence["slots"]:
    print(slot["slot_index"], slot["avatar_name"], slot["individual_days"])
  • tier は動作中のライセンス、licensed はアバターが実際に接続してよいときだけ真になります。
  • slot はそれぞれ座席で、載っているアバターと残り日数が分かります。スロット 0 は保有者のもので、時間は持ちません。
  • これは読むだけです。ライセンスの付与や延長は、意図してスクリプトの手が届かないようにしてあります。