LoginSignup
0
0

【UEFN】Verseでプレイヤーを回復させてみる

Last updated at Posted at 2023-12-18

背景

最近メタであるボックスPVPを作ろうとしたときに一定の間隔で回復する役職を作りたかったので調査してきました。

image.png
image.png

やること

セッションにいるプレイヤーそれぞれ一秒ごとに10体力を回復させる機能をつけます。

動画

実装

全体コード

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }

player_heal_device := class(creative_device):

    OnBegin<override>()<suspends>:void=
        Print("Hello, world!")
        Print("2 + 2 = {2 + 2}")
        AllPlayers := GetPlayspace().GetPlayers()
        for (Player : AllPlayers):
            if(FortCharacter := Player.GetFortCharacter[]):
                Heal(FortCharacter)

    Heal(FortCharacter : fort_character)<suspends>:void=
        Print("Healing player !")
        # 体力が回復することを確認するために、一時的に体力を10に設定します。
        FortCharacter.SetHealth(10.0)
        loop:
            Sleep(1.0)
                FortCharacter.Heal(10.0)

いつものGetPlayspaceでそのセッションにいるプレイヤーを取得してそれぞれのfort_characterを取得している感じになります。

fort_characterはhealableインターフェースを実装しているので以下の関数がプレイヤーに対して有効でした。

    # Implemented by Fortnite objects that can be healed.
    healable<native><public> := interface<epic_internal>:
        # Heal the `healable` object anonymously by `Amount`. Setting `Amount` to less than 0 will cause no healing.
        # Use `Heal(:healing_args):void` when healing is being applied from a known instigator and source.
        Heal<public>(Amount:float):void

        # Cause `Args.Amount` damage to the `damageable` object. Setting `Amount` to less than 0 will cause no damage.
        Heal<public>(Args:healing_args):void

        # Signaled when healing is applied to the `healable` object.
        HealedEvent<public>():listenable(healing_result)

今回はただ回復させたいだけだったのでHeal<public>(Amount:float):voidを使いました。
Heal<public>(Args:healing_args):voidこちらの関数は回復してくれたプレイヤーなどのオプションを付けて回復させることができるようです。

fort_characterでキャラ関連の操作は何でも行けそう?

    fort_character<native><public> := interface<unique><epic_internal>(positional, healable, healthful, damageable, shieldable, game_action_instigator, game_action_causer):

fort_characterに実装されているインターフェースを見た感じだと体力やシールド、このプレイヤーに影響を与えた・与えられたプレイヤーなどさまざあなことが取れそう。

まとめ

今回もシンプルに実装できました。

game_action_instigator,game_action_causerインターフェースも利用できるようになれば相手に与えたダメージ分だけ回復するとかが実装できそうでした。

余談

この度UEFN/Verseに関するオープンコミュニティサーバーを建ち上げました。ちょっとでも興味があれば奮ってご参加くださいませ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0