Jump to content
  • 0

help query_sql syntax


BuLaLaKaW

Question


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  125
  • Reputation:   7
  • Joined:  11/19/11
  • Last Seen:  

Hi!

 

Requesting help on how to implement these lines.

 

1. Check the player account id who is online on a specific map on the char sql table.

Main goal is to get the value of @acct_id (single and multiple results)

 



set @last_map$, "prontera";
query_sql "SELECT account_id FROM char WHERE last_map = "+@last_map$+" AND online = 1",@acct_id;


 

 

2. Update last location of a character

Main goal is to update char sql table and make sure last_map is updated in this command

 



set @char_id, strcharinfo(0);
set @last_map$, "prontera";
query_sql "UPDATE char SET last_map = "+@last_map$+" WHERE char_id = "+@char_id+"";


 

 

Thanks

Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  135
  • Reputation:   41
  • Joined:  02/05/14
  • Last Seen:  

set @last_map$, "prontera";
query_sql "SELECT account_id FROM char WHERE last_map = "+@last_map$+" AND online = 1",@acct_id;

 

You'd probably be better of using a temporary NPC variable (.@last_map$), since it doesn't seem like you'll need that data exclusive to the attached player; same goes for where you're storing the account IDs (.@acct_id).

 

set @char_id, strcharinfo(0);
set @last_map$, "prontera"; 
query_sql "UPDATE char SET last_map = "+@last_map$+" WHERE char_id = "+@char_id+"";

This will cause your script to error, as you're trying to store a string (strcharinfo(0), which will return the player's name as a string) as a numerical value for @char_id (again, probably better off as a temporary NPC variable, .@char_id); from what I gather, you intend to retrieve the player's character ID, which can be done with getcharid(0). Additionally, your SQL query will fail, because the table char needs to be enclosed in backticks (`char`); char is a reserved keyword and will not execute correctly if not enclosed properly.

 

In regards to your script, it just seems like you're trying to force-update a player's last map, which may actually be overwritten when the char-server saves again. o_o

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  


set .@last_map$, "prontera";

query_sql "SELECT DISTINCT(`account_id`) FROM `char` WHERE `last_map` = '" +escape_sql(.@last_map$)+ "' AND `online` = '1'",.@acct_id;

/* Single Result */

mes "Account ID : " +.@acct_id;

/* Multiple Results */

for ( .@i = 0; .@i < getarraysize(.@acct_id); .@i++ )

mes "Account ID : " +.@acct_id[.@i];

-----------------------------------------------------------------------------------------------------------

set .@char_id, getcharid(0);

set .@last_map$, "prontera";

query_sql "UPDATE `char` SET `last_map` = '" +escape_sql(.@last_map$)+ "' WHERE `char_id` = '" +.@char_id+ "'";

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...