|
You last visited: Today at 02:38
Advertisement
Distribute Attributes Command
Discussion on Distribute Attributes Command within the CO2 Private Server forum part of the Conquer Online 2 category.
02/04/2010, 06:06
|
#1
|
elite*gold: 0
Join Date: Jul 2008
Posts: 259
Received Thanks: 73
|
Distribute Attributes Command
I'm using the 4267 CoFuture source and am trying to code some simple commands. I made this command to distribute dexterity attributes but when i try it, the console gives an error saying the index was outside the bounds od the array.
Heres my code.
Code:
if (Splitter[0] == "/dex")
{
if (Client.Char.StatPoints >= Convert.ToUInt16(Splitter[2]))
{
Client.Char.StatPoints -= Convert.ToUInt16(Splitter[2]);
Client.Char.Dexterity = Convert.ToUInt16(Splitter[2]);
Client.SendData(ConquerPacket.Status(Client, Client.Char.Dexterity, Struct.StatusTypes.DexterityStatPoints));
Client.SendData(ConquerPacket.Status(Client, Client.Char.StatPoints, Struct.StatusTypes.AttributePoints));
}
}
Any help or feedback is appreciated.
|
|
|
02/04/2010, 06:42
|
#2
|
elite*gold: 20
Join Date: Oct 2009
Posts: 1,009
Received Thanks: 621
|
Quote:
Originally Posted by CIRASH
I'm using the 4267 CoFuture source and am trying to code some simple commands. I made this command to distribute dexterity attributes but when i try it, the console gives an error saying the index was outside the bounds od the array.
Heres my code.
Code:
if (Splitter[0] == "/dex")
{
if (Client.Char.StatPoints >= Convert.ToUInt16(Splitter[2]))
{
Client.Char.StatPoints -= Convert.ToUInt16(Splitter[2]);
Client.Char.Dexterity = Convert.ToUInt16(Splitter[2]);
Client.SendData(ConquerPacket.Status(Client, Client.Char.Dexterity, Struct.StatusTypes.DexterityStatPoints));
Client.SendData(ConquerPacket.Status(Client, Client.Char.StatPoints, Struct.StatusTypes.AttributePoints));
}
}
Any help or feedback is appreciated.
|
Should be
Code:
if (Splitter[0] == "/dex")
{
if (Client.Char.StatPoints >= Convert.ToUInt16(Splitter[1]))
{
Client.Char.StatPoints -= Convert.ToUInt16(Splitter[1]);
Client.Char.Dexterity = Convert.ToUInt16(Splitter[1]);
Client.SendData(ConquerPacket.Status(Client, Client.Char.Dexterity, Struct.StatusTypes.DexterityStatPoints));
Client.SendData(ConquerPacket.Status(Client, Client.Char.StatPoints, Struct.StatusTypes.AttributePoints));
}
}
|
|
|
02/04/2010, 06:55
|
#3
|
elite*gold: 0
Join Date: Jul 2008
Posts: 259
Received Thanks: 73
|
Wow, such a simple problem haha. Thanks Spare
#request close
|
|
|
02/04/2010, 07:15
|
#4
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,383
|
Yah, always remember that [0] is the initial command, they don't start with 1.
It's even more fun when you're selecting ranges of stuff and trying to figure out why it's not grabbing the right data... then you realize you were counting them up wrong :P
|
|
|
02/04/2010, 08:05
|
#5
|
elite*gold: 0
Join Date: Jul 2008
Posts: 259
Received Thanks: 73
|
I'm converting your met/db bank for 1.0 now xD
|
|
|
02/04/2010, 08:17
|
#6
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,383
|
Ahaha... that's funny because I converted my metbank FROM 1.0.
here's the original code (no met/db scroll functionality cause I didn't have a itemtype editor to add them)
PHP Code:
#region Met/Db Storage case 47://input test npc (prize npc) { if (LinkBack == 0) { Text("I can help you store your excess mets and dbs!", Client); Text("What would you like to do today?", Client); Link("Mets", 1, Client); Link("Dbs", 2, Client); Link("Check balance", 11, Client); Link("Nevermind...", 255, Client); Face(91, Client); End(Client); }
if (LinkBack == 1)//Mets { Text("Are you wanting to put mets in or withdraw?", Client); Text("Met balance - " + Client.Char.MetPoint, Client); Link("Withdraw", 3, Client); Link("Deposit", 4, Client); Link("Nevermind...", 255, Client); Face(91, Client); End(Client); }
if (LinkBack == 2)//Dbs { Text("Are you wanting to put dragonballs in or withdraw?", Client); Text("DragonBall balance - " + Client.Char.DbPoint, Client); Link("Withdraw", 5, Client); Link("Deposit", 6, Client); Link("Nevermind...", 255, Client); Face(91, Client); End(Client); } if (LinkBack == 11) { Text("Met balance - " + Client.Char.MetPoint, Client); Text("DragonBall balance - " + Client.Char.DbPoint, Client); Link("Main menu", 0, Client); Link("Thanks", 255, Client); Face(91, Client); End(Client); } if (LinkBack == 3) { Text("How many mets are you withdrawing today?", Client); Input(" ", 7, Client); Link("Nevermind...", 255, Client); Face(91, Client); End(Client); } if (LinkBack == 4) { Text("How many mets are you depositing today?", Client); Input(" ", 8, Client); Link("Nevermind...", 255, Client); Face(91, Client); End(Client); } if (LinkBack == 5) { Text("How many dragonballs are you withdrawing today?", Client); Input(" ", 9, Client); Link("Nevermind...", 255, Client); Face(91, Client); End(Client); } if (LinkBack == 6) { Text("How many dragonballs are you depositing today?", Client); Input(" ", 10, Client); Link("Nevermind...", 255, Client); Face(91, Client); End(Client); } else if (LinkBack == 7)//withdraw mets { string Mets = ""; for (int i = 14; i < 14 + Data[13]; i++) { Mets += Convert.ToChar(Data[i]); } Console.WriteLine("NameGiven = " + Mets); int MetsInt = 0; try { MetsInt = int.Parse(Mets); Console.WriteLine("Int = " + MetsInt); } catch { Text("You did not enter a number!", Client); Link("Oops, my bad!", 255, Client); Face(91, Client); End(Client); Console.WriteLine("Error: Could not convert to int!"); } if (Client.Char.MetPoint >= MetsInt) { if ((Client.Char.Inventory.Count + MetsInt) <= 40) { int Quantity = MetsInt; while (Quantity > 0) { AddItem(1088001, 255, 0, 0, 0, 0, Client); Quantity -= 1; } Client.Char.MetPoint -= MetsInt; Database.SaveMetPoint(Client.Char); Text("You have " + Client.Char.MetPoint + " MetPoints left", Client); Link("Main Menu", 0, Client); Link("Wow, thanks alot!", 255, Client); Face(91, Client); End(Client);
} else { Text("You do not have enough room in your inventory", Client); Link("Oops, my bad", 255, Client); Face(91, Client); End(Client); } } else { Text("You do not have that many MetPoints!", Client); Link("Oops, my bad", 255, Client); Face(91, Client); End(Client); }
} else if (LinkBack == 8)//deposit mets { string Mets = ""; for (int i = 14; i < 14 + Data[13]; i++) { Mets += Convert.ToChar(Data[i]); } Console.WriteLine("NameGiven = " + Mets); int MetsInt = 0; try { MetsInt = int.Parse(Mets); Console.WriteLine("Int = " + MetsInt); } catch { Text("You did not enter a number!", Client); Link("Oops, my bad!", 255, Client); Face(91, Client); End(Client); Console.WriteLine("Error: Could not convert to int!"); } if (InventoryContains(1088001, Client, MetsInt)) { RemoveItem(1088001, Client, MetsInt); Client.Char.MetPoint += MetsInt; Database.SaveMetPoint(Client.Char); Text("You now have " + Client.Char.MetPoint + " MetPoints!", Client); Link("Main Menu", 0, Client); Link("Wow, thanks alot!", 255, Client); Face(91, Client); End(Client);
} else { Text("You do not have that many mets in your inventory!", Client); Link("Oops, my bad", 255, Client); Face(91, Client); End(Client); }
} else if (LinkBack == 9)//withdraw Dbs { string Dbs = ""; for (int i = 14; i < 14 + Data[13]; i++) { Dbs += Convert.ToChar(Data[i]); } Console.WriteLine("NameGiven = " + Dbs); int DbsInt = 0; try { DbsInt = int.Parse(Dbs); Console.WriteLine("Int = " + DbsInt); } catch { Text("You did not enter a number!", Client); Link("Oops, my bad!", 255, Client); Face(91, Client); End(Client); Console.WriteLine("Error: Could not convert to int!"); } if (Client.Char.DbPoint >= DbsInt) { if ((Client.Char.Inventory.Count + DbsInt) <= 40) { int Quantity = DbsInt; while (Quantity > 0) { AddItem(1088000, 255, 0, 0, 0, 0, Client); Quantity -= 1; } Client.Char.DbPoint -= DbsInt; Database.SaveDbPoint(Client.Char); Text("You have " + Client.Char.DbPoint + " DbPoints left", Client); Link("Main Menu", 0, Client); Link("Wow, thanks alot!", 255, Client); Face(91, Client); End(Client);
} else { Text("You do not have enough room in your inventory.", Client); Link("Oops, my bad", 255, Client); Face(91, Client); End(Client); } } else { Text("You do not have that many DbPoints!", Client); Link("Oops, my bad", 255, Client); Face(91, Client); End(Client); }
} else if (LinkBack == 10)//deposit Dbs { string Dbs = ""; for (int i = 14; i < 14 + Data[13]; i++) { Dbs += Convert.ToChar(Data[i]); } Console.WriteLine("NameGiven = " + Dbs); int DbsInt = 0; try { DbsInt = int.Parse(Dbs); Console.WriteLine("Int = " + DbsInt); } catch { Text("You did not enter a number!", Client); Link("Oops, my bad!", 255, Client); Face(91, Client); End(Client); Console.WriteLine("Error: Could not convert to int!"); } if (InventoryContains(1088000, Client, DbsInt)) { RemoveItem(1088000, Client, DbsInt); Client.Char.DbPoint += DbsInt; Database.SaveDbPoint(Client.Char); Text("You now have " + Client.Char.DbPoint + " DbPoints!", Client); Link("Main Menu", 0, Client); Link("Wow, thanks alot!", 255, Client); Face(91, Client); End(Client);
} else { Text("You do not have that many DragonBalls in your inventory!", Client); Link("Oops, my bad", 255, Client); Face(91, Client); End(Client); }
} break; } #endregion
database voids
PHP Code:
public static void SaveMetPoint(Character Char) { lock (DatabaseConnection) { MySqlCommand Comm = new MySqlCommand("UPDATE `characters` SET `MetPoint` = " + Char.MetPoint + " WHERE `CharID` = " + Char.ID + "", DatabaseConnection); } } public static void SaveDbPoint(Character Char) { lock (DatabaseConnection) { MySqlCommand Comm = new MySqlCommand("UPDATE `characters` SET `DbPoint` = " + Char.DbPoint + " WHERE `CharID` = " + Char.ID + "", DatabaseConnection);
}
}
Not sure if you need these but w/e
here's the voids, most should be in source already though
PHP Code:
public static bool RemoveItem(int ItemID, COClient Client, int Amount) { List<Struct.ItemInfo> RemoveList = new List<Struct.ItemInfo>(Amount); int Count = 0; foreach (Struct.ItemInfo Item in Client.Char.Inventory.Values) if (Item.ItemID == ItemID) { if (Count < Amount) { Database.DeleteItem(Item.UID); RemoveList.Add(Item); Client.SendData(ConquerPacket.ItemUsage(Item.UID, 0, Struct.ItemUsage.RemoveItem)); Count++; } else break; } foreach (Struct.ItemInfo Item in RemoveList) Client.Char.Inventory.Remove(Item.UID); return false; }
public static bool InventoryContains(int ItemID, COClient Client, int Amount) { int got = 0; foreach (Struct.ItemInfo Item in Client.Char.Inventory.Values) if (Item.ItemID == ItemID) got++; if (got >= Amount) return true; if (ItemID == 1088000) ErrorMsg("I cant do it, I still need " + (Amount - got) + " dragonballs.", Client); if (ItemID == 1088001) ErrorMsg("I cant do it, I still need " + (Amount - got) + " meteors.", Client); return false; }
Enjoy.
|
|
|
02/04/2010, 08:49
|
#7
|
elite*gold: 0
Join Date: Jul 2008
Posts: 259
Received Thanks: 73
|
Thanks. Saved me quite some time. Testing now.
|
|
|
02/04/2010, 09:00
|
#8
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,383
|
You might wanna remove some of the console.writeline's. I had them in there when I was first writing it for debug purposes... it's kinda a messy release but it should work.
|
|
|
02/06/2010, 01:13
|
#9
|
elite*gold: 0
Join Date: Jul 2008
Posts: 259
Received Thanks: 73
|
Hmm, wont save after logoff even though i added it for saving and loading character.
|
|
|
All times are GMT +1. The time now is 02:39.
|
|