1

我一直在尝试让自定义库存脚本在 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;
}
4

1 回答 1

0

如果你想在 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, optional 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 作为存储的类

于 2012-02-22T11:04:14.723 回答