Beispiel #1
0
        public int WeaponImageStashSpareAmmo(coItemData thisobj, coPlayer player)
        {
            // If the amount in our pocket plus what we are about to add from the clip
            // Is over a clip, add a clip to inventory and keep the remainder
            // on the player
            coItemData ammo = thisobj["ammo"];

            if (ShapeBaseShapeBaseGetInventory(player, ammo) < thisobj["ammo.maxInventory"].AsInt())
            {
                string nameOfAmmoField = "remaining" + ammo.getName();


                int amountInPocket = player[nameOfAmmoField].AsInt();

                int amountIngun  = ShapeBaseShapeBaseGetInventory(player, thisobj["ammo"]);
                int combinedammo = amountInPocket + amountIngun;

                if (combinedammo >= thisobj["ammo.maxInventory"].AsInt())
                {
                    player[nameOfAmmoField] = (combinedammo - thisobj["ammo.maxInventory"].AsInt()).AsString();

                    ShapeBaseShapeBaseIncInventory(player, thisobj["clip"], 1);
                }
                else if (ShapeBaseShapeBaseGetInventory(player, thisobj["clip"]) > 0)
                {
                    player[nameOfAmmoField] = combinedammo.AsString();
                }

                return(player[nameOfAmmoField].AsInt());
            }

            return(0);
        }
Beispiel #2
0
        public int ShapeBaseShapeBaseMaxInventory(coShapeBase thisobj, coItemData data)
        {
            if (data.isField("clip"))
            {
                return(data["maxInventory"].AsInt());
            }

            return((( coSimDataBlock)thisobj.getDataBlock())["maxInv[" + data.getName() + "]"].AsInt());
        }
Beispiel #3
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);
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 public int ShapeBaseShapeBaseGetInventory(coShapeBase thisobj, coItemData data)
 {
     return(thisobj.isObject() ? thisobj["inv[" + data.getName() + "]"].AsInt() : 0);
 }
Beispiel #8
0
        public bool ShapeBaseShapeBaseHasInventory(coShapeBase thisobj, coItemData data)
        {
            int amount = thisobj["inv[" + data.getName() + "]"].AsInt();

            return(amount > 0);
        }