getcharname()

There is a existing command for this?

Code:
rid2name(getcharid(3));
 
There is a existing command for this?

rid2name(getcharid(3));
rid2name() will only return the name of an online character, using their RID; additionally, the character name may not be produced properly, since the RID for a player is the account ID. getcharname() queries the `char` table for the name of the specified character ID, regardless of whether or not they are online. I've purposefully released an Account Remover utility simultaneously to demonstrate how this function may be used efficiently.

Here's an excerpt in which getcharname() is used to list all character names on an account:

mes .npc_name$; switch (@menu) { case 1: // View list of characters if (query_sql("SELECT `char_id` FROM `char` WHERE `account_id` = '"+ .@account_id +"' ORDER BY `name` ASC", .@char_id[0])) { mes "List of characters:"; for (.@i = 0; .@i < getarraysize(.@char_id); .@i++) { mes "- ^0000FF"+ getcharname(.@char_id[.@i]) +"^000000"; } } else { mes "There are no characters on this account."; } next; break;

Documentation for rid2name() can be found in doc/script_commands.txt.

 
Last edited by a moderator:
Since you brought up the list of characters thing as an example. Supposed to be i would like to get all the character name of all characters on my server. Your function would only get the first 128 values ( 128 character names supposed to be ). A suggestion from me that you might want to add into your function is to support > 128 values. That will make your function more flexible and more awesome. Anyway good job!
default_tongue.png


 
@Mumbles

Question: What if for example, the character deletion is still ongoing, but suddenly someone logins that same account, what will happen then?

default_smile.png


 
Last edited by a moderator:
Since you brought up the list of characters thing as an example. Supposed to be i would like to get all the character name of all characters on my server. Your function would only get the first 128 values ( 128 character names supposed to be ). A suggestion from me that you might want to add into your function is to support > 128 values. That will make your function more flexible and more awesome. Anyway good job! 
default_tongue.png
The only purpose of getcharname() is to return a single character's name, by querying the database with an ID; the example above that returns all character names of the account being invoked uses an array filled by query_sql(), which may multiple results. This limitation is not exclusive to getcharname(), as any array filled in any manner (currently) can only store 128 values. It is my understanding that the limitation on arrays may soon be lifted, though it is up to our core developers or other contributors to do so; I wouldn't know where to begin.

@Mumbles

Question: What if for example, the character deletion is still ongoing, but suddenly someone logins that same account, what will happen then?

default_smile.png
If you're deleting an account, I recommend you ban the account prior to doing so; if the system hosting your database has at least 512MB RAM, the deletion process should only take a second (if not less). Despite this, a check is made to ensure that the account is not logged in when the invoking user chooses to confirm removal.

This check can be found on lines 80-86:

Code:
						case 3:	// Confirm removal							if (isloggedin(.@account_id)) {								mes "All characters from this account must be offline before proceeding.";								next;																break;							}
 
Last edited by a moderator:
That's why i use might
default_smile.png
it's up to you though
default_tongue.png


 
Update (for Patskie, really):

  • As of 82b583b, array sizes are virtually limitless.

 
Last edited by a moderator:
Back
Top