我一直在尝试让一个自定义清单脚本在unrealscript中工作。我需要检查武器拾取情况,你正在拾取的武器是否有与你现有武器组匹配的武器组。如果是这样的话,它会交换特定团体的武器。否则你将获得新武器。目前我们有4个武器组。我试着找不到的是如何找到被拿起武器的武器组。以及如何与其他武器进行核对。我一直在使用添加库存功能。
NewItem是您刚刚与之交互的项目。我需要在你当前的库存中找到其他武器以及它们的武器组。
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;
}
如果您想在InventoryManager中编写所有代码,它将看起来像
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 weapon - work in personal weapon function
if(Weapon(NewItem) != none)
return AddItemWeapon(NewItem, bDoNotActivate);
// 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;
}
模拟函数AddItemWeapon(Inventory NewItem,可选bool bDoNotActivate){
local Inventory Item, LastItem;
local Weapon WeaponNewItem;
WeaponNewItem= Weapon(NewItem);
// 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
{
//look for our group
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
if(Weapon(Item) != none && Weapon(Item).Group == WeaponNewItem.Group){
RemoveFromInventory(Item);
break;
}
}
// 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;
}
这是最好的方式,若你们的游戏使用网络和复制库存。如果没有,你可以简单地写一些类似的东西
simulated function AddItemWeapon(Inventory NewItem, optional bool bDoNotActivate){
local Inventory Item, LastItem;
local Weapon WeaponNewItem;
local bool bAddNewWeapon;
bAddNewWeapon = true;
WeaponNewItem = Weapon(NewItem);
// 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
{
//look for our group
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
if(Weapon(Item) != none && Weapon(Item).Group == WeaponNewItem.Group){
NewItem.Inventory = Item.Inventory;
bAddNewWeapon = false;
RemoveFromInventory(Item);
break;
}
LastItem = Item;
}
if(bAddNewWeapon){
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
LastItem = Item;
}
}
LastItem.Inventory = NewItem;
}
但我确信这是一种糟糕的方式。您应该编写一个类,该类将保存所有使用过的武器组,并将InventoryManager仅用作存储