Really good question!
First off, I’m slightly unsure about the logic that you actually want, but I’ll give you some base ideas that can hopefully get you off the ground.
The key to this is the conditional button and more specifically the IsHoldingItem()
function in verse (to check what weapon is equipped). To create a basic example, what I did was to create a sentry in my world, check for the EliminatedEvent, and then checked what item the player is currently holding with the conditional button (which of course needs to be configured first).
Then, I wrote some verse code to check if the sentry had died:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
register_weapon := class(creative_device):
@editable AR_Conditional : conditional_button_device = conditional_button_device { }
@editable SentryTest : sentry_device = sentry_device { }
OnBegin<override>()<suspends>:void=
SentryTest.EliminatedEvent.Subscribe(SentryElim)
SentryElim(MaybeAgent : ?agent):void=
if (Player := player[MaybeAgent?]):
if (AR_Conditional.IsHoldingItem[Player]):
Print("Player is currently holding the AR!")
# magic
And indeed, it printed. Now, you probably also want it to work with players, which is a pretty similar concept:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
register_weapon := class(creative_device):
@editable AR_Conditional : conditional_button_device = conditional_button_device { }
@editable SentryTest : sentry_device = sentry_device { }
OnBegin<override>()<suspends>:void=
Players := GetPlayspace().GetPlayers();
for (Player : Players, Char := Player.GetFortCharacter[]):
Char.DamagedEvent().Subscribe(OnPlayerHit)
OnPlayerHit(Result : damage_result):void=
if (InstigatorObj := Result.Instigator?, InstigatorAgent := agent[InstigatorObj]):
if (AR_Conditional.IsHoldingItem[InstigatorAgent]):
Print("Player is currently holding the AR!")
# magic
Note: I used DamagedEvent here, but not in the sentry, simply because it didn’t immediately seem available in the sentry, and I’m still unsure of your desired outcome.
Extra note: I don’t know if it actually works, I haven’t tested with other players lol.
Sadly, I don’t think it’s possible to check for the weapon rarity in verse yet, as Epic haven’t implemented the weapon API, but hopefully it’ll be available in the near future