Post by pioni on Jul 21, 2018 17:49:10 GMT
Hey people. This is great integration. The melee weapons works great, but with the shooter. You cannot reload the weapon and the ammo wont update in inventory pro. This is becouse the onReloadWeapon listener is not working for some reason. I worked out a quick fix for this. Instead of using the listener im manually calling the function. So i will explain you guys how i got it working if some of you are intrested.
Pls note that im amateur at coding. This fix might not be the best way of doing this. Please backup your project before attempting this.
Please also note that if we are to manually call the reload weapon function in the vAmmoManager_InventoryPro. We have to modify the code of invector itself (vShooterManager). We are not actually removing any code from the ShooterManager. We just add some code to work with the vAmmoManager_InventoryPro.
My fix is made very quickly. There might be bugs and it is currently hard coded to work on right weapon only!
Note that codes are collapsed into regions. Open them all to avoid confusions.
So vAmmoManager_InventoryPro script. Please use vMonoBehaviour.
Open vShooterManager.cs
We need to use namespace for the integration files.
using.Devdog.InventoryPro.Integration.Invector;
Open the variables region. And in line 90. (Under [vEditorToolbar("Weapons")]) We need a reference for the new ammomanager.
[HideInInspector]
public vAmmoManager_InventoryPro inventoryManager;
Also if we are not to remove anything from invector code. We need a bool variable to determine if we want to use our method for reload or invectors.
add into line 93: public bool useInventoryAmmo = true;
You can now edit this bool value in the inspector under vShooterManager/weapons.
Under Start function we would get a null reference if we dont have normal vAmmoManager with our player
so on line 120 we need to close the updateTotalAmmo into if statement to prevent null ref:
if (ammoManager != null)
{
ammoManager.updateTotalAmmo = new vAmmoManager.OnUpdateTotalAmmo(UpdateTotalAmmo);
}
right under this line. (124) We need to get ref to the ammomanager by sickscore.
if (ammoManager == null)
{
inventoryManager = this.GetComponent<vAmmoManager_InventoryPro>();
}
Now we have the reload function on line 305.
Here we can use the bool variable we created earlier. so:
if (!useInventoryAmmo)
{
the original content of this function must be inside this curly bracket! So close the bracket on line 357 right under UpdateTotalAmmo();
}
And then we add to this function our own code. Here we make sure our current ammo in clip is less that clipSize. Then we trigger the animation for reload and call the reload function manually.
So paste this in line 358.
if (useInventoryAmmo)
{
if (rWeapon != null)
{
if (rWeapon.ammoCount < rWeapon.clipSize)
{
if (animator && !ignoreAnim)
{
animator.SetInteger("ReloadID", GetReloadID());
animator.SetTrigger("Reload");
}
inventoryManager.ReloadWeapon(rWeapon);
}
}
}
Now this shooter integration should work ok. Like i said this is not 100% fix as it is currently hard coded for the right weapon only.
But i hope this helps and gives inspiration for someone to make a 100% fix.
Pls note that im amateur at coding. This fix might not be the best way of doing this. Please backup your project before attempting this.
Please also note that if we are to manually call the reload weapon function in the vAmmoManager_InventoryPro. We have to modify the code of invector itself (vShooterManager). We are not actually removing any code from the ShooterManager. We just add some code to work with the vAmmoManager_InventoryPro.
My fix is made very quickly. There might be bugs and it is currently hard coded to work on right weapon only!
Note that codes are collapsed into regions. Open them all to avoid confusions.
So vAmmoManager_InventoryPro script. Please use vMonoBehaviour.
Open vShooterManager.cs
We need to use namespace for the integration files.
using.Devdog.InventoryPro.Integration.Invector;
Open the variables region. And in line 90. (Under [vEditorToolbar("Weapons")]) We need a reference for the new ammomanager.
[HideInInspector]
public vAmmoManager_InventoryPro inventoryManager;
Also if we are not to remove anything from invector code. We need a bool variable to determine if we want to use our method for reload or invectors.
add into line 93: public bool useInventoryAmmo = true;
You can now edit this bool value in the inspector under vShooterManager/weapons.
Under Start function we would get a null reference if we dont have normal vAmmoManager with our player
so on line 120 we need to close the updateTotalAmmo into if statement to prevent null ref:
if (ammoManager != null)
{
ammoManager.updateTotalAmmo = new vAmmoManager.OnUpdateTotalAmmo(UpdateTotalAmmo);
}
right under this line. (124) We need to get ref to the ammomanager by sickscore.
if (ammoManager == null)
{
inventoryManager = this.GetComponent<vAmmoManager_InventoryPro>();
}
Now we have the reload function on line 305.
Here we can use the bool variable we created earlier. so:
if (!useInventoryAmmo)
{
the original content of this function must be inside this curly bracket! So close the bracket on line 357 right under UpdateTotalAmmo();
}
And then we add to this function our own code. Here we make sure our current ammo in clip is less that clipSize. Then we trigger the animation for reload and call the reload function manually.
So paste this in line 358.
if (useInventoryAmmo)
{
if (rWeapon != null)
{
if (rWeapon.ammoCount < rWeapon.clipSize)
{
if (animator && !ignoreAnim)
{
animator.SetInteger("ReloadID", GetReloadID());
animator.SetTrigger("Reload");
}
inventoryManager.ReloadWeapon(rWeapon);
}
}
}
Now this shooter integration should work ok. Like i said this is not 100% fix as it is currently hard coded for the right weapon only.
But i hope this helps and gives inspiration for someone to make a 100% fix.