Determine damage causer

I have been trying to see if I can make something happen when a player is damaged by a pickaxe. I was able to subscribe to DamagedEvent() for the player and from that can get the damage value but haven’t been able to go deeper than that.

The DamagedEvent returns a type damage_result struct - that struct has a couple things including for example the damage amount which I was able to access. More interestingly according to the docs it also contains a Source of type game_action_causer. This seems to contain info about the weapon that was used and possibly other info and I have confirmed an object of this type is returned but there are no methods specified for accessing anything inside the game_action_causer.

Curious if anyone here has played around with this or has any idea how to get info out of the game_action_causer. I realize it might be the case that epic has purposely hidden this but I thought it was interesting I was able to actually get a game_action_causer object.

game_action_causer is a marker interface. I haven’t worked with it myself but it looks like the only class currently implementing the interface is fort_character. I suspect that in the future as the APIs are expanded other classes like weapon and vehicle will also implement this interface.

To work with damaged_result you would attempt to cast the game_action_causer to different types to determine what type of object caused damage to the player. For example:

OnDamaged(DamagedEvent:damaged_event):void =
    if (CauserCharacter := fort_character[DamagedEvent.Source?]):
        # Game code...
3 Likes

How would one instantiate and listen to damaged_event in this case? Would you need to grab the player in question/all players in the space and then subscribe to the events on that particular character? I’m just a little confused at how to approach this interface

The code doesn’t work. When a player is damaged by another player, nothing happens

Thanks @Incredulous_Hulk that is quite interesting. Thanks for the info. I do hope that we get a weapon and vehicle api in the future - I can think of lots of fun things to try with that.

For everyone else: if you want to run code (ie execute OnDamaged(...)) you first need to subscribe to the damaged event for the FortCharacter you are interested in. Something like:

FortCharacter.DamagedEvent().Subscribe(OnDamaged)

I can get the causer, how do I get the target/who was this damage caused on? damage_result has target but how do you an agent/player from this?

I’ve noticed its a little unrealiable subscribing to this

GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)

I did my damage subscribing here - but my main player I play with doesnt get that event when I launch, however a secondary player I connect into my session later does, I think you’d want to use the spawner pad spawn event to use as your subscriber event - anyway, log everything and make sure its doing what you want it to do

In my game I use

GetPlayspace().GetPlayers() 

to get all players then subscribe to the DamagedEvent. Once you have the causer you will need to follow Incredulous_Hulk’s suggestion above to cast the DamagedEvent.Source to a fort_character.