|
Post by moabishere on Jul 30, 2019 12:22:11 GMT
Hi developers!
I am trying to make a weapon draw system like in Counter Strike. Instead of using the right arrow button to cycle the weapons, I want to use 1-2-3-4-5 (or more) keys to switch weapons. I am using invector shooter-melee with inventory system.
The first question is, is there an easy way to do it. Weapon draw code is extremely complicated and almost impossible to edit!
I want to explain my algorithm:
1) I have a script which holds button-equip slot duos in a data structure like a dictionary. alpha1-equipslot0 , alpha2-equipslot1... 2) When I press 1 as an example, this script finds linked equipslot and reach the item attached to that equipslot. 3) After doing these operations, I am calling these lines
area.onEquipItem.Invoke(area, area.equipSlots[slotIndex].item);
lastEquipedItem = area.equipSlots[slotIndex].item; //this is to prevent re-draw the same weapon.
More or less, this approach works. However, I have a problem. At the very beginning of the game, character starts with a sword in his hands. I want to check this sword's item id (inside vItem script). I can reach item ID of the items which are attached to the equip slots but not the weapon's that the charachter holds at the beginning.
Anyone has an idea or a solution? I have spent 2 weeks to solve it but everything related with the inventory system in Invector is way too complicated.
Bests
|
|
|
Post by Invector on Jul 30, 2019 13:43:18 GMT
Did you check the vShooterOnly_WITHInventory&HipFire demo scene? it's already set up to to be 1-2-3-4 style, so it's halfway there, now if you want specific itemTypes for each slot, for ex: slot 1 for pistols, slot 2 for rifle, etc... you could create new itemTypes and filter these slots to only accept those types.
Now to get an item ID we have a few examples in the vInventory demo scene, such as the vContainsItemTrigger script
|
|
|
Post by moabishere on Jul 31, 2019 9:13:52 GMT
I managed to solve the problem. Your code falls short for many things. As an example, vShooterManager and vMeleeManager are completely different. In vShooterManager manager, there is a virtual field called "CurrentWeapon". I tried to find the item id using this field. However, there is no such option like "CurrentWeapon.id". Instead, I used "CurrentWeapon.GetComponent<vShooterEquipment>().referenceItem.id"
My character also uses melee weapons. I thought that there exist a CurrentWeapon field but there are any. Instead, there are rightWeapon and leftWeapon as vMeleeWeapon. Huge ambiguity here. My character uses only right weapon. This time I used "rightWeapon.GetComponent<vMeleeEquipment>().referenceItem.id;"
That is why I did not use vShooterOnly scenes. In the future, you should consider refactoring many classes. I am using invector for more than a year. It seems it is not suitable for editing or customizing.
Not: Please design your inventory system from scratch :D
Bests wishes!
|
|