How do I use ItemPickedUpEvent ?

if (CastSpawner := item_spawner_device[Spawner]):
                CastSpawner.ItemPickedUpEvent.Subscribe(ItemCollected)

I’ve set up events for each of my tagged spawners…

    ItemCollected(e : agent):void=
        Print("item collected")

…and they’re working. But I don’t know what sort of object that agent is or what I can do with it.

I could really do with knowing what’s been picked up, or which spawner it’s been picked up from, and by whom. Or just the player, but in which case I need to know what they’re carrying.

Ta.

That’s how you cast the agent to a player, as for getting the item that was picked up and by which spawner, looking at the docs (item_spawner_device class), currently there aren’t any members which provide that information, unless I’ve missed something.

This may not be the most elegant solution, but you could have separate item spawners as their own @editable prop and assign them to your creative_device, say one with a Pistol and one with an Assault Rifle.

Then in that custom device’s Verse script, subscribe to each spawner individually but pass through a unique callback function to the Subscribe method depending on the spawner/item. Example: ItemCollectedPistol and ItemCollectedAssaultRifle.

That way when a player picks up the item up from that spawner, only the specific method you requested gets fired, so that way you know which spawner, which item, then if you cast Agent to Player in that method, you also know the player. Not sure how to get the players inventory yet, but there is a post here asking the same question which you might want to set up notifications for!

1 Like

It is indeed a player, so that casting worked. Ta.

I will have way too many spawners to subscribe to them individually, but I’ll have fewer drop off points so I’ll make a spawner tag for each drop off point and subscribe to each group of tagged spawners individually.

I can also use that to keep track of the player’s inventory - as long as you can only pick up one item at a time from spawner, drop all of an item type at once at capture devices, and can never gain or lose inventory by any other means. All those should hold true, but I don’t particularly like having a second source of truth!