I have been trying to get a custom inventory script working in unrealscript. I need to check on weapon pickup if the weapon you are picking up has a weapon group that matches one you already have or not. If so it swaps the weapons of the given group. If not you gain the new weapon. Currently we have 4 weapon groups. What i have tried to no avail to find is how to find the weapon group of a weapon being picked up. and how to check that against the other weapons. I have been working with the add inventory function.
NewItem is the item you just interacted with. And i need to find the other weapons in your current inventory and their weapon groups.
simulated function bool AddInventory(Inventory NewItem, optional bool bDoNotActivate)
{
local Inventory Item, LastItem;
// The item should not have been destroyed if we get here.
if( (NewItem != None) && !NewItem.bDeleteMe )
{
// if we don't have an inventory list, start here
if( InventoryChain == None )
{
InventoryChain = newItem;
}
else
{
// Skip if already in the inventory.
for (Item = InventoryChain; Item != None; Item = Item.Inventory)
{
if( Item == NewItem )
{
return FALSE;
}
LastItem = Item;
}
LastItem.Inventory = NewItem;
}
//Edited by Matt Kerns
`LogInv("adding" @ NewItem @ "bDoNotActivate:" @ bDoNotActivate);
`Log ("Added to inventory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
NewItem.SetOwner( Instigator );
NewItem.Instigator = Instigator;
NewItem.InvManager = Self;
NewItem.GivenTo( Instigator, bDoNotActivate);
// Trigger inventory event
Instigator.TriggerEventClass(class'SeqEvent_GetInventory', NewItem);
return TRUE;
}
return FALSE;
}
If you want write all code in InventoryManager it will be look like
}
simulated function AddItemWeapon(Inventory NewItem, optional bool bDoNotActivate) {
}
This is best way if your game use network and replicate inventory. If not, you can simple write something like
But im sure that this is bad way. You should write class which will save all used weapon groups and use InventoryManager only as storage