RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Safe Trash 4 Tokens to MasterLooter

espcevan

Sorceror
All I'm trying to do is get the tokens to the Master Looter instead of the Token Ledger
Having a little issue with this. I'm getting the same error for 2 lines.

Errors:
+ Custom Systems/Daat99/Tokens/Safe Trash 4 Tokens Backpack.cs:
CS0019: Line 234: Operator '+' cannot be applied to operands of type 'ulong' and 'int'
CS0019: Line 237: Operator '+' cannot be applied to operands of type 'ulong' and 'int'

Code:
        public static void EmptyTrash(Mobile from, Item item)
        {
            List<Item> items = item.Items;
            if ( items.Count > 0 )
            {
                int i_Reward = 0;
                from.PlaySound(0x76);
                for ( int i = items.Count - 1; i >= 0; --i )
                {
                    if ( i >= items.Count )
                        continue;
                    Item it = (Item)items[i] as Item;
                    if ( it.Stackable == false && !(item is BaseBook) )
                        i_Reward += Utility.RandomMinMax(2,5);
                    ((Item)items[i]).Delete();
                }
                if (i_Reward > 0)
                {
                    Item[] lootbag = from.Backpack.FindItemsByType( typeof( MasterLooterBackpack ) );
                    //Item[] ledgers = from.Backpack.FindItemsByType( typeof( TokenLedger ) );//Original
 
 
                    foreach( MasterLooterBackpack ml in lootbag )
                    //foreach( TokenLedger tl in ledgers )//Original
                    {
                        if ( ml.Owner == from.Serial )
                        //if ( tl.Owner == from.Serial )//Original
                        {
                            if ((ml.TokensAmount + i_Reward) <= 2000000000 )
                            //if ((tl.Tokens + i_Reward) <= 2000000000 )//Original
                            {
                                ml.TokensAmount = (ml.TokensAmount + i_Reward);
                                //tl.Tokens = (tl.Tokens + i_Reward);//Stock
                                from.SendMessage(1173, "You were rewarded {0} Tokens to your Master Looter for cleaning the shard.", i_Reward);
                                //from.SendMessage(1173, "You were rewarded {0} Tokens to your ledger for cleaning the shard.", i_Reward);//Original
                                break;
                            }
                            else
                                from.SendMessage(1173, "You have a full Mater Looter, please make a check and store it in your bank.");
                                //from.SendMessage(1173, "You have a full token ledger, please make a check and store it in your bank.");//Original
                        }
                    }
                }
            }
        }


Line 134
Code:
if ((ml.TokensAmount + i_Reward) <= 2000000000 )


Line 137
Code:
ml.TokensAmount = (ml.TokensAmount + i_Reward);



Any Suggestions?
 

Attachments

  • Safe Trash 4 Tokens Backpack.cs
    7.7 KB · Views: 0

Hammerhand

Knight
Not sue with the MasterLooter backpack, but in MasterStorage.cs lines 57 & 58 might be of some use to you in this..
Code:
            GoldLedger = true; //enables the gold ledger
            TokenLedger = true; //enables the token ledger  //line 58
Just set the TokenLedger to false to disable it. tokens may go into the players reg backpack, but they wont be going into the Ledger.
 

daat99

Moderator
Staff member
Hi,

i_Reward is an integer which means its range is -2^32 to 2^32 (+-1).
The ml.TokensAmount is a ulong which means its range is 0-2^64-1.
The i_Reward can be a negative number because we want the ability to subtract tokens but the TokensAmount can't be a negative number because we don't want the players to "go into debt".

C# doesn't allow you to compare an integer and a ulong types so you'll need to convert one to the other.
Your best bet is to convert the int to ulong while keeping in mind that the int value can be a negative value and needs to be treated differently in that case.

If you don't care about negative tokens than you should look at the master storage class and check the "TryStoreItemType" method.
This method will receive two parameters, the type of the item (Daat99Tokens or Gold) and the integer amount to add to the storage.
It then converts the amount to ulong before adding it to the storage.
Please note that this approach will have ill effects when it's called with a negative amount of tokens/gold.
 

espcevan

Sorceror
I'm using an older version of MasterLooter, and we are also using RunUO 2.2 Sorry i didn't Specify that earlier.

I'm not the one that put the server together, just fixing stuff they already have.


Here is what i have now. It just wont put the tokens in my MasterLooter

Code:
        public static void EmptyTrash(Mobile from, Item item)
        {
            List<Item> items = item.Items;
            if ( items.Count > 0 )
            {
                int i_Reward = 0;
                ulong ii_Reward = Convert.ToUInt64(i_Reward);//Added this line
                from.PlaySound(0x76);
                for ( int i = items.Count - 1; i >= 0; --i )
                {
                    if ( i >= items.Count )
                        continue;
                    Item it = (Item)items[i] as Item;
                    if ( it.Stackable == false && !(item is MasterLooterBackpack) )
                        i_Reward += Utility.RandomMinMax(2,5);
                    ((Item)items[i]).Delete();
                }
                if (i_Reward > 0)
                {
                    Item[] lootbag = from.Backpack.FindItemsByType( typeof( MasterLooterBackpack ) );
 
 
                    foreach( MasterLooterBackpack ml in lootbag )
                    {
                        if ( ml.Owner == from.Serial )
                        {
                            if ((ml.TokensAmount + ii_Reward) <= 2000000000 )
                            {
                                ml.TokensAmount = (ml.TokensAmount + ii_Reward);
                                from.SendMessage(1173, "{0} Tokens have been put in your Master Looter for cleaning the shard.", i_Reward);
                                break;
                            }
                            else
                                from.SendMessage(1173, "You have a full Mater Looter, please make a check and store it in your bank.");
                        }
                    }
                }
            }
        }

I added this...
Code:
ulong ii_Reward = Convert.ToUInt64(i_Reward);
Thinking it would convert the 'int' to a 'ulong'



Is this right or am i doing it WAY wrong?
 

Attachments

  • MasterLooter.rar
    12.4 KB · Views: 0

espcevan

Sorceror
OK it works in a way now.

In this section if i make every item worth 3 tokens it will give me the 3 tokens in the MasterLooter
Code:
                for ( int i = items.Count - 1; i >= 0; --i )
                {
                    if ( i >= items.Count )
                        continue;
                    Item it = (Item)items[i] as Item;
                    if ( it.Stackable == false && !(item is MasterLooterBackpack) )
                        ii_Reward += 3;//Gives 3 tokens per item
                    ((Item)items[i]).Delete();
                }

How can i give a ulong a random number?
 

daat99

Moderator
Staff member
Download the latest OWLTR and look at how I handled it in the master storage.
You have a code example there.
 

espcevan

Sorceror
So i managed to work around getting it to work the way i wanted it to.

This section of code in SafeTrash4TokensBackpack.cs Will give it the random 1-5 tokens to the MasterLooterBackpack

Code:
        public static void EmptyTrash(Mobile from, Item item)
        {
            List<Item> items = item.Items;
            if ( items.Count > 0 )
            {
                int i_Reward = Utility.RandomMinMax(1,4);
                ulong ii_Reward = Convert.ToUInt64(i_Reward);//This line converts i_Reward to a ulong to put the tokens in the MasterLooterBackpack.
                from.PlaySound(0x76);
                for ( int i = items.Count - 1; i >= 0; --i )
                {
                    if ( i >= items.Count )
                        continue;
                    Item it = (Item)items[i] as Item;
                    if ( it.Stackable == false && !(item is MasterLooterBackpack) )
                        ii_Reward += 1;
                    ((Item)items[i]).Delete();
                }
                if (ii_Reward > 0)
                {
                    Item[] lootbag = from.Backpack.FindItemsByType( typeof( MasterLooterBackpack ) );
 
 
                    foreach( MasterLooterBackpack ml in lootbag )
                    {
                        if ( ml.Owner == from.Serial )
                        {
                            if ((ml.TokensAmount + ii_Reward) <= 2000000000 )
                            {
                                ml.TokensAmount = (ml.TokensAmount + ii_Reward);
                                from.SendMessage(1173, "{0} Tokens have been put in your Master Looter for cleaning the shard.", ii_Reward);
                                break;
                            }
                            else
                                from.SendMessage(1173, "You have a full Mater Looter, please make a check and store it in your bank.");
                        }
                    }
                }
            }
        }

I may not have done what someone else would have, but it did what I wanted it to in the long run.

Thanks daat99 for the help.
 
Top