RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Adding An Account Tag

Broadside

Wanderer
Adding An Account Tag

This is originally written by Jeoku I am just posting it here at his request and i think it is a good thing to have out for it helped me out. ;)

Alright, I'm going to go through this step by step...

1. Define your Account instance...
Code:
Account myAccount = ( mob.Account as Account );

Where "mob" is an instance of a mobile, this is how you define its account as "myAccount". You HAVE to cast "mob.Account" as an "Account" type, otherwise it'll give you an error.

2. Create a tag on "myAccount"...
Code:
myAccount.SetTag( "Name", "Content" );

This function, unlike Account.AddTag, checks to see whether or not a tag with "Name" already exists (and modifies it if it does, rather than duplicating it). "Name" is what you use to find the tag when you want to retrieve your information, and "Content" is the string of information that you can store. Of course you can replace "Name" and "Content" with what you want.

3. Read a tag on "myAccount"...
Code:
string myString = myAccount.GetTag( "Name" );

Now, if a tag named "Name" has already been added to this account, myString will return its content (in the above case, "Content"). If this tag does not exist, it will return -null-.

4. Remove a tag on "myAccount"...
Code:
myAccount.RemoveTag( "Name" );

This removes ALL tags named "Name" from "myAccount". If you used
"myAccount.AddTag(...)" (multiple times) instead of "myAccount.SetTag(...)", it will remove every single instance of an account tag named "Name".

5. Utilizing an AccountTag...
Code:
Account myAccount = ( mob.Account as Account ); 
 
myAccount.SetTag( "Tag!", "This is the tag." ); 
mob.SendMessage( "myAccount.SetTag( 'Tag!', 'This is the tag.' );" ); 
 
string myString = myAccount.GetTag( "Tag!" ); 
mob.SendMessage( "string myString = myAccount.GetTag( 'Tag!' );" ); 
 
if( myString != null ) 
      mob.SendMessage( "myString == {0}", myString ); 
else 
      mob.SendMessage( "myString == null" ); 
 
myAccount.RemoveTag( "Tag!" ); 
mob.SendMessage( "myAccount.RemoveTag( 'Tag!' );" ); 
 
myString = myAccount.GetTag( "Tag!" ); 
mob.SendMessage( "myString = myAccount.GetTag( 'Tag!' );" ); 
 
if( myString != null ) 
      mob.SendMessage( "myString == {0}", myString ); 
else 
      mob.SendMessage( "myString == null" );

You can put this into a simple script (when you doubleclick on a custom item, perhaps) and see what it outputs (where "mob" is you).
 
Top