So I was bored and re-wrote my met/db bank that I made for my 1.0 server and converted it for use with CoEmu. I ended up changing some stuff around so that it works with met/db scrolls also.
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)
#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.
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); }
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)
and under character.cs
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!
Really is shocking after having come back how few people care about CoEmu anymore. 10 bux said if I or someone else converted it for the new lotf source this thread would be buzzing ^^
Good work, despite CoEmu's "dying" popularity. It's good to see a public system that many people are going to try and implement into their PS'. Can't wait 'till my level of coding is as decent, so many ideas so many steps ^_^
Good work, despite CoEmu's "dying" popularity. It's good to see a public system that many people are going to try and implement into their PS'. Can't wait 'till my level of coding is as decent, so many ideas so many steps ^_^
Glad you find it useful. There isn't anything super complex with this script (although as you mentioned there is alot of it lol) except getting a hang of input fields and making sure I handled counting properly. If you have any questions about how to use some of the stuff out of it for a different script (or even have a request for a system/npc you would like to see made), lemme know.
When I get bored I tend to put together lil scripts just for fun so having a direction to them would be kinda nice.
Glad you find it useful. There isn't anything super complex with this script (although as you mentioned there is alot of it lol) except getting a hang of input fields and making sure I handled counting properly. If you have any questions about how to use some of the stuff out of it for a different script (or even have a request for a system/npc you would like to see made), lemme know.
When I get bored I tend to put together lil scripts just for fun so having a direction to them would be kinda nice.
Cool, I really appreciate it. And all the help everyone's been. It's hard to find a community with patience.
Really is shocking after having come back how few people care about CoEmu anymore. 10 bux said if I or someone else converted it for the new lotf source this thread would be buzzing ^^
I have converted it, anyway conqueremu have died just because ninety percent of the forum only cares about highest patch and not about the quantity nor quality.
I have converted it, anyway conqueremu have died just because ninety percent of the forum only cares about highest patch and not about the quantity nor quality.
Yeah, I noticed that today.
****, some things never change.
Pro4Never, just sayin gratz.
You have a lot more experience from the first time I saw one of your releases.
This script is proving you know the very basics now. Gratz on that.
Ok so I was using this script again and when I grabbed if off here and actually tested what I posted I realized just how messed up my checks were. I re-wrote them and updated the npc.
The way it was before, it would check inventory met/db's and account for scroll but it wouldn't actually check while removing stuff.. so lets say you have 21 db's in your inventory (2 scrolls 1 loose) and you try to deposit 19 dbs. It would pass the check cause you DO have enough but instead it would only remove 11 db's and give you the 19 points giving you 8 free dbs.
Not a good thing so I re-wrote it using some more checks. They may not be the prettiest things ever but they work. Also re-added some missing stuff that was organized wrong, mislabeled or just missing from the post.
[Re-Release]Met/Db Bank 07/17/2009 - CO2 PServer Guides & Releases - 3 Replies Did it, this time dbs and mets store seperate.
1. You need to "Design" your Sql table, i dont know a command for this but heres the manual way.
A. Open up Navicat(what i use)
B. Go to the Character table
C. Go to File/ Design Table
D. Click on Add field
E. Name the field Name: MetPoint,Type: int,Lenght: 11,Decimals: 0, Not Null.
F. Add a second one for DbPoint
Put this in NpcTalk.cs(obviously)
Openkore Fields bearbeiten 08/28/2006 - Ragnarok Online - 1 Replies Hallo,
wie die Topic schon sagt gibt es ein Programm womit ich die einzelnen Fields bearbeiten kann?