|
Post by drenyn on Apr 6, 2020 18:19:06 GMT
Trying to use vItemManager.UseItem through Unity Event, but it's wanting a (V Item) to be selected and there doesn't appear to be any in the assets. Does anyone know if it's possible to use this as an Event or not, and if so, how you generated the V Item to place in the event?
Thanks!
|
|
|
Post by Chronicman on Apr 6, 2020 18:29:12 GMT
the vItem is the item being used.
Example: OnUse() will trigger an event which will pass the vItem though the event. So if you used a health pot it will pass that item.
What exactly are you trying to do with the event ?
|
|
|
Post by drenyn on Apr 6, 2020 18:30:43 GMT
the vItem is the item being used. Example: OnUse() will trigger an event which will pass the vItem though the event. So if you used a health pot it will pass that item. What exactly are you trying to do with the event ? I'm trying to use a key card, but it's not showing as an item available to add to the event.
|
|
|
Post by Chronicman on Apr 6, 2020 18:35:01 GMT
I haven't used the keycards like that before so this is fresh for me. What function do you need to call from that event ? can you set it up dynamically ?
|
|
|
Post by Chronicman on Apr 6, 2020 18:36:31 GMT
When a UnityEvent has a parameter you can use it 2 ways. Where you can manually set the parameter or dynamically. The dynamic methods are at the top of the list of functions.
|
|
|
Post by drenyn on Apr 6, 2020 18:54:41 GMT
When a UnityEvent has a parameter you can use it 2 ways. Where you can manually set the parameter or dynamically. The dynamic methods are at the top of the list of functions. I don't see anything that would allow me to either use the Item (Keycard) or verify that the Item is in the inventory dynamically. The only thing I've found was the .UseItem function. :(
|
|
|
Post by Chronicman on Apr 6, 2020 19:11:44 GMT
Ok now I see what your trying to do.
I don't know if there is a method build in to tell you that a Item exists in your inventory. I can however help you code one fast.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Invector.vItemManager;
using UnityEngine.Events;
public class ItemCheck : MonoBehaviour
{
public UnityEvent hasItem;
public UnityEvent noItem;
private GameObject user;
private vItemManager itemManager;
public void UpdateUser(GameObject gameObject)
{
user = gameObject;
}
public void ClearUser(GameObject gameObject)
{
user = null;
}
public void DestoryItem(int id)
{
itemManager = user.GetComponent<vItemManager>();
itemManager.DestroyItem(itemManager.itemListData.items[id], 1);
}
public void CheckIfItemExists(int id)
{
itemManager = user.GetComponent<vItemManager>();
var item = itemManager.items.Find(i => i.id == id);
if (item != null)
{
hasItem.Invoke();
}
else
{
noItem.Invoke();
}
}
}
|
|
|
Post by Chronicman on Apr 6, 2020 19:16:37 GMT
Attach this to your door or what ever.
Call UpdateUser OnPlayerEnter event Dynamically. Call ClearUser OnPlayerExit event Dynamically. Call CheckIfItemExists OnPressActionInput pass the id of the key. On hasItem Call your events to open what ever. You can also call the DestroyItem
|
|
|
Post by drenyn on Apr 6, 2020 19:23:37 GMT
Attach this to your door or what ever. Call UpdateUser OnPlayerEnter event Dynamically. Call ClearUser OnPlayerExit event Dynamically. Call CheckIfItemExists OnPressActionInput pass the id of the key. On hasItem Call your events to open what ever. You can also call the DestroyItem I bow before your greatness!!! Thank you sir.
|
|
|
Post by Chronicman on Apr 6, 2020 19:26:39 GMT
welcome
|
|
|
Post by Chronicman on Apr 7, 2020 21:43:51 GMT
Hey man I made a mistake in the destroy method you should update it to this.
public void DestoryItem(int id)
{
itemManager = user.GetComponent<vItemManager>();
var itemToDestroy = itemManager.GetItem(id); itemManager.DestroyItem(itemToDestroy, 1);
} You should also check your database amount for the items you tried to destroy if you did try at all.
|
|