public int ShapeBaseShapeBaseGetInventory(coShapeBase thisobj, coItemData data)
     {
     return thisobj.isObject() ? thisobj["inv[" + data.getName() + "]"].AsInt() : 0;
     }
Example #2
0
        public void AmmoOnInventory(coItemData thisobj, coPlayer player, int amount)
            {
            coGameConnection client = player["client"];
            for (int i = 0; i < 8; i++)
                {
                coItemData image = player.getMountedImage(i);
                if (image <= 0)
                    continue;

                if (!image["ammo"].isObject())
                    continue;
                if (console.Call(image["ammo"], "getID") != console.Call(thisobj, "getID"))
                    continue;


                player.setImageAmmo(i, amount != 0);

                int currentammo = ShapeBaseShapeBaseGetInventory(player, thisobj);

                if (player.getClassName() != "Player")
                    continue;

                int amountInClips;

                if (thisobj["clip"].isObject())
                    {
                    amountInClips = ShapeBaseShapeBaseGetInventory(player, thisobj["clip"]);

                    amountInClips *= thisobj["maxInventory"].AsInt();

                    amountInClips += player["remaining" + thisobj.getName()].AsInt();
                    }
                else
                    {
                    amountInClips = currentammo;
                    currentammo = 1;
                    }
                if (player["client"] != "" && !player["isAiControlled"].AsBool())
                    {
                    GameConnectionSetAmmoAmountHud(client, currentammo, amountInClips);
                    }
                }
            }
        public int ShapeBaseShapeBaseDecInventory(coShapeBase shapebase, coItemData data, int amount = 0)
            {
            int total = shapebase["inv[" + data.getName() + "]"].AsInt();


            if (total > 0)
                {
                if (total < amount)
                    amount = total;

                ShapeBaseShapeBaseSetInventory(shapebase, data, (total - amount));
                return amount;
                }
            return 0;
            }
        public int ShapeBaseShapeBaseSetInventory(coShapeBase thisobj, coItemData data, int value = 0)
            {
            if (thisobj == "")
                return 0;
            int max = 0;


            max = ShapeBaseShapeBaseMaxInventory(thisobj, data);
            if (value > max)
                value = max;

            int amount = thisobj["inv[" + data.getName() + "]"].AsInt();


            if (amount != value)
                {
                thisobj["inv[" + data.getName() + "]"] = value.AsString();


                if (console.isMethodInNamespace(data, "onInventory"))
                    data.call("onInventory", thisobj, value.AsString());

                //string datablock = console.getDatablock(thisobj).AsString();

                if (console.isObject((( coSimDataBlock)thisobj.getDataBlock())) && console.isMethodInNamespace((( coSimDataBlock)thisobj.getDataBlock()), "onInventory"))
                    (( coSimDataBlock)thisobj.getDataBlock()).call("onInventory", data, value.AsString());
                }
            return value;
            }
        public int ShapeBaseShapeBaseIncInventory(coShapeBase player, coItemData datablock, int amount)
            {
            int maxamount = ShapeBaseShapeBaseMaxInventory(player, datablock);

            int total = player["inv[" + datablock.getName() + "]"].AsInt();

            if (total < maxamount)
                {
                if (total + amount > maxamount)
                    {
                    amount = (maxamount - total);
                    }
                ShapeBaseShapeBaseSetInventory(player, datablock, (total + amount));
                return amount;
                }
            return 0;
            }
        public int ShapeBaseShapeBaseMaxInventory(coShapeBase thisobj, coItemData data)
            {
            if (data.isField("clip"))
                return data["maxInventory"].AsInt();

            return (( coSimDataBlock)thisobj.getDataBlock())["maxInv[" + data.getName() + "]"].AsInt();
            }
 public bool ShapeBaseShapeBaseHasInventory(coShapeBase thisobj, coItemData data)
     {
     int amount = thisobj["inv[" + data.getName() + "]"].AsInt();
     return amount > 0;
     }