[Request] The save for the Inventory after converting into ini.

01/19/2009 04:01 justprownage#1
Does anyone know how to make the Inventory save all the items? Because when ever I disconnect or restart the server, the items in my inventory disappears.
This is what I have so far:
Code:
public static void SaveInventory(Character Charr)
        {
            Ini Cli = new Ini(System.Windows.Forms.Application.StartupPath + @"\characters\\" + Charr.Name + ".chr");
            Cli.WriteString("Character", "Inventory", Convert.ToString(Charr.PackedInventory));
        }
01/19/2009 04:18 tao4229#2
Okay, so people stfu about this...

Code:
[color=black]
[color=blue]public static void[/color] SaveInventory([color=mediumturquoise]Character[/color] Character)
{
    [color=mediumturquoise]Ini[/color] IniFile = [color=blue]new[/color] [color=mediumturquoise]Ini[/color]([color=darkred]@"\Database\Characters"[/color] + Character.Name + [color=darkred]".ini"[/color]);[color=green]//fix db path if you want..[/color]
    [color=blue]for[/color]([color=blue]byte[/color] i = 1; i < Character.Inventory.Length; i++)
    {
        IniFile.WriteString([color=darkred]"Character"[/color],[color=darkred]"Inventory["[/color] + i + [color=darkred]"]"[/color], Character.Inventory[i]);
    }
}

[color=blue]public static void[/color] LoadInventory([color=mediumturquoise]Character[/color] Char)
{
     [color=mediumturquoise]Ini[/color] IniFile = [color=blue]new[/color] [color=mediumturquoise]Ini[/color]([color=darkred]@"\Database\Characters"[/color] + Char.Name + [color=darkred]".ini"[/color]);[color=green]//fix db path if you want yet again.[/color]
     Char.Inventory = [color=blue]new[/color] [color=blue]string[/color][41];[color=green]//I think LOTF does it like this, fix it if not.[/color]
     [color=blue]for[/color]([color=blue]byte[/color] i = 1; i < Char.Inventory.Length; i++)
     {
           Char.Inventory[i] = Ini.ReadString([color=darkred]"Character"[/color],[color=darkred]"Inventory"[/color]);[color=green]//fix parameters, if you need to specify size etc..[/color]
     }
}
[/color]
01/19/2009 04:19 justprownage#3
Quote:
Originally Posted by tao4229 View Post
Okay, so people stfu about this...

Code:
[color=black]
[color=blue]public static void[/color] SaveInventory([color=cyan]Character[/color] Character)
{
    [color=cyan]Ini[/color] IniFile = [color=blue]new[/color] [color=cyan]Ini[/color]([color=darkred]@"\Database\Characters"[/color] + Character.Name + [color=darkred]".ini"[/color]);[color=green]//fix db path if you want..[/color]
    [color=blue]for[/color]([color=blue]byte[/color] i = 1; i < Character.Inventory.Length; i++)
    {
        IniFile.WriteString([color=darkred]"Character"[/color],[color=darkred]"Inventory["[/color] + i + [color=darkred]"]"[/color], Character.Inventory[i]);
    }
}

[color=blue]public static void[/color] LoadInventory([color=cyan]Character[/color] Char)
{
     [color=cyan]Ini[/color] IniFile = [color=blue]new[/color] [color=cyan]Ini[/color]([color=darkred]@"\Database\Characters"[/color] + Character.Name + [color=darkred]".ini"[/color]);[color=green]//fix db path if you want yet again.[/color]
     Char.Inventory = [color=blue]new[/color] [color=blue]string[/color][41];[color=green]//I think LOTF does it like this, fix it if not.[/color]
     [color=blue]for[/color]([color=blue]byte[/color] i = 1; i < Char.Inventory.Length; i++)
     {
           Char.Inventory[i] = Ini.ReadString([color=darkred]"Character"[/color],[color=darkred]"Inventory"[/color]);[color=green]//fix parameters, if you need to specify size etc..[/color]
     }
}
[/color]
I want to thanks you a million times xD

#edit
Tested it and it still doesn't save the inventory. Do I have to add something in the GetCharInfo?
01/19/2009 05:09 HellCo#4
Quote:
Originally Posted by justprownage View Post
Does anyone know how to make the Inventory save all the items? Because when ever I disconnect or restart the server, the items in my inventory disappears.
This is what I have so far:
Code:
public static void SaveInventory(Character Charr)
        {
            Ini Cli = new Ini(System.Windows.Forms.Application.StartupPath + @"\characters\\" + Charr.Name + ".chr");
            Cli.WriteString("Character", "Inventory", Convert.ToString(Charr.PackedInventory));
        }
Bro, just look in other sources that have it working, LOTF have it working, or just use Kinishi's source which xmasterrr released without permission.
01/19/2009 05:15 justprownage#5
Quote:
Originally Posted by HellCo View Post
Bro, just look in other sources that have it working, LOTF have it working, or just use Kinishi's source which xmasterrr released without permission.
Those sources arent converted to ini u n00b.
01/19/2009 05:20 HellCo#6
Quote:
Originally Posted by justprownage View Post
Those sources arent converted to ini u n00b.
How does this make me a noob please explain,

For one you didnt mension .ini files not once in this thread, you may have in other threads which i yet havent had time to look at yet.

For two, I only tried to help, if you're gonna call everyone a noob that tries to help, God help you, you'll receive no help.
01/19/2009 05:24 justprownage#7
Quote:
Originally Posted by HellCo View Post
How does this make me a noob please explain,

For one you didnt mension .ini files not once in this thread, you may have in other threads which i yet havent had time to look at yet.

For two, I only tried to help, if you're gonna call everyone a noob that tries to help, God help you, you'll receive no help.
You must be blind. The title says it all.

[Request] The save for the Inventory after converting into ini.
01/19/2009 05:26 HellCo#8
Quote:
Originally Posted by justprownage View Post
You must be blind. The title says it all.

[Request] The save for the Inventory after converting into ini.
Ok, sorry, i mis-read, I'll read carefully next time, but still, It gives you no rights to call anybody a noob, after trying to help you.
01/19/2009 05:28 justprownage#9
Quote:
Originally Posted by HellCo View Post
Ok, sorry, i mis-read, I'll read carefully next time, but still, It gives you no rights to call anybody a noob, after trying to help you.
n00b = my way of saying dunce
noob on the other hand, know little and have no will to learn any more.
01/19/2009 05:31 HellCo#10
Don't call someone a noob after they tried to help you, it'll get you nowhere.
01/19/2009 05:33 justprownage#11
Quote:
Originally Posted by HellCo View Post
Don't call someone a noob after they tried to help you, it'll get you nowhere.
Sure my friend.
01/19/2009 06:41 culo01#12
ReadString not defined .....any help please?will this fix warehouse too?
01/19/2009 06:44 kinshi88#13
LOTF "packs" the inventory to save it.

Pack:
Code:
        public void PackInventory()
        {
            if (!MyClient.There)
                return;
            Ready = false;
            try
            {
                PackedInventory = "";
                int count = 0;
                foreach (string item in Inventory)
                {
                    if (item != null && item != "")
                    {
                        if (count == 0)
                            PackedInventory += item + ":";
                        else if (count > 0)
                            PackedInventory += ":" + item + ":";
                    }
                    else
                        break;

                }
                if (PackedInventory.Length > 1)
                    PackedInventory = PackedInventory.Remove(PackedInventory.Length - 1, 1);
            }
            catch (Exception Exc) { General.WriteLine(Convert.ToString(Exc)); }
            Ready = true;
        }
UnPack:
Code:
        public void UnPackInventory()
        {
            Ready = false;
            if (PackedInventory.Length < 1)
                return;

            string[] Items = PackedInventory.Split(':');

            int count = 0;

            foreach (string item in Items)
            {
                if (item != null)
                    if (item.Length > 1)
                    {
                        AddItem(item, 0, (uint)General.Rand.Next(10000000));
                        count++;
                    }
                    else
                        break;
            }
            Ready = true;
        }
Save:
Code:
                Charr.PackInventory();
                Save.IniWriteValue("Packed", "Inventory", Charr.PackedInventory);
Then call the Unpack in case 74.

(I'm surprised, all of this is default in any LOTF based server... lol)
01/19/2009 07:29 alexbigfoot#14
ok....kinshi if u didnt know ... ur ini is not rdy to save over 256 chars....that needs fixing...or use the Tao`s save n load ,but for noobs, is too hard to put it in their sources. :rtfm:
01/19/2009 07:33 µ~Xero~µ#15
Quote:
Originally Posted by alexbigfoot View Post
ok....kinshi if u didnt know ... ur ini is not rdy to save over 256 chars....that needs fixing...or use the Tao`s save n load ,but for noobs, is too hard to put it in their sources. :rtfm:
255 chars not 256 :)

btw a save function is one of the easy things btw i recommend an Array list for inv. :)