Database + Conversions

Database + Conversions

Postby Warren1001 » 04 May 2013, 14:18

How would you convert the colors in Database to the code, such as black to %0
I want meh command to have the person's color when I use it.
Also, if they were to have no color at all, how could you define them to use a certain color? :3
Example:
Code: Select all
                        Player.SendMessage(p, string.Format("%c{0}. {1}{2} has {3} money.", (object)(count.ToString()), (object)dataTable.Rows[index]["color"].ToString(), (object)dataTable.Rows[index]["Name"].ToString(), (object)(money.ToString())));
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: Database + Conversions

Postby ismellike » 04 May 2013, 15:00

Oh man, I can probably get that, but im not home right now.

I will post it when I do get home though, thats a nice idea.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Database + Conversions

Postby Warren1001 » 04 May 2013, 16:28

Awesome, and one more thing, I notice users with emails, their emails pop up, how to hide it? :3
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: Database + Conversions

Postby dzienny » 22 May 2013, 10:41

If you want to convert %0 to Black etc. you should create a method that will do it.
Code: Select all
public static string GetColorName(string code)
{
   switch(code)
   {
      case "%0":
      case "&0":
         return "Black";
      case "%1":
      case "&1":
         return "Dark Blue";
      ...
      default:
         throw new ArgumentException("Unknown color code", "code");
   }
}


Replace (...) with the remaining cases and then you can use this method.

If you want to hide the domain of the email address there's a method for this already. It's Player.RemoveEmailDomain(string name) , if the name is an email it returns the name without a domain, otherwise it returns the same string.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron