As far as I know there is no better, more complete system released publicly. It may not be perfect but it's close. I don't actually run a server so there could be some bugs that I didn't run into while testing it for a few minutes so keep your eyes open.
Main Npc text (using lady luck simply because I don't want lottery on my server but simple enough to change the npc number)
Place in handlers>NpcTalk.cs
PHP Code:
#region Met/db Storage
case 47: // Prize npc test
{
if (LinkBack == 0)
{
Text("I can help you store your excess mets and dbs!\n", CSocket);
Text("What would you like to do today?", CSocket);
Link("Mets", 1, CSocket);
Link("Dbs", 2, CSocket);
Link("Check balance", 11, CSocket);
Link("Nevermind...", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (LinkBack == 1)//Mets
{
Text("Are you wanting to put mets in or withdraw?\n", CSocket);
Text("Met balance - " + CSocket.Client.MetPoints, CSocket);
Link("Withdraw", 3, CSocket);
Link("Deposit", 4, CSocket);
Link("Nevermind...", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (LinkBack == 2)//Dbs
{
Text("Are you wanting to put dragonballs in or withdraw?\n", CSocket);
Text("DragonBall balance - " + CSocket.Client.DbPoints, CSocket);
Link("Withdraw", 5, CSocket);
Link("Deposit", 6, CSocket);
Link("Nevermind...", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (LinkBack == 11)
{
Text("Met balance - " + CSocket.Client.MetPoints, CSocket);
Text("\nDragonBall balance - " + CSocket.Client.DbPoints, CSocket);
Link("Main menu", 0, CSocket);
Link("Thanks", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (LinkBack == 3)
{
Text("How many mets are you withdrawing today?", CSocket);
Input(" ", 7, CSocket);
Link("Nevermind...", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (LinkBack == 4)
{
Text("How many mets are you depositing today?", CSocket);
Input(" ", 8, CSocket);
Link("Nevermind...", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (LinkBack == 5)
{
Text("How many dragonballs are you withdrawing today?", CSocket);
Input(" ", 9, CSocket);
Link("Nevermind...", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (LinkBack == 6)
{
Text("How many dragonballs are you depositing today?", CSocket);
Input(" ", 10, CSocket);
Link("Nevermind...", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
else if (LinkBack == 7)//withdraw mets
{
string Mets = ""; for (int i = 14; i < 14 + Data[13]; i++) { Mets += Convert.ToChar(Data[i]); }
int MetsInt = 0;
try
{
MetsInt = int.Parse(Mets);
}
catch
{
Text("You did not enter a number!", CSocket);
Link("Oops, my bad!", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (CSocket.Client.MetPoints >= MetsInt)
{
int MetScrollInt = 0;
int Amount = MetsInt;
while (Amount >= 10)
{
MetScrollInt += 1;
Amount -= 10;
}
if ((CSocket.Client.Inventory.Count + Amount + MetScrollInt) <= 40)
{
int Quantity = MetsInt;
while (Quantity >= 10)
{
AddItem(720027, 0, 0, 0, 0,0, 0, 0, 0, 1, CSocket);
Quantity -= 10;
}
while (Quantity > 0)
{
AddItem(1088001, 0, 0, 0, 0, 0, 0, 0, 0, 1, CSocket);
Quantity -= 1;
}
CSocket.Client.MetPoints -= MetsInt;
Database.Database.SaveMetPoint(CSocket);
Text("You have " + CSocket.Client.MetPoints + " MetPoints left", CSocket);
Link("Main Menu", 0, CSocket);
Link("Wow, thanks alot!", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
else
{
Text("You do not have enough room in your inventory", CSocket);
Link("Oops, my bad", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
}
else
{
Text("You do not have that many MetPoints!", CSocket);
Link("Oops, my bad", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
}
else if (LinkBack == 8)//deposit mets
{
string Mets = ""; for (int i = 14; i < 14 + Data[13]; i++) { Mets += Convert.ToChar(Data[i]); }
int MetsInt = 0;
try
{
MetsInt = int.Parse(Mets);
}
catch
{
Text("You did not enter a number!", CSocket);
Link("Oops, my bad!", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
int MetScToTake = (int)(MetsInt / 10);
int MetToTake = (MetsInt - (MetScToTake * 10));
int InventMets = 0;
int InventScroll = 0;
if (MetScToTake > 0)
{
foreach (Struct.ItemInfo Item in CSocket.Client.Inventory.Values)
if (Item.ItemID == 720027)
InventScroll += 1;
}
foreach (Struct.ItemInfo Item in CSocket.Client.Inventory.Values)
if (Item.ItemID == 1088001)
InventMets += 1;
if ((InventMets > MetToTake) && ((InventScroll > MetScToTake) || ((InventMets * 10) > MetScToTake)))
{
while((MetScToTake >= 0) && (InventoryContains(720027, CSocket, 1)))
{
RemoveItem(720027, CSocket, 1);
MetScToTake--;
}
while ((MetScToTake > 0) && InventoryContains(1088001, CSocket, 10))
{
int totake = 10;
while (totake > 0)
{
RemoveItem(1088001, CSocket, 1);
totake--;
}
MetScToTake--;
}
while ((MetToTake > 0) && InventoryContains(1088001, CSocket, 1))
{
RemoveItem(1088001, CSocket, 1);
MetToTake--;
}
if (MetToTake == 0 && MetScToTake == 0)
{
CSocket.Client.MetPoints += MetsInt;
Database.Database.SaveMetPoint(CSocket);
Text("You now have " + CSocket.Client.MetPoints + " MetPoints!", CSocket);
Link("Main Menu", 0, CSocket);
Link("Wow, thanks alot!", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
else
{
ErrorMsg("Shit Got Fucked Up...", CSocket);
}
}
else
{
Text("You do not have that many mets in your inventory!", CSocket);
Link("Oops, my bad", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
}
else if (LinkBack == 9)//withdraw Dbs
{
string Dbs = ""; for (int i = 14; i < 14 + Data[13]; i++) { Dbs += Convert.ToChar(Data[i]); }
int DbsInt = 0;
try
{
DbsInt = int.Parse(Dbs);
}
catch
{
Text("You did not enter a number!", CSocket);
Link("Oops, my bad!", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
if (CSocket.Client.DbPoints >= DbsInt)
{
int DbScrollInt = 0;
int Amount = DbsInt;
while (Amount >= 10)
{
DbScrollInt += 1;
Amount -= 10;
}
if ((CSocket.Client.Inventory.Count + Amount + DbScrollInt) <= 40)
{
int Quantity = Amount + (DbScrollInt * 10);
while (Quantity >= 10)
{
AddItem(720028, 0, 0, 0, 0, 0, 0, 0, 0, 1, CSocket);
Quantity -= 10;
}
while (Quantity > 0)
{
AddItem(1088000, 0, 0, 0, 0, 0, 0, 0, 0, 1, CSocket);
Quantity -= 1;
}
CSocket.Client.DbPoints -= DbsInt;
Database.Database.SaveDbPoint(CSocket);
Text("You have " + CSocket.Client.DbPoints + " DbPoints left", CSocket);
Link("Main Menu", 0, CSocket);
Link("Wow, thanks alot!", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
else
{
Text("You do not have enough room in your inventory.", CSocket);
Link("Oops, my bad", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
}
else
{
Text("You do not have that many DbPoints!", CSocket);
Link("Oops, my bad", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
}
else if (LinkBack == 10)//deposit Dbs
{
string Dbs = ""; for (int i = 14; i < 14 + Data[13]; i++) { Dbs += Convert.ToChar(Data[i]); }
int DbsInt = 0;
try
{
DbsInt = int.Parse(Dbs);
}
catch
{
Text("You did not enter a number!", CSocket);
Link("Oops, my bad!", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
int DbScToTake = (int)(DbsInt / 10);
int DbToTake = (DbsInt - (DbScToTake * 10));
int InventMets = 0;
int InventScroll = 0;
if (DbScToTake > 0)
{
foreach (Struct.ItemInfo Item in CSocket.Client.Inventory.Values)
if (Item.ItemID == 720028)
InventScroll++;
}
foreach (Struct.ItemInfo Item in CSocket.Client.Inventory.Values)
if (Item.ItemID == 1088000)
InventMets += 1;
if ((InventMets >= DbToTake) && ((InventScroll > DbScToTake) || ((InventMets * 10) > DbScToTake)))
{
while ((DbScToTake > 0) && (InventoryContains(720028, CSocket, 1)))
{
RemoveItem(720028, CSocket, 1);
DbScToTake--;
}
while ((DbScToTake > 0) && InventoryContains(1088000, CSocket, 10))
{
int totake = 10;
while (totake > 0)
{
RemoveItem(1088000, CSocket, 1);
totake--;
}
DbScToTake--;
}
while ((DbToTake > 0) && InventoryContains(1088000, CSocket, 1))
{
RemoveItem(1088000, CSocket, 1);
DbToTake--;
}
if (DbToTake == 0 && DbScToTake == 0)
{
CSocket.Client.DbPoints += DbsInt;
Database.Database.SaveDbPoint(CSocket);
Text("You now have " + CSocket.Client.DbPoints + " DbPoints!", CSocket);
Link("Main Menu", 0, CSocket);
Link("Wow, thanks alot!", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
else
{
ErrorMsg("Shit Got Fucked Up...", CSocket);
}
}
else
{
Text("You do not have that many DragonBalls in your inventory!", CSocket);
Link("Oops, my bad", 255, CSocket);
Face(91, CSocket);
End(CSocket);
}
}
break;
}
#endregion
You will also be needing some functions so I may as well post some of them (if I miss some, that's your own damn problem to fix them.)
Note: the base source I was messing around with doesn't have composition or anything like that so you will need to modify the codes accordingly.
Place in Database>Database.cs
PHP Code:
public static void SaveMetPoint(ClientSocket CSocket)
{
MySqlCommand Cmd = new MySqlCommand("UPDATE `characters` SET `MetPoints` = " + CSocket.Client.MetPoints + " WHERE `CharID` = " + CSocket.Client.ID + "", DatabaseConnection.NewConnection());
Cmd.ExecuteNonQuery();
Cmd.Connection.Close();
Cmd.Connection.Dispose();
Cmd.Dispose();
}
public static void SaveDbPoint(ClientSocket CSocket)
{
MySqlCommand Cmd = new MySqlCommand("UPDATE `characters` SET `DbPoints` = " + CSocket.Client.DbPoints + " WHERE `CharID` = " + CSocket.Client.ID + "", DatabaseConnection.NewConnection());
Cmd.ExecuteNonQuery();
Cmd.Connection.Close();
Cmd.Connection.Dispose();
Cmd.Dispose();
}
place in the bottom of Handlers>Npctalk.cs
Code:
public static void Input(int LinkBack, ClientSocket CSocket) { CSocket.Send(ConquerPacket.NPCTalk(LinkBack, 3, "")); } public static void Input(string text, int LinkBack, ClientSocket CSocket) { CSocket.Send(ConquerPacket.NPCTalk(LinkBack, 3, text)); }
Code:
public static bool InventoryContains(int ItemID, ClientSocket CSocket, int Amount) { int got = 0; foreach (Struct.ItemInfo Item in CSocket.Client.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.", CSocket); if (ItemID == 1088001) ErrorMsg("I cant do it, I still need " + (Amount - got) + " meteors.", CSocket); return false; }
PHP Code:
public static void AddItem(int itemid, int bless, int dura, int enchant, int plus, int position, int soc1, int soc2, int color, ClientSocket CSocket, byte Count)
{
for (byte t = 0; t < Count; t++)
{
Struct.ItemInfo Item = new Struct.ItemInfo();
if (dura == 255)
{
Item.Dura = Item.MaxDura;
}
else
{
Item.Dura = dura;
}
Item.Bless = bless;
Item.Enchant = enchant;
Item.ItemID = itemid;
Item.Plus = plus;
//Item.Progress = Progress;
Item.Position = position;
Item.Soc1 = soc1;
Item.Soc2 = soc2;
Item.Color = color;
Item.UID = Nano.Rand.Next(1, 9999999);
bool created = Database.Database.NewItem(Item, CSocket);
while (!created)
{
Item.UID = Nano.Rand.Next(1, 9999999);
created = Database.Database.NewItem(Item, CSocket);
}
CSocket.Client.Inventory.Add(Item.UID, Item);
CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
}
}
public static bool RemoveItem(int ItemID, ClientSocket CSocket, int Amount)
{
List<Struct.ItemInfo> RemoveList = new List<Struct.ItemInfo>(Amount);
int Count = 0;
foreach (Struct.ItemInfo Item in CSocket.Client.Inventory.Values)
if (Item.ItemID == ItemID)
{
if (Count < Amount)
{
Database.Database.DeleteItem(Item.UID);
RemoveList.Add(Item);
CSocket.Send(ConquerPacket.ItemUsage(Item.UID, 0, Struct.ItemUsage.RemoveItem));
Count++;
}
else
break;
}
foreach (Struct.ItemInfo Item in RemoveList)
CSocket.Client.Inventory.Remove(Item.UID);
return false;
}
public static void DeleteItem(int ItemID, byte Count, ClientSocket CSocket)
{
int[] Uids = new int[Count]; byte ItemsFound = 0;
foreach (Struct.ItemInfo Item in CSocket.Client.Inventory.Values)
{
if (Item.ItemID == ItemID)
{
Uids[ItemsFound] = Item.UID; ItemsFound++;
}
if (ItemsFound == Count) break;
}
for (byte t = 0; t < Count; t++)
{
CSocket.Client.Inventory.Remove(Uids[t]);
CSocket.Send(ConquerPacket.ItemUsage(Uids[t], 255, Struct.ItemUsage.RemoveItem));
Database.Database.DeleteItem(Uids[t]);
}
}
public static void MetPoints(int value, ClientSocket CSocket)
{
CSocket.Client.MetPoints += value;
}
public static void DbPoints(int value, ClientSocket CSocket)
{
CSocket.Client.DbPoints += value;
}
Code:
public static void Face(int Face, ClientSocket CSocket) { CSocket.Send(ConquerPacket.NPCTalk(2544, Face, 255, 4)); }
Note: If you don't have Data you will need to modify the top npctalk void to include it by using this line of code
Code:
public static void NpcTalk(ClientSocket CSocket, int ID, int LinkBack, byte[] Data)
Code:
public int DbPoints = 0; public int MetPoints = 0;
Obviously you will need to modify the character database to have a field for MetPoints and DbPoints (int, not nul, 0 decimals, default 0 etc)
Now modify your database so that it loads the points with the character (if not you will lose them on logoff even though they ARE being saved to the database properly)
Search Client.ID = Convert.ToInt32(DR["CharID"]);
and place
Client.MetPoints = Convert.ToInt32(DR["MetPoints"]);
Client.DbPoints = Convert.ToInt32(DR["DbPoints"]);
somewhere below it
Should be simple enough to setup by simply following other met/db storage scripts. Only difference is this one uses input fields. Storage will store scrolls first and extra mets second, removal should work perfectly with inventory space calculating scrolls and loose met/db's separately.
Anyways, should be easily converted to use in any source but figured seeing as I finished it and have no real use for it I'd release. Hopefully it will help ppl be able to learn from it.
<edit>
Cleaned up some stuff, had two copies of the database voids. Added spoilers so it's not quite as massive a post, grouped some stuff together. Nothing big changed.
<edit 2>
Re-wrote alot of the depositing code so you can't get free db/mets.. WHOOPS!