|
You last visited: Today at 00:24
Advertisement
Best Way
Discussion on Best Way within the CO2 Private Server forum part of the Conquer Online 2 category.
07/09/2011, 10:32
|
#1
|
elite*gold: 0
Join Date: May 2011
Posts: 168
Received Thanks: 33
|
Best Way
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
|
#2
|
elite*gold: 12
Join Date: Jul 2011
Posts: 8,283
Received Thanks: 4,191
|
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
|
#3
|
elite*gold: 0
Join Date: May 2011
Posts: 168
Received Thanks: 33
|
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?
Code:
public static void iSave()
{
int Value = DateTime.Now.Minute;
int[] iGo = new int[12] { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60 };
if (Value == iGo[0])
{
World.SaveAllChars();
}
if (Value == iGo[1])
{
World.SaveAllChars();
}
if (Value == iGo[2])
{
World.SaveAllChars();
}
if (Value == iGo[3])
{
World.SaveAllChars();
}
if (Value == iGo[4])
{
World.SaveAllChars();
}
if (Value == iGo[5])
{
World.SaveAllChars();
}
if (Value == iGo[6])
{
World.SaveAllChars();
}
if (Value == iGo[7])
{
World.SaveAllChars();
}
if (Value == iGo[8])
{
World.SaveAllChars();
}
if (Value == iGo[9])
{
World.SaveAllChars();
}
if (Value == iGo[10])
{
World.SaveAllChars();
}
if (Value == iGo[11])
{
World.SaveAllChars();
}
}
*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
|
#4
|
elite*gold: 28
Join Date: Jun 2010
Posts: 2,226
Received Thanks: 868
|
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
|
#5
|
elite*gold: 0
Join Date: May 2011
Posts: 168
Received Thanks: 33
|
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
|
#6
|
elite*gold: 0
Join Date: May 2011
Posts: 648
Received Thanks: 413
|
|
|
|
07/09/2011, 18:52
|
#7
|
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
|
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 };
|
|
|
All times are GMT +1. The time now is 00:25.
|
|