SC2Mapster Forums

Development > Galaxy Scripting

Script for ammo management misfiring

  • 2 posts
    #1 Dec 02, 2012 at 11:54 UTC - 0 likes

    Hi,

    I am helping out Ability (creator of NOTD) with fixing a persistent issue that has been plaguing the map since the 1.5.0 patch. It seems that some changes in 1.5.0 have broken our inventory handling script and cause it to give out free ammo to players.

    I've had a look at broth Triggers and Data but those seemed to be fine.

    What happened pre-1.5.0: Player drops a magazine from their equipped section which reduces equipped section by 3 and creates a stack of 1 magazines in inventory. Magazines in inventory can stack up to 3 before it creates a new stack. If inventory is full, drops a stack of 1 magazine on the floor.

    What happened post-1.5.0: When player drops a magazine while all inventory slots are occupied but there is a stack of 1 magazines present (i.e. stackable) the game stacks it to 3 instead of 2 and drops a NEGATIVE magazine stack on the floor. If that stack is not picked up, the player just received a free magazine. Also, if the player has a full inventory of stacks of 2 magazines, dropping a magazine fills randomly 3 of the stacks to 3 without dropping a magazine on the floor (i.e. 3 free magazines), which can be repeated and abused.

    On observation, if you have only 3 stacks or no magazines in inventory, dropping a magazine gives you 1. If you have a stack of 1, dropping a magazine seems to increment the existing stack by 1 as well as add a -1 magazine stack to your inventory for a split second. If you have a stack of 2, dropping a magazine seems to increment the existing stack to 3 as well as add a 0 magazine stack to your inventory for a split second.

    Note that what may be related to this is that pre-1.5.0 if your inventory was full but stackable, items would drop on the floor regardless and you had to make a space in your inventory first to stack things. 1.5.0 somehow made it ignore the inventory full limitation and just allow you to stack items with a full inventory when you click to pick something up. So that may be causative.

    Another thing that has been bothersome is that if you stack items with a full but stackable inventory (i.e. some stacks in inventory are not filled) it will fill them with the picked up item but not update the stack count until you change something with the inventory (use/drop something)

    Thank you for any help/pointers you can offer.

    Inventory backbone:

    include "TriggerLibs/NativeLib"
    
    //--------------------------------------------------------------------------------------------------
    // Library: Item Utility Library
    //--------------------------------------------------------------------------------------------------
    // Function Declarations
    order lib2_gf_OrderUseItemTargetingPoint (abilcmd lp_cmd, unit lp_item, point lp_tgt);
    order lib2_gf_OrderUseItemTargetingRelativePoint (abilcmd lp_cmd, unit lp_item, point lp_tgt);
    order lib2_gf_OrderUseItemTargetingUnit (abilcmd lp_cmd, unit lp_item, unit lp_tgt);
    order lib2_gf_OrderTakeItem (abilcmd lp_cmd, unit lp_item);
    order lib2_gf_OrderUseItem (abilcmd lp_cmd, unit lp_item);
    unitgroup lib2_gf_UnitsInGroupOfType (unitgroup lp_group, string lp_type);
    string lib2_gf_ItemTypeChargeLink (string lp_itemId);
    string lib2_gf_ItemTypeChargeLinkName (string lp_itemId);
    void lib2_gf_ItemSetChargesRemaining (unit lp_tgt, fixed lp_charges);
    fixed lib2_gf_ItemTypeMaxCharges (string lp_itemId);
    fixed lib2_gf_ItemTypeStartCharges (string lp_itemId);
    int lib2_gf_InventoryCountItemsOfType (unit lp_tgt, string lp_type);
    unitgroup lib2_gf_InventoryGetItemsOfType (unit lp_tgt, string lp_type);
    bool lib2_gf_InventoryHasItemOfType (unit lp_tgt, string lp_type);
    unit lib2_gf_InventoryGetRandomItemOfType (unit lp_tgt, string lp_type);
    fixed lib2_gf_ItemGetChargesUsed (unit lp_tgt);
    fixed lib2_gf_ItemGetChargesRemaining (unit lp_tgt);
    fixed lib2_gf_InventoryTotalChargesOfItemType (unit lp_tgt, string lp_type);
    bool lib2_gf_InventoryPreStackItemCountCheck (string lp_type);
    bool lib2_gf_InventoryPreStackItemForbiddenItems (string lp_type);
    int lib2_gf_InventoryMaxItemCount (unit lp_tgt);
    void lib2_gf_InventoryStackItems (unit lp_tgt, string lp_type, bool lp_useStartCount);
    void lib2_gf_InventoryStackItemsofType (unit lp_tgt, string lp_type);
    void lib2_gf_InventoryStackItemsofDifferentType (unit lp_tgt, string lp_type1, string lp_type2);
    
    // Custom Script
    //--------------------------------------------------------------------------------------------------
    // Custom Script: Custom Script
    //--------------------------------------------------------------------------------------------------
    unitgroup UnitsInGroupOfType(unitgroup group, string type)
    {
        unitgroup matchingUnits = UnitGroupEmpty();
        int numUnits = UnitGroupCount(group, c_unitCountAll);
        unit curUnit;
        int i = 1;
        while(i <= numUnits)
        {
            curUnit = UnitGroupUnit(group, i);
            if(UnitGetType(curUnit) == type)
            {
                UnitGroupAdd(matchingUnits, curUnit);
            }
            i += 1;
        }
        return matchingUnits;
    }
    unitgroup InventoryGetItemsOfType(unit tgt, string type)
    {
        return UnitsInGroupOfType(UnitInventoryGroup(tgt), type);
    }
    int InventoryItemCountOfType(unit tgt, string type)
    {
        return UnitGroupCount(InventoryGetItemsOfType(tgt, type), c_unitCountAll);
    }
    bool InventoryHasItemOfType(unit tgt, string type)
    {
        return InventoryItemCountOfType(tgt, type) > 0;
    }
    unit InventoryGetRandomItemOfType(unit tgt, string type)
    {
        unitgroup items = InventoryGetItemsOfType(tgt, type);
        if(UnitGroupCount(items, c_unitCountAll) <= 0)
        {
            return null;
        }
        return UnitGroupUnit(items, 0);
    }
    string ItemTypeChargeLink(string itemId)
    {
        string itemLinkId = CatalogFieldValueGet(c_gameCatalogUnit, itemId, "Item", -1);
        return CatalogFieldValueGet(c_gameCatalogItem, itemLinkId, "EffectCost.Charge.Link", -1);
    }
    fixed ItemTypeMaxCharges(string itemId)
    {
        return StringToFixed(CatalogFieldValueGet(c_gameCatalogItem, itemId, "EffectCost.Charge.CountMax", -1));
    }
    fixed ItemGetChargesUsed(unit tgt)
    {
        string chargeLinkName = ItemTypeChargeLink(UnitGetType(tgt));
        return UnitGetChargeUsed(tgt, chargeLinkName);
    }
    fixed ItemGetChargesRemaining(unit tgt)
    {
        string itemId = UnitGetType(tgt);
        string chargeLinkName = ItemTypeChargeLink(itemId);
        return ItemTypeMaxCharges(itemId) - UnitGetChargeUsed(tgt, chargeLinkName);
    }
    void ItemSetChargesRemaining(unit tgt, fixed charges)
    {
        string chargeLinkName = ItemTypeChargeLink(UnitGetType(tgt));
        fixed curCharges = ItemGetChargesRemaining(tgt);
        UnitAddChargeUsed(tgt, chargeLinkName, (curCharges - charges));
    }
    fixed InventoryTotalChargesOfItemType(unit tgt, string type)
    {
        unitgroup items = InventoryGetItemsOfType(tgt, type);
        fixed chargeCount = 0;
        int numItems = UnitGroupCount(items, c_unitCountAll);
        int i = 1;
        while(i <= numItems)
        {
            chargeCount += ItemGetChargesRemaining(UnitGroupUnit(items, i));
            i += 1;
        }
        return chargeCount;
    }
    void InventoryStackItemsOfType(unit tgt, string type)
    {
        fixed chargeCount = InventoryTotalChargesOfItemType(tgt, type);
        fixed maxCharges = ItemTypeMaxCharges(type);
        unitgroup items = InventoryGetItemsOfType(tgt, type);
        int i = UnitGroupCount(items, c_unitCountAll);
        unit curUnit;
        while(i > 0)
        {
            curUnit = UnitGroupUnit(items, i);
            if(chargeCount > maxCharges)
            {
                ItemSetChargesRemaining(curUnit, maxCharges);
                chargeCount -= maxCharges;
            }
            else if(chargeCount > 0)
            {
                ItemSetChargesRemaining(curUnit, chargeCount);
                chargeCount = 0;
            }
            else
            {
                UnitRemove(curUnit);
            }
            i -= 1;
        }
    }
    order OrderUseItemTargetingPoint(abilcmd cmd, unit item, point tgt)
    {
        order ord = OrderTargetingPoint(cmd, tgt);
        OrderSetTargetItem(ord, item);
        return ord;
    }
    order OrderUseItemTargetingRelativePoint(abilcmd cmd, unit item, point tgt)
    {
        order ord = OrderTargetingRelativePoint(cmd, tgt);
        OrderSetTargetItem(ord, item);
        return ord;
    }
    order OrderUseItemTargetingUnit(abilcmd cmd, unit item, unit tgt)
    {
        order ord = OrderTargetingUnit(cmd, tgt);
        OrderSetTargetItem(ord, item);
        return ord;
    }
    order OrderUseItem(abilcmd cmd, unit item)
    {
        return OrderTargetingItem(cmd, item);
    }
    
    void lib2_InitCustomScript () {
    }
    
    // Functions
    order lib2_gf_OrderUseItemTargetingPoint (abilcmd lp_cmd, unit lp_item, point lp_tgt) {
        // Variable Declarations
        order lv_ord;
    
        // Variable Initialization
        lv_ord = OrderTargetingPoint(lp_cmd, lp_tgt);
    
        // Implementation
        OrderSetTargetItem(lv_ord, lp_item);
        return lv_ord;
    }
    
    order lib2_gf_OrderUseItemTargetingRelativePoint (abilcmd lp_cmd, unit lp_item, point lp_tgt) {
        // Variable Declarations
        order lv_ord;
    
        // Variable Initialization
        lv_ord = OrderTargetingRelativePoint(lp_cmd, lp_tgt);
    
        // Implementation
        OrderSetTargetItem(lv_ord, lp_item);
        return lv_ord;
    }
    
    order lib2_gf_OrderUseItemTargetingUnit (abilcmd lp_cmd, unit lp_item, unit lp_tgt) {
        // Variable Declarations
        order lv_ord;
    
        // Variable Initialization
        lv_ord = OrderTargetingUnit(lp_cmd, lp_tgt);
    
        // Implementation
        OrderSetTargetItem(lv_ord, lp_item);
        return lv_ord;
    }
    
    order lib2_gf_OrderTakeItem (abilcmd lp_cmd, unit lp_item) {
        // Variable Declarations
        order lv_ord;
    
        // Variable Initialization
        lv_ord = OrderTargetingUnit(lp_cmd, lp_item);
    
        // Implementation
        OrderSetTargetItem(lv_ord, lp_item);
        return lv_ord;
    }
    
    order lib2_gf_OrderUseItem (abilcmd lp_cmd, unit lp_item) {
        // Implementation
        return OrderTargetingItem(lp_cmd, lp_item);
    }
    
    unitgroup lib2_gf_UnitsInGroupOfType (unitgroup lp_group, string lp_type) {
        // Variable Declarations
        int lv_numUnits;
        unitgroup lv_matchingUnits;
        unit lv_curUnit;
        int lv_i;
    
        // Variable Initialization
        lv_numUnits = UnitGroupCount(lp_group, c_unitCountAll);
        lv_matchingUnits = UnitGroupEmpty();
        lv_curUnit = null;
        lv_i = 1;
    
        // Implementation
        while ((lv_i <= lv_numUnits)) {
            lv_curUnit = UnitGroupUnit(lp_group, lv_i);
            if ((UnitGetType(lv_curUnit) == lp_type)) {
                UnitGroupAdd(lv_matchingUnits, lv_curUnit);
            }
            else {
            }
            lv_i += 1;
        }
        return lv_matchingUnits;
    }
    
    string lib2_gf_ItemTypeChargeLink (string lp_itemId) {
        // Variable Declarations
        string lv_itemLinkId;
    
        // Variable Initialization
        lv_itemLinkId = CatalogFieldValueGet(c_gameCatalogUnit, lp_itemId, "Item", c_playerAny);
    
        // Implementation
        return CatalogFieldValueGet(c_gameCatalogItem, lv_itemLinkId, "EffectCost.Charge.Link", c_playerAny);
    }
    
    string lib2_gf_ItemTypeChargeLinkName (string lp_itemId) {
        // Variable Declarations
        string lv_itemLinkId;
    
        // Variable Initialization
        lv_itemLinkId = CatalogFieldValueGet(c_gameCatalogUnit, lp_itemId, "Item", c_playerAny);
    
        // Implementation
        return CatalogFieldValueGet(c_gameCatalogItem, lv_itemLinkId, "PowerupCost.Charge.Link", c_playerAny);
    }
    
    void lib2_gf_ItemSetChargesRemaining (unit lp_tgt, fixed lp_charges) {
        // Variable Declarations
        string lv_chargeLinkName;
        fixed lv_curCharges;
    
        // Variable Initialization
        lv_chargeLinkName = lib2_gf_ItemTypeChargeLink((UnitGetType(lp_tgt)));
        lv_curCharges = lib2_gf_ItemGetChargesRemaining(lp_tgt);
    
        // Implementation
        UnitAddChargeUsed(lp_tgt, lv_chargeLinkName, (lv_curCharges - lp_charges));
    }
    
    fixed lib2_gf_ItemTypeMaxCharges (string lp_itemId) {
        // Variable Declarations
        int lv_untitledVariable001;
    
        // Variable Initialization
        lv_untitledVariable001 = 0;
    
        // Implementation
        return StringToFixed(CatalogFieldValueGet(c_gameCatalogItem, lp_itemId, "EffectCost.Charge.CountMax", c_playerAny));
    }
    
    fixed lib2_gf_ItemTypeStartCharges (string lp_itemId) {
        // Variable Declarations
        int lv_untitledVariable001;
    
        // Variable Initialization
        lv_untitledVariable001 = 0;
    
        // Implementation
        return StringToFixed(CatalogFieldValueGet(c_gameCatalogItem, lp_itemId, "EffectCost.Charge.CountStart", c_playerAny));
    }
    
    int lib2_gf_InventoryCountItemsOfType (unit lp_tgt, string lp_type) {
        // Implementation
        return UnitGroupCount(lib2_gf_InventoryGetItemsOfType(lp_tgt, lp_type), c_unitCountAll);
    }
    
    unitgroup lib2_gf_InventoryGetItemsOfType (unit lp_tgt, string lp_type) {
        // Implementation
        return lib2_gf_UnitsInGroupOfType(UnitInventoryGroup(lp_tgt), lp_type);
    }
    
    bool lib2_gf_InventoryHasItemOfType (unit lp_tgt, string lp_type) {
        // Implementation
        return (lib2_gf_InventoryCountItemsOfType(lp_tgt, lp_type) > 0);
    }
    
    unit lib2_gf_InventoryGetRandomItemOfType (unit lp_tgt, string lp_type) {
        // Variable Declarations
        unitgroup lv_items;
    
        // Variable Initialization
        lv_items = lib2_gf_InventoryGetItemsOfType(lp_tgt, lp_type);
    
        // Implementation
        if ((UnitGroupCount(lv_items, c_unitCountAll) <= 0)) {
            return null;
        }
        else {
        }
        return UnitGroupRandomUnit(lv_items, c_unitCountAll);
    }
    
    fixed lib2_gf_ItemGetChargesUsed (unit lp_tgt) {
        // Variable Declarations
        string lv_chargeLinkName;
    
        // Variable Initialization
        lv_chargeLinkName = lib2_gf_ItemTypeChargeLink((UnitGetType(lp_tgt)));
    
        // Implementation
        return UnitGetChargeUsed(lp_tgt, lv_chargeLinkName);
    }
    
    fixed lib2_gf_ItemGetChargesRemaining (unit lp_tgt) {
        // Variable Declarations
        string lv_itemId;
        string lv_chargeLinkName;
    
        // Variable Initialization
        lv_itemId = (UnitGetType(lp_tgt));
        lv_chargeLinkName = lib2_gf_ItemTypeChargeLink((UnitGetType(lp_tgt)));
    
        // Implementation
        return (lib2_gf_ItemTypeMaxCharges(lv_itemId) - UnitGetChargeUsed(lp_tgt, lv_chargeLinkName));
    }
    
    fixed lib2_gf_InventoryTotalChargesOfItemType (unit lp_tgt, string lp_type) {
        // Variable Declarations
        unitgroup lv_items;
        fixed lv_chargeCount;
        int lv_numItems;
        int lv_i;
    
        // Variable Initialization
        lv_items = lib2_gf_InventoryGetItemsOfType(lp_tgt, lp_type);
        lv_chargeCount = 0.0;
        lv_numItems = UnitGroupCount(lv_items, c_unitCountAll);
        lv_i = 1;
    
        // Implementation
        while ((lv_i <= lv_numItems)) {
            lv_chargeCount += lib2_gf_ItemGetChargesRemaining(UnitGroupUnit(lv_items, lv_i));
            lv_i += 1;
        }
        return lv_chargeCount;
    }
    
    bool lib2_gf_InventoryPreStackItemCountCheck (string lp_type) {
        // Implementation
        if (((lp_type == "Magazine"))) {
            return true;
        }
        else {
            return false;
        }
    }
    
    bool lib2_gf_InventoryPreStackItemForbiddenItems (string lp_type) {
        // Implementation
        if (((lp_type == "AmmoBox"))) {
            return false;
        }
        else {
            return true;
        }
    }
    
    int lib2_gf_InventoryMaxItemCount (unit lp_tgt) {
        // Implementation
        return UnitGroupCount(UnitInventoryGroup(lp_tgt), c_unitCountAll);
    }
    
    void lib2_gf_InventoryStackItems (unit lp_tgt, string lp_type, bool lp_useStartCount) {
        // Variable Declarations
        fixed lv_chargeCount;
        string lv_typeString;
        fixed lv_maxCharge;
        fixed lv_maxCharges;
        unitgroup lv_items;
        int lv_i;
        unit lv_curUnit;
    
        // Variable Initialization
        lv_chargeCount = lib2_gf_InventoryTotalChargesOfItemType(lp_tgt, lp_type);
        lv_typeString = (lp_type);
        lv_maxCharge = lib2_gf_ItemTypeStartCharges(lv_typeString);
        lv_maxCharges = lib2_gf_ItemTypeMaxCharges(lv_typeString);
        lv_items = lib2_gf_InventoryGetItemsOfType(lp_tgt, lp_type);
        lv_i = UnitGroupCount(lv_items, c_unitCountAll);
        lv_curUnit = null;
    
        // Implementation
        if ((lp_useStartCount == false)) {
            lv_maxCharge = lv_maxCharges;
        }
        else {
        }
        while ((lv_i > 0)) {
            lv_curUnit = UnitGroupUnit(lv_items, lv_i);
            if ((lv_chargeCount > lv_maxCharge)) {
                lv_chargeCount -= FixedToInt(lv_maxCharge);
                lib2_gf_ItemSetChargesRemaining(lv_curUnit, lv_maxCharge);
            }
            else if ((lv_chargeCount > 0.0)) {
                lib2_gf_ItemSetChargesRemaining(lv_curUnit, lv_chargeCount);
                lv_chargeCount = 0.0;
            }
            else if ((StringExternal("Param/Value/lib_2_3481135D") != null)) {
                UnitRemove(lv_curUnit);
            }
            lv_i -= 1;
        }
    }
    
    void lib2_gf_InventoryStackItemsofType (unit lp_tgt, string lp_type) {
        // Variable Declarations
        bool lv_useStartCount;
    
        // Variable Initialization
        lv_useStartCount = false;
    
        // Implementation
        lv_useStartCount = lib2_gf_InventoryPreStackItemCountCheck(lp_type);
        if ((lib2_gf_InventoryPreStackItemForbiddenItems(lp_type) == true)) {
            lib2_gf_InventoryStackItems(lp_tgt, lp_type, lv_useStartCount);
        }
        else {
        }
    }
    
    void lib2_gf_InventoryStackItemsofDifferentType (unit lp_tgt, string lp_type1, string lp_type2) {
        // Variable Declarations
        fixed lv_chargeCount;
        fixed lv_maxCharge1;
        fixed lv_maxCharge2;
        string lv_typeString1;
        string lv_typeString2;
        unitgroup lv_items1;
        unitgroup lv_items2;
        int lv_i;
        int lv_j;
        unit lv_curUnit;
    
        // Variable Initialization
        lv_chargeCount = 0.0;
        lv_maxCharge1 = 0.0;
        lv_maxCharge2 = 0.0;
        lv_typeString1 = (lp_type1);
        lv_typeString2 = (lp_type2);
        lv_items1 = lib2_gf_InventoryGetItemsOfType(lp_tgt, lp_type1);
        lv_items2 = lib2_gf_InventoryGetItemsOfType(lp_tgt, lp_type2);
        lv_i = UnitGroupCount(lv_items1, c_unitCountAll);
        lv_j = UnitGroupCount(lv_items2, c_unitCountAll);
        lv_curUnit = null;
    
        // Implementation
        lv_chargeCount = lib2_gf_InventoryTotalChargesOfItemType(lp_tgt, lp_type1);
        lv_chargeCount += lib2_gf_InventoryTotalChargesOfItemType(lp_tgt, lp_type2);
        if ((lib2_gf_InventoryPreStackItemCountCheck(lp_type1) == true)) {
            lv_maxCharge1 = lib2_gf_ItemTypeStartCharges(lv_typeString1);
        }
        else {
            lv_maxCharge1 = lib2_gf_ItemTypeMaxCharges(lv_typeString1);
        }
        if ((lib2_gf_InventoryPreStackItemCountCheck(lp_type2) == true)) {
            lv_maxCharge2 = lib2_gf_ItemTypeStartCharges(lv_typeString2);
        }
        else {
            lv_maxCharge2 = lib2_gf_ItemTypeMaxCharges(lv_typeString2);
        }
        while ((lv_i > 0)) {
            lv_curUnit = UnitGroupUnit(lv_items1, lv_i);
            if ((lv_chargeCount > lv_maxCharge1)) {
                lv_chargeCount -= FixedToInt(lv_maxCharge1);
                lib2_gf_ItemSetChargesRemaining(lv_curUnit, lv_maxCharge1);
            }
            else if ((lv_chargeCount >= 0.0)) {
                lib2_gf_ItemSetChargesRemaining(lv_curUnit, lv_chargeCount);
                lv_chargeCount = 0.0;
            }
            lv_i -= 1;
        }
        while ((lv_j > 0)) {
            lv_curUnit = UnitGroupUnit(lv_items2, lv_j);
            if ((lv_chargeCount > lv_maxCharge2)) {
                lv_chargeCount -= FixedToInt(lv_maxCharge2);
                lib2_gf_ItemSetChargesRemaining(lv_curUnit, lv_maxCharge2);
            }
            else if ((lv_chargeCount > 0.0)) {
                lib2_gf_ItemSetChargesRemaining(lv_curUnit, lv_chargeCount);
                lv_chargeCount = 0.0;
            }
            else if ((StringExternal("Param/Value/lib_2_2E248428") != null)) {
                UnitRemove(lv_curUnit);
            }
            lv_j -= 1;
        }
    }
    

    Code for dropping a magazine

    //--------------------------------------------------------------------------------------------------
    // Trigger: Drop Magazine
    //--------------------------------------------------------------------------------------------------
    bool gt_DropMagazine_Func (bool testConds, bool runActions) {
        // Variable Declarations
        unit lv_triggUnit;
        int lv_localIntA;
        unit lv_dummyCarrier;
        unit lv_magazine;
    
        // Variable Initialization
        lv_triggUnit = EventUnit();
        lv_localIntA = UnitGetOwner(EventUnit());
        lv_dummyCarrier = null;
        lv_magazine = null;
    
        // Conditions
        if (testConds) {
            if (!((gv_marineMags[lv_localIntA] >= 3))) {
                return false;
            }
        }
    
        // Actions
        if (!runActions) {
            return true;
        }
    
        UnitInventoryCreate(lv_triggUnit, "Magazine");
        lv_magazine = UnitInventoryLastCreated();
        libNtve_gf_UnitSetVariation(lv_magazine, "Crate", 1, "");
        if ((UnitIsValid(lv_magazine) == true)) {
            UnitAddChargeUsed(lv_magazine, "Ammo/Magazine", 2.0);
        }
        else {
            libNtve_gf_CreateUnitsWithDefaultFacing(1, "Rifleman", 0, 0, UnitGetPosition(lv_triggUnit));
            lv_dummyCarrier = UnitLastCreated();
            libNtve_gf_ShowHideUnit(lv_dummyCarrier, false);
            UnitInventoryCreate(lv_dummyCarrier, "Magazine");
            lv_magazine = UnitInventoryLastCreated();
            UnitSetOwner(lv_magazine, 0, true);
            Wait(0.1, c_timeGame);
            libNtve_gf_UnitSetVariation(lv_magazine, "Crate", 1, "");
            UnitAddChargeUsed(lv_magazine, "Ammo/Magazine", 2.0);
            Wait(0.1, c_timeGame);
            UnitKill(lv_dummyCarrier);
        }
        gv_marineMags[lv_localIntA] -= 3;
        libNtve_gf_SetDialogItemText(gv_ammoCounterDialogItem[lv_localIntA][1], IntToText(gv_marineRounds[lv_localIntA]), PlayerGroupActive());
        libNtve_gf_SetDialogItemText(gv_ammoCounterDialogItem[lv_localIntA][2], IntToText(gv_marineMags[lv_localIntA]), PlayerGroupActive());
        gf_UpdateInventoryDialog(lv_localIntA);
        gf_EquipmentUpdateMarineWeight(lv_localIntA);
        return true;
    }
    
    //--------------------------------------------------------------------------------------------------
    void gt_DropMagazine_Init () {
        gt_DropMagazine = TriggerCreate("gt_DropMagazine_Func");
        TriggerAddEventUnitAbility(gt_DropMagazine, null, AbilityCommand("DropMagazine", 0), c_unitAbilStageComplete, false);
    }
    

    Code for stacking items

    //--------------------------------------------------------------------------------------------------
    // Trigger: Pick and Stack Items
    //--------------------------------------------------------------------------------------------------
    bool gt_PickandStackItems_Func (bool testConds, bool runActions) {
        // Variable Declarations
        unit lv_inventoryItem;
        unit lv_inventoryHero;
        int lv_heroOwner;
        string lv_itemClass;
    
        // Variable Initialization
        lv_inventoryItem = EventUnitInventoryItem();
        lv_inventoryHero = EventUnit();
        lv_heroOwner = UnitGetOwner(lv_inventoryHero);
        lv_itemClass = CatalogFieldValueGet(c_gameCatalogItem, (UnitGetType(lv_inventoryItem)), "Class", c_playerAny);
    
        // Conditions
        if (testConds) {
            if (!((UnitGetType(lv_inventoryHero) != "ReaperMK13"))) {
                return false;
            }
    
            if (!((UnitGetType(lv_inventoryHero) != "DummyItemCarrier"))) {
                return false;
            }
    
            if (!((UnitIsAlive(EventUnit()) == true))) {
                return false;
            }
        }
    
        // Actions
        if (!runActions) {
            return true;
        }
    
        UnitBehaviorRemove(lv_inventoryItem, "LaserDesignatorLevel1", 1);
        UnitBehaviorRemove(lv_inventoryItem, "LaserDesignatorLevel2", 1);
        UnitBehaviorRemove(lv_inventoryItem, "LaserDesignatorLevel3", 1);
        UnitBehaviorRemove(lv_inventoryItem, "LaserDesignatorReveal", 1);
        if ((EventUnitInventoryItemContainer() == gv_equipmentContainer[lv_heroOwner])) {
            if ((lv_itemClass == "Weapons")) {
                UnitGroupAdd(gv_equipmentWeaponEquipped[lv_heroOwner], lv_inventoryItem);
                gf_DisableAttackEquippingWeapons(lv_heroOwner);
            }
            else if ((lv_itemClass == "Armor")) {
                UnitGroupAdd(gv_equipmentArmorEquipped[lv_heroOwner], lv_inventoryItem);
            }
            else if ((lv_itemClass == "Enhancements")) {
                UnitGroupAdd(gv_equipmentEnhancementsEquipped[lv_heroOwner], lv_inventoryItem);
            }
        }
        else {
        }
        if (((lv_itemClass == "Supplies") || (lv_itemClass == "Ammo"))) {
            lib2_gf_InventoryStackItemsofType(lv_inventoryHero, UnitGetType(lv_inventoryItem));
            Wait(0.1, c_timeGame);
        }
        else {
        }
        if (((lib2_gf_InventoryHasItemOfType(lv_inventoryHero, "AmmoBox") == true) && (lib2_gf_InventoryHasItemOfType(lv_inventoryHero, "Magazine") == true))) {
            lib2_gf_InventoryStackItemsofDifferentType(lv_inventoryHero, "AmmoBox", "Magazine");
        }
        else {
        }
        Wait(0.1, c_timeGame);
        gf_UpdateInventoryDialog(lv_heroOwner);
        gf_UpdateEquipmentMenu(lv_heroOwner);
        return true;
    }
    
    //--------------------------------------------------------------------------------------------------
    void gt_PickandStackItems_Init () {
        gt_PickandStackItems = TriggerCreate("gt_PickandStackItems_Func");
        TriggerAddEventUnitInventoryChange(gt_PickandStackItems, null, c_unitInventoryChangeGains, null);
        TriggerAddEventUnitInventoryChange(gt_PickandStackItems, null, c_unitInventoryChangeMoves, null);
    }
    
    Last edited Dec 02, 2012 by NOTDHelper
    #2 Dec 08, 2012 at 01:19 UTC - 0 likes

    Any ideas for help? Thanks

    NOTD (8 player cooperative survival) - http://www.notdstarcraft.com

  • 2 posts

You must login to post a comment. Don't have an account? Register to get one!