Jump to content
Sign in to follow this  
sbk_

[Script] getcharname

Recommended Posts

Well, I was developing script for a Brazilian community, I came across a way not to find an appropriate command to get the name of the player in a fast and effective.
 
This method would be the id of the character, I made a simple formula that may be usable to be implemented in the project.
 
would be:
 
BUILDIN(getcharname) {        TBL_PC *sd = NULL;	int char_id = script_getnum(st, 2);	sd = map->charid2sd(char_id);	if( sd == NULL )		script_pushint(st, 0);	else			script_pushstrcopy(st, sd->status.name);	return true;}
Thus do not need a sql query or something to get a simple name of a character.
 
Well, this is my suggestion.
 
Sorry google translator.
Edited by SoulBlaker

Share this post


Link to post
Share on other sites

maybe ppl will ask why implement this when we got strcharinfo, right? the answer is: retrieve name from an offline character by its ID without the need of a query, I agree with that implementation.

Share this post


Link to post
Share on other sites

A suggestion,instead of pushing 0 , maybe push null, so that there's no confusion.

Edited by Dastgir Pojee

Share this post


Link to post
Share on other sites

maybe ppl will ask why implement this when we got strcharinfo, right? the answer is: retrieve name from an offline character by its ID without the need of a query, I agree with that implementation.

exactly, get quickly and effectively.

 

 

A suggestion,instead of pushing 0 , maybe push null, so that there's no confusion.

 

both solve the problem, more's there.

Share this post


Link to post
Share on other sites

to my understanding charid2sd doesn't get the name of offline characters, it looks up the charid list for online characters

Share this post


Link to post
Share on other sites

maybe ppl will ask why implement this when we got strcharinfo, right? the answer is: retrieve name from an offline character by its ID without the need of a query, I agree with that implementation.

 

You will always have to query the DB for offline characters if you don't have an id->name cache somewhere.

 

edit: Then you'd have to ask yourself why make something like that vs querying the DB?

Edited by SketchyPhoenix

Share this post


Link to post
Share on other sites

 

maybe ppl will ask why implement this when we got strcharinfo, right? the answer is: retrieve name from an offline character by its ID without the need of a query, I agree with that implementation.

 

You will always have to query the DB for offline characters if you don't have an id->name cache somewhere.

 

edit: Then you'd have to ask yourself why make something like that vs querying the DB?

 

getcharid(<type>{,"<character name>"})

 

:P

Share this post


Link to post
Share on other sites

to my understanding charid2sd doesn't get the name of offline characters, it looks up the charid list for online characters

Well, there must be another way, even making an adaptation of strcharinfo which has more interesting information.

 

 

 

maybe ppl will ask why implement this when we got strcharinfo, right? the answer is: retrieve name from an offline character by its ID without the need of a query, I agree with that implementation.

 

You will always have to query the DB for offline characters if you don't have an id->name cache somewhere.

 

edit: Then you'd have to ask yourself why make something like that vs querying the DB?

This would be to avoid more complex queries to the database character.

 

 

 

 

maybe ppl will ask why implement this when we got strcharinfo, right? the answer is: retrieve name from an offline character by its ID without the need of a query, I agree with that implementation.

 

You will always have to query the DB for offline characters if you don't have an id->name cache somewhere.

 

edit: Then you'd have to ask yourself why make something like that vs querying the DB?

 

getcharid(<type>{,"<character name>"})

 

:P

Exactly, that solves these kinds of problems, but it would be easier to work with ID.

 

@Off

Well it was a suggestion, but I totally understand if you think you do not need.

Share this post


Link to post
Share on other sites

Not sure what I'd use it for but here's a script function version of it lol:

 

 

/*****************************************************************************************getcharname()******************************************************************************************Description:Return player's name by ID query.******************************************************************************************Usage:mes "The first person on this server was named "+ getcharname(150000) +".";*****************************************************************************************/function    script    getcharname    {    query_sql("SELECT `name` FROM `char` WHERE `char_id` = '"+ getarg(0) +"'", .@query_name$);    return .@query_name$;}

Share this post


Link to post
Share on other sites

 

 

maybe ppl will ask why implement this when we got strcharinfo, right? the answer is: retrieve name from an offline character by its ID without the need of a query, I agree with that implementation.

 

You will always have to query the DB for offline characters if you don't have an id->name cache somewhere.

 

edit: Then you'd have to ask yourself why make something like that vs querying the DB?

 

getcharid(<type>{,"<character name>"})

 

:P

it would be nice if hercules have time to add the optional char name/id parameter to these script command....it would be very useful .... 

 

last time we have a short discussion for adding these optional parameter....but somehow the developer are busy and have no time to start it i guess...

Share this post


Link to post
Share on other sites

 

Not sure what I'd use it for but here's a script function version of it lol:

 

 

/*****************************************************************************************getcharname()******************************************************************************************Description:Return player's name by ID query.******************************************************************************************Usage:mes "The first person on this server was named "+ getcharname(150000) +".";*****************************************************************************************/function    script    getcharname    {    query_sql("SELECT `name` FROM `char` WHERE `char_id` = '"+ getarg(0) +"'", .@query_name$);    return .@query_name$;}

 

 

 

 

maybe ppl will ask why implement this when we got strcharinfo, right? the answer is: retrieve name from an offline character by its ID without the need of a query, I agree with that implementation.

 

You will always have to query the DB for offline characters if you don't have an id->name cache somewhere.

 

edit: Then you'd have to ask yourself why make something like that vs querying the DB?

 

getcharid(<type>{,"<character name>"})

 

:P

it would be nice if hercules have time to add the optional char name/id parameter to these script command....it would be very useful .... 

 

last time we have a short discussion for adding these optional parameter....but somehow the developer are busy and have no time to start it i guess...

 

Saw interesting, started with an idea and has generated other matters interesting, let's see if the optional parameter giving more freedom act, the work would be spared and new ideas emerged, the topic can be good to finally here, the more that these two friends told the term is more practical to apply.
 
Thanks for understanding,

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.