Hi, have a question. For example I have <Pistol v1> with inv.Group 1 and <Pistol v2> with same inv.Group, so if <Pistol v1> is already equiped and I equiping <Pistol v2>, it mean I have two different weapons on one inv. Group. So I wondering how to remove <Pistol v1> when equiping <Pistol v2>. Thanks in advance.
Announcement
Collapse
No announcement yet.
Two different weapons on one inventory group
Collapse
X
-
I find this code
function Touch( actor Other )
{
local inventory Inv;
local Pistol V1 W;
if( Other.IsA('Pawn') && (Other != none))
{
for(Inv=Other.Inventory; Inv!=None; Inv=Inv.Inventory)
if ( Inv.IsA('Pistol V1'))
{
W = Pistol V1(Inv);
W.Destroy();
}
}}
-
The class 'Actor' (which is the type of 'Other') doesn't have a variable named 'Inventory'.
Since you're already checking whether it's a Pawn, you can cast to Pawn and if that check succeeded then access that Pawn's InventoryManager ('InvManager'). From there you can iterate over all items in the inventory and remove those you don't want. By the way you don't have to reinvent the wheel, the InventoryManager already comes with helper functions for different things.
Comment
-
Originally posted by Sunderland View PostThanks for reply, really appreciate it. Talking about helpers functions in InventoryManager are they:
simulated event Inventory FindInventoryType
simulated function RemoveFromInventory(Inventory ItemToRemove)
Comment
-
I need to correct myself in my question: how to implement system when you pick up weapon that have the same inv. group with weapon that you already have and it remove old weapon from your inventory (maybe it should check GroupWeight parameter and remove weapon with lower parameter)?
Thanks in advance.
Comment
-
Ok, another try. I give a weapon to my pawn in kismet with node <Give Inventory>, basically I have a trigger which connected to node <Has Inventory> which check if I have <pistol v1> and if I have, then it goes to node <GiveInventory> and give me <Pistol v2>. So I try to modify node <GiveInventory> to delete <pistol v1> but i have troubles with correct code wrighting:
/**
class MyGame_SeqAct_GiveInventory extends SequenceAction;
var() array<class<Inventory> > InventoryList;
var() bool bClearExisting;
var() bool bForceReplace;
var Inventory Inventory; // Next Inventory in Linked List
var InventoryManager InvManager;
var Inventory InventoryChain;
simulated function RemoveClassFromInventory(class<MyGame_InventoryMan ager> DesiredClass, optional bool bAllowSubclass)
{
local Inventory Inv;
Inv = FindInventoryType(DesiredClass, bAllowSubclass);
while(Inv != none)
{
RemoveFromInventory(Inv);
Inv = FindInventoryType(DesiredClass, bAllowSubclass);
}
}
simulated function RemoveFromInventory(Inventory ItemToRemove)
{
local Inventory Item;
local bool bFound;
if( ItemToRemove != None )
{
if( InventoryChain == ItemToRemove )
{
bFound = TRUE;
InventoryChain = ItemToRemove.Inventory;
}
else
{
// If this item is in our inventory chain, unlink it.
for(Item = InventoryChain; Item != None; Item = Item.Inventory)
{
if( Item.Inventory == ItemToRemove )
{
bFound = TRUE;
Item.Inventory = ItemToRemove.Inventory;
break;
}
}
}
if( bFound )
{
ItemToRemove.ItemRemovedFromInvManager();
ItemToRemove.SetOwner(None);
ItemToRemove.Inventory = None;
}
// make sure we don't have other references to the item
if( ItemToRemove == Instigator.Weapon)
{
Instigator.Weapon= None;
}
if( Instigator.Health > 0 && Instigator.Weapon== None && Instigator.Controller != None )
{
Instigator.Controller.ClientSwitchToBestWeapon(TRU E);
}
}
}
simulated event Inventory FindInventoryType(class<MyGame_InventoryManager> DesiredClass, optional bool bAllowSubclass)
{
local Inventory Inv;
ForEach InventoryActors(DesiredClass, Inv)
{
if (bAllowSubclass || Inv.Class == DesiredClass)
{
return Inv;
}
}
return None;
}
defaultproperties
{
ObjName="Give Inventory"
ObjCategory="MyGame"
}
MyGame_SeqAct_GiveInventory.uc(82) : Error, 'ForEach': An iterator expression is required
MyGame_SeqAct_GiveInventory.uc(64) : Error, Bad or missing expression after '==': 'Instigator'
My programing skills are bad, so any help would be appreciated.
Comment
-
Well you don't just copy-paste "random" bits of code to your own class and expect it to work (unless it's a static function maybe).
Your best bet would be to learn and improve your programming skills. Most compiler errors may read weird and you might think "what's with this stupid !$%# error" but they will always point you at the line (including the ones above and below the number in the error message) where you've done something wrong. Learning how to fix these errors yourself is actually a very important step as well.
For Kismet, look at the existing classes and how they are implemented (those that are implemented in unreal script and aren't native). Then start with something simple, a node that prints "Hello World!" or whatever else to the log (you have to implement the function Activated() with your logic. Then move to your actual goal. To gain access to the InventoryManager functions you'll need a pawn which is fairly simple to obtain in Kismet especially if you've already got a touch event or something like that set up. You can pass this Pawn to your RemoveInventory node as a variable or alternatively search the Pawn in your Activated() implementation. Once you have that Pawn all you need to do is call your RemoveClassFromInventory function you have above (you'll need to solve the compiler errors).
Comment
Comment