Invoke item actions from code

ChristianWiele

Active member
Hi,

I would like to invoke an item action from code, but have not found an example. I want to implement a kind of auto-heal. If the health attribute reaches 0 I want to check if the character has some health potion in the inventory, and apply it if the amount is > 0.
Any example for this available? (using the UCC integration)

Thanks, Christian
 
There are multiple options:
1) Use a (Category)ItemActionSet with the Item Action you want, initialize it and call the "UseAllItemActions" or the "UseItemAction" function on it.

2) Create an object with Item Action type of your choice and call the Invoke Action on it. Item Actions are simple C# classes. So you can create one in Start, Awake or during an Initialization phase and then you may call the "InvokeAction" on it.

Code not tested:
Code:
//Do this once on initialize.
var itemAction = new CharacterModifyAttributeItemAction();
itemAction.Initialize(false);

//Then use the item action on the item of your choice.
itemAction.InvokeAction(itemInfo, m_ItemUser);

3) Instead of using an ItemAction for this you can simply write the code to directly affect the health of the player using the item attribute. You can copy paste the code from our item action to get started quickly.

If you wish to use option 1 or 2 the Item Action you'll want to use with the Integration is the CharacterModifyAttributeItemAction.

I hope that helps
 
Top