Best Way

07/09/2011 10:32 zTek#1
So I was trying to think of a way to do this using an array, example:
Code:
byte[] iVal = new byte[12] { 5, 10, etc };
I couldn't think of a way to call it though.

So then I used this method (which most likely is the worst way to do it):
Code:
public static void iSave()
        {
            byte i = 1;
        Restart:
            while (i <= 12)
            {
                World.SaveAllChars();
                Thread.Sleep(300000);
                i++;
            }
            goto Restart;
        }
If anyone can show me the best way to do it, that would be great, and something to learn off of.

Thank you
07/09/2011 10:37 Spirited#2
Code:
public static void iSave()
        {
            while (true)
            {
                World.SaveAllChars();
                Thread.Sleep(300000);
            }
        }
You can use arrays for movement direction or for an npc.
07/09/2011 10:45 zTek#3
Thanks man, I appreciate it.

Just for learning experience, can you show me a way I COULD do it with arrays?
I would really like to know.

*Edit*

How could you use a loop on this?

*Edit*

This is probably a failure attempt to loop it, but could you do this:

if (iGo[0] <= iGo[11])
{
byte i = (byte)iGo[0];
World.SaveAllChars();
i++;
}
07/09/2011 11:18 _DreadNought_#4
Basically, Find your character thread and link the void in, Have a TimeStamp check using the native TimeGetTime() and use cases for faster processesing.
07/09/2011 12:27 zTek#5
Code:
 public static void SaveChar(Character Charr)
        {
            try
            {
                Charr.PackInventory();
                Charr.PackEquips();
                Charr.PackSkills();
                Charr.PackProfs();
                Charr.PackWarehouses();
                Charr.PackEnemies();
                Charr.PackFriends();

                MySqlCommand Command = new MySqlCommand("UPDATE `Characters` SET `CharName` = '" + Charr.Name + "', `Level` = " + Charr.Level + ",`Exp` = " + Charr.Exp + ",`GuildDonation` = " + Charr.GuildDonation + ",`Strength` = " + Charr.Str + ",`Agility` = " + Charr.Agi + ",`Vitality` = " + Charr.Vit + ",`Spirit` = " + Charr.Spi + ",`Job` = " + Charr.Job + ",`Model` = " + Charr.RealModel + ",`Money` = " + Charr.Silvers + ",`CPs` = " + Charr.CPs + ",`CurrentHP` = " + Charr.CurHP + ",`StatPoints` = " + Charr.StatP + ",`MyGuild` = " + Charr.GuildID + ",`GuildPos` = " + Charr.GuildPosition + ",`LocationMap` = " + Charr.LocMap + ",`LocationX` = " + Charr.LocX + ",`LocationY` = " + Charr.LocY + ",`Hair` = " + Charr.Hair + ",`Equipment` = '" + Charr.PackedEquips + "',`Inventory` = '" + Charr.PackedInventory + "',`PKPoints` = " + Charr.PKPoints + ",`PrevMap` = " + Charr.PrevMap + ", `Skills` = '" + Charr.PackedSkills + "', `Profs` = '" + Charr.PackedProfs + "',`RBCount` = " + Charr.RBCount + ",`Avatar` = " + Charr.Avatar + ",`WHMoney` = " + Charr.WHSilvers + ",`VP` = " + Charr.VP + ",`Warehouses` = '" + Charr.PackedWHs + "',`Friends` = '" + Charr.PackedFriends + "',`Enemies` = '" + Charr.PackedEnemies + "' WHERE `Account` = '" + Charr.MyClient.Account + "'", Connection);
                Command.ExecuteNonQuery();
            }
            catch (Exception Exc) { General.WriteLine(Convert.ToString(Exc));}
        }
Code:
public static void SaveAllChars()
        {
            try
            {
                foreach (DictionaryEntry DE in AllChars)
                {
                    Character Charr = (Character)DE.Value;
                    DataBase.SaveChar(Charr);
                }
                Guilds.SaveAllGuilds();
            }
            catch (Exception Exc) { General.WriteLine(Convert.ToString(Exc)); }
        }
07/09/2011 17:18 Y u k i#6
:facepalm:
07/09/2011 18:52 BaussHacker#7
You don't need to put a length of an array, if you're defining values in it.
Code:
int[] iGo = new int[12] { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60 };
Would be the same as
Code:
int[] iGo = new int[] { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60 };