sbk_ 30 Posted October 17, 2013 (edited) 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 October 17, 2013 by SoulBlaker 2 JulioCF and evilpuncker reacted to this Quote Share this post Link to post Share on other sites
evilpuncker 503 Posted October 17, 2013 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. Quote Share this post Link to post Share on other sites
Dastgir 1246 Posted October 17, 2013 (edited) A suggestion,instead of pushing 0 , maybe push null, so that there's no confusion. Edited October 17, 2013 by Dastgir Pojee Quote Share this post Link to post Share on other sites
sbk_ 30 Posted October 17, 2013 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. Quote Share this post Link to post Share on other sites
Ind 945 Posted October 18, 2013 to my understanding charid2sd doesn't get the name of offline characters, it looks up the charid list for online characters Quote Share this post Link to post Share on other sites
sketchyphoenix 15 Posted October 19, 2013 (edited) 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 October 19, 2013 by SketchyPhoenix Quote Share this post Link to post Share on other sites
evilpuncker 503 Posted October 19, 2013 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>"}) Quote Share this post Link to post Share on other sites
sbk_ 30 Posted October 19, 2013 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>"}) 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. Quote Share this post Link to post Share on other sites
Mumbles 193 Posted October 20, 2013 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$;} Quote Share this post Link to post Share on other sites
Emistry 145 Posted October 20, 2013 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>"}) 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... Quote Share this post Link to post Share on other sites
sbk_ 30 Posted October 22, 2013 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>"}) 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, Quote Share this post Link to post Share on other sites