Jump to content
  • 0

rid2name with char_id


Nameless2you

Question


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  351
  • Reputation:   52
  • Joined:  11/15/11
  • Last Seen:  

As title indicates, anybody have any idea how to do this?

I used a sql query but that resulted in giving me only 1 results, and killed the purpose of my script cause it was a ladder and only showed the first person ><

sample of how I tried it and only got 1 char

query_sql "SELECT `char_id`,`name` FROM `char` WHERE `char_id` = "+.@charid, .@charidd, .@name$;

.@charid is already provided earlier on in the script without a problem, if it wasn't for this, the script would nicely display a bunch of char id's but no names which is my problem.

Edited by Nameless2you
Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  69
  • Topics Per Day:  0.02
  • Content Count:  1315
  • Reputation:   372
  • Joined:  12/10/11
  • Last Seen:  

I don't know much about SQL but your syntax looks wrong.

*query_sql "your MySQL query", <array variable> {,<array variable>, ...};
*query_logsql "your MySQL query", <array variable> {,<array variable>, ...};

Puts up to 128 rows of values into the arrays and returns the number of rows.

Example:
set @nb, query_sql("select name,fame from `char` ORDER BY fame DESC LIMIT 5", @name$, @fame);
mes "Hall Of Fame: TOP5";
mes "1."+@name$[0]+"("+@fame[0]+")"; // Will return a person with the biggest fame value.
mes "2."+@name$[1]+"("+@fame[1]+")";
mes "3."+@name$[2]+"("+@fame[2]+")";
mes "4."+@name$[3]+"("+@fame[3]+")";
mes "5."+@name$[4]+"("+@fame[4]+")";

Note: In the TXT version it doesn't fill the array and always return -1.
Note: Use $ as suffix in the array to receive all data as text.
Note: The difference between query_sql and query_logsql is that the latter
uses the sql connection to the log database, and should be used when you want
to query the server log tables.

https://rathena.svn.sourceforge.net/svnroot/rathena/trunk/doc/script_commands.txt

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

 WHERE `char_id` = 

^ this implicitly limits it to only returning 1 row, because char_id are unique,

so for 1 char_id you will get 1 name.

This example will create a new function that looks up char_id --> name:

prontera,155,188,0	script	GuildLevel50	910,{
function charid2name;
mes "char_id: 150000";
mes "name: " + charid2name(150000);
close;


function charid2name {
	if (query_sql("SELECT `name` FROM `char` WHERE `char_id`="+getarg(0), .@name$) == 1)
		return .@name$;
	else
		return "null";
}
}

What does your ladder script look like? maybe we could write a SQL query to directly fetch the Top 10 names as an array.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  351
  • Reputation:   52
  • Joined:  11/15/11
  • Last Seen:  

Got it fixed, but thanks.

I had 2 query's so I just made it into 1, I had trouble with that thought but then got the bright idea of using

SELECT global_reg_value.char,global_reg_value.str,global_reg_value.value

and so on that did the trick that way I was able to use the tables of `char` and `global_reg_value`. Now I just have to dump everything into a new query because I don't want my test server to lag or potential other users when using it as it's fetching all out of global reg values >.<

@Arcenciel it works just fine the way I scripted it with results.

I might show the finished product later

Link to comment
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
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

×
×
  • Create New...