Code to recreate familiar scripting logic

05/04/2011 15:15 mircato#1
As I have been working to create my own plugins, I figured I might as well simplify and standardize my own plugin creation. As my choice of doing so I decided to standardize as closely as possible to your scripting language for familiarity. As such I thought you may find these little snippets of code to be at your convenience of time.

Among the scripting logic I have as needed to created these thus far:

level, getitemamount, invsize, map

Here they are if you wish to incorporate them as standardized functions:

level()
Code:
PHP Code:
        public static int level()
        {

            return 
Client.Level;

        } 
getitemamount()

PHP Code:
public static int getitemamount(string ItemName)
        {

            try
            {

                
int ItemID;
                
                
bool isItemID Int32.TryParse(ItemNameout ItemID);

                
int count 0;

                foreach (
COFarmerItem i in Client.Inventory.Items)
                {

                    if (
isItemID == false && i.Attributes.Name.ToLower() == ItemName.ToLower()) count++;
                    if (
isItemID == true && i.Attributes.TypeID == ItemIDcount++;

                }

                return 
count;

            }

            catch (
Exception exception)
            {

                
Client.Chat("Error: " exception.MessageChatMode.SystemCOFarmerPacketSource.FromServer"ALL");

                return -
1;

            }

        } 
invsize()

PHP Code:
        public static int invsize()
        {

            return 
Client.Inventory.Items.Count();

        } 
map()
PHP Code:
        public static int map()
        {
            if (
Client.MapID == Client.DynamicMapID)
            {

                return 
Client.MapID;

            }

            else
            {

                return 
Client.DynamicMapID;

            }

        }