Jump to content
  • 0

help query_sql syntax


Question

Posted
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

3 answers to this question

Recommended Posts

Posted
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

Posted


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+ "'";

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...