[HELP]ini files for npcs

11/10/2008 01:05 taylor2846#1
Ty for your all help

how wold i setup for items??
11/10/2008 01:10 alexbigfoot#2
Code:
    
    public static void LoadNPCs()
        {
            try
            {
                string[] ENpc = File.ReadAllLines(System.Windows.Forms.Application.StartupPath + @"\gets\npcs.ini");
                NPCs = new uint[ENpc.Length][];
                for (int ik = 0; ik < ENpc.Length; ik++)
                {
                    string[] a = ENpc[ik].Split('#');
                    NPCs[ik] = new uint[8] { uint.Parse(a[0]), uint.Parse(a[1]), uint.Parse(a[3]), uint.Parse(a[4]), uint.Parse(a[5]), uint.Parse(a[6]), uint.Parse(a[7]), uint.Parse(a[8]) };
                }
                Console.Write("NPCs Loaded from DataBase: " + ENpc.Length + "\n");
                passednpcs = true;
            }
            catch (Exception Exc) { General.WriteLine(Convert.ToString(Exc)); passednpcs = false; }
        }
the thing i`m using.
11/10/2008 01:26 taylor2846#3
ty dude i was just aking for help but this works and saves me lots of time so ty dude no im gona go start working on the rest of my files to ini files
11/10/2008 01:36 © Haydz#4
Code:
 
public static string LoadNpcs
        {
            get
            {
                string[] StrDelimiter = File.ReadAllLines(DBFolder + "\\Npc\\Spawns.txt");
                Npcs = new ConquerNpc[StrDelimiter.Length];
                for (uint i = 0; i < StrDelimiter.Length; i++)
                    Npcs[i] = ConquerNpc.Parse(StrDelimiter[i]);
                return string.Format("\tLoaded {0} Npcs.", Npcs.Length);
            }
        }
Haydz wins?
11/10/2008 05:07 taguro#5
Actually, the way LOTF handles the NPC's is probably the most efficient. MYSQL only made the server unstable when it was required to keep an active connection to the server at all times. As players made changes to characters, the way the MYSQL connection was coded, the more unstable the server became. This was the source of the login error. C# reads from a MYSQL database faster than from flat files(most of the time, depending on the coding and the coder...), and in LOTF loading all non-changing entities from the MYSQL database increased the speed of the loading, and reduced overall memory usage. If your going to use flat files, you should only convert the characters, accounts, guilds, and friends to text files. This is strictly a personal opinion, as others may and will have different views, but I believe this is the most efficient way to write a server source.
11/10/2008 09:05 alexbigfoot#6
Quote:
Originally Posted by © Haydz View Post
Code:
 
public static string LoadNpcs
        {
            get
            {
                string[] StrDelimiter = File.ReadAllLines(DBFolder + "\\Npc\\Spawns.txt");
                Npcs = new ConquerNpc[StrDelimiter.Length];
                for (uint i = 0; i < StrDelimiter.Length; i++)
                    Npcs[i] = ConquerNpc.Parse(StrDelimiter[i]);
                return string.Format("\tLoaded {0} Npcs.", Npcs.Length);
            }
        }
Haydz wins?
probabily :D, after all, i`m not a genius :D
11/10/2008 13:25 tao4229#7
I intend to use .txt and .ini files for my new source the whole way through .

But from the looks of the first post it reads 1 value from each key and does nothing? Wtf? ._.
11/10/2008 14:59 Korvacs#8
Quote:
Originally Posted by © Haydz View Post
Code:
 
public static string LoadNpcs
        {
            get
            {
                string[] StrDelimiter = File.ReadAllLines(DBFolder + "\\Npc\\Spawns.txt");
                Npcs = new ConquerNpc[StrDelimiter.Length];
                for (uint i = 0; i < StrDelimiter.Length; i++)
                    Npcs[i] = ConquerNpc.Parse(StrDelimiter[i]);
                return string.Format("\tLoaded {0} Npcs.", Npcs.Length);
            }
        }
Haydz wins?
Not really, your still using strings at the end of the day which requires alot more processing...so no.
11/10/2008 15:45 Ultimatum#9
Quote:
public static void LoadNpcs()
{
string[] NPCFile = File.ReadAllLines(DB + "\\Instance\\NPC.txt");
foreach (string Content in NPCFile)
{
string[] NPCArray = Content.Split(' ');
NPCInstance Npc = new NPCInstance();
Npc.UID = Convert.ToUInt32(NPCArray[0]);
Npc.ID = Convert.ToUInt32(NPCArray[1]);
Npc.PosX = Convert.ToUInt16(NPCArray[2]);
Npc.PosY = Convert.ToUInt16(NPCArray[3]);
Npc.Type = Convert.ToUInt16(NPCArray[4]);
Npc.Direction = Convert.ToUInt16(NPCArray[5]);
Npc.Flag = Convert.ToUInt32(NPCArray[6]);
Npc.MapID = Convert.ToUInt16(NPCArray[7]);
SpawnNPCPack Spawn = new SpawnNPCPack();
Spawn.Npc = Npc;
Spawn.BuildPacket();
Spawn.SpawnNPCPack = Spawn.PacketData;
World.AllNpcs.Add(Npc.UID, Npc);
}
}
A bit like haydz ;D
11/10/2008 16:34 YukiXian#10
I can't equip any items anymore =( Someone knows how comes? ( I'm using Ini's )
11/10/2008 16:51 © Haydz#11
Quote:
Originally Posted by Korvacs View Post
Not really, your still using strings at the end of the day which requires alot more processing...so no.
The competion was between the other 2 pieces of code.
11/10/2008 20:34 YukiXian#12
Quote:
Originally Posted by YukiXian View Post
I can't equip any items anymore =( Someone knows how comes? ( I'm using Ini's )
*Edit : Found out my Source doesn't load my Ini items. how to load them?
I'f got this :
Code:
public static void LoadItems()
        {
            string[] Item = File.ReadAllLines(System.Windows.Forms.Application.StartupPath + @"\Others\AllItems.ini");
            DBItems = new string[Item.Length][];

            for (int i = 0; i < Item.Length; i++)
            {
                string[] Splitter = Item[i].Split('-');
                //Items[i] = new uint[15] { uint.Parse(Splitter[0]), uint.Parse(Splitter[1]), uint.Parse(Splitter[2]), uint.Parse(Splitter[3]), uint.Parse(Splitter[4]), uint.Parse(Splitter[5]), uint.Parse(Splitter[6]), uint.Parse(Splitter[7]), uint.Parse(Splitter[8]), uint.Parse(Splitter[9]), uint.Parse(Splitter[10]), uint.Parse(Splitter[11]), uint.Parse(Splitter[12]), uint.Parse(Splitter[13]), uint.Parse(Splitter[14]), uint.Parse(Splitter[15]) };
                DBItems[i] = new string[16] { Splitter[0], Splitter[1], uint.Parse(Splitter[2]), uint.Parse(Splitter[3]), uint.Parse(Splitter[4]), uint.Parse(Splitter[5]), uint.Parse(Splitter[6]), uint.Parse(Splitter[7]), uint.Parse(Splitter[8]), uint.Parse(Splitter[9]), uint.Parse(Splitter[10]), uint.Parse(Splitter[11]), uint.Parse(Splitter[12]), uint.Parse(Splitter[13]), uint.Parse(Splitter[14]), uint.Parse(Splitter[15]) };
            }
            Console.WriteLine("Loaded all items.");