Trying to activate the OnButtonClick through the OnPlayerDamaged

I’m trying to activate this knockback event when a player is damaged but I have no idea how to integrate the two

using { /Fortnite.com/Devices }
using { /Fortnite.com/Playspaces }
using { /Fortnite.com/Teams }
using { /Fortnite.com/Game }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }
using { /Verse.org/Native }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }

Game_Manager := class(creative_device):

@editable
MovementButton:button_device = button_device{}

@editable
MM_Mover:creative_prop = creative_prop{}

@editable
MM:movement_modulator_device = movement_modulator_device{}

@editable
PlayerSpawner: player_spawner_device = player_spawner_device{} 


(Prop:creative_prop).ActivateKnockBackEffect(Agent:agent)<suspends>:void =
    if(Fort:=Agent.GetFortCharacter[]):
        option:
            Yaw := Fort.GetViewRotation().GetYawPitchRollDegrees()[0]
            Pitch := 0.0
            Roll := 0.0
            NewRotation := MakeRotationFromYawPitchRollDegrees(Yaw,Pitch,Roll)
            if(Prop.TeleportTo[Fort.GetTransform().Translation - vector3{Z:=120.0},NewRotation]):
              
        Sleep(0.1)
        MM.Activate(Agent)
        Sleep(0.1)
        
        option:
            Prop.TeleportTo[Prop.GetTransform().Translation - vector3{Z:=500.0},Prop.GetTransform().Rotation]
        


OnBegin<override>()<suspends>:void=
    MovementButton.InteractedWithEvent.Subscribe(OnButtonClick)
    PlayerSpawner.SpawnedEvent.Subscribe(OnPlayerSpawned)

OnPlayerSpawned(Agent:agent):void=
    if(FC:= Agent.GetFortCharacter[]):
        FC.DamagedEvent().Subscribe(OnPlayerDamaged)

OnPlayerDamaged(d:damage_result):void=
        if(InstigatorCharacter := fort_character[d.Target],player[InstigatorCharacter.GetAgent[]]):

OnButtonClick(Agent:agent):void=
if(FC:=Agent.GetFortCharacter):
option:
MM_Mover.TeleportTo[FC.GetTransform().Translation, FC.GetTransform().Rotation]
spawn:
MM_Mover.ActivateKnockBackEffect(Agent)

Why do you need a prop to knockback a player ? Also using an if inside an option block is wild, didn’t even know it was a thing :smiley:

A bunch of your code fell outside the format block so its unclear if this is the complete code and also unclear what scope/indent some of it is on — just fyi.

side question - Is it common to use empty IF:s to execute a decide expressions?

if(Prop.TeleportTo[Fort.GetTransform().Translation - vector3{Z:=120.0},NewRotation]):
# empty?

What is the expected behavior and how is it acting now? If you click the button does it knock you back? If this method of player moving is proven then do you have any other verse build errors?

You wrote MM.Activate(), wouldn’t it be MM_Mover? Did you mean Enable as in creative_device? Not sure how the build process wouldn’t have brought this to your attention, but maybe you have an MM class level var :slight_smile:

using { /Fortnite.com/Devices }
using { /Fortnite.com/Playspaces }
using { /Fortnite.com/Teams }
using { /Fortnite.com/Game }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }
using { /Verse.org/Native }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }

Game_Manager := class(creative_device):

@editable
MovementButton:button_device = button_device{}

@editable
MM_Mover:creative_prop = creative_prop{}

@editable
MM:movement_modulator_device = movement_modulator_device{}

@editable
PlayerSpawner: player_spawner_device = player_spawner_device{} 


(Prop:creative_prop).ActivateKnockBackEffect(Agent:agent)<suspends>:void =
    if(Fort:=Agent.GetFortCharacter[]):
        option:
            Yaw := Fort.GetViewRotation().GetYawPitchRollDegrees()[0]
            Pitch := 0.0
            Roll := 0.0
            NewRotation := MakeRotationFromYawPitchRollDegrees(Yaw,Pitch,Roll)
            if(Prop.TeleportTo[Fort.GetTransform().Translation - vector3{Z:=120.0},NewRotation]):
              
        Sleep(0.1)
        MM.Activate(Agent)
        Sleep(0.1)
        
        option:
            Prop.TeleportTo[Prop.GetTransform().Translation - vector3{Z:=500.0},Prop.GetTransform().Rotation]
        


OnBegin<override>()<suspends>:void=
    MovementButton.InteractedWithEvent.Subscribe(OnButtonClick)
    PlayerSpawner.SpawnedEvent.Subscribe(OnPlayerSpawned)

OnPlayerSpawned(Agent:agent):void=
    if(FC:= Agent.GetFortCharacter[]):
        FC.DamagedEvent().Subscribe(OnPlayerDamaged)

OnPlayerDamaged(d:damage_result):void=
        if(InstigatorCharacter := fort_character[d.Target],player[InstigatorCharacter.GetAgent[]]):
           
OnButtonClick(Agent:agent):void=
            if(FC:=Agent.GetFortCharacter[]):
                option:
                     MM_Mover.TeleportTo[FC.GetTransform().Translation, FC.GetTransform().Rotation]
                spawn:
                    MM_Mover.ActivateKnockBackEffect(Agent)

Yes, when you click the button it knocks the player back (well forward at the moment and I’m working to fix that), I’m trying to activate this “knockback” when a player is damaged through -

OnPlayerSpawned(Agent:agent):void=
    if(FC:= Agent.GetFortCharacter[]):
        FC.DamagedEvent().Subscribe(OnPlayerDamaged)

OnPlayerDamaged(d:damage_result):void=
        if(InstigatorCharacter := fort_character[d.Target],player[InstigatorCharacter.GetAgent[]]):

and I’m not sure how to get it working
note - no current verse build errors

Sadly it is, I never use it because I find it dumb but a lot of creators use that syntax

Pretty sure your logic is failing at this spot ^ Add your call to
MM_Mover.ActivateKnockBackEffect(agent) under that if:

  • Those static variables InstigatorCharacter := .. inside this if expression are only accessible within the scope of the proceeding block, what was the goal with this line of code?
  • You cast it as player but never use it player[InstigatorCharacter.GetAgent[]]

I didn’t test it specifically but try something like this?

OnPlayerDamaged(d:damage_result):void=
    if(InstigatorCharacter := fort_character[d.Target], Player:=  player[InstigatorCharacter.GetAgent[]]):
        MM_Mover.ActivateKnockBackEffect(Player)

^ added Player := assignment && Activate call

edit: Not sure its a great “Pattern” long term but to answer the question / title specifically you could pretend to be a button and call OnButtonClick() there too