Jump to content
  • 0

Script to Count cards adquired


KeiGardev

Question


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.01
  • Content Count:  6
  • Reputation:   0
  • Joined:  05/26/24
  • Last Seen:  

Hello I made a Script, the idea is to have a NPC, maybe later a @command , that counts the number of cards that the Player adquired for the first time.
but total cards is always returning 1

I have tried using ("SELECT COUNT(DISTINCT card_id) an then I got -1 


 

prontera,140,174,4	script	Personal storage2#prt	113,{
OnInit:
        // Query of obtained cards
        totalCards = query_sql("SELECT COUNT(*) FROM player_cards WHERE account_id = '" + getcharid(3) + "'");
        // totalCards = query_sql("SELECT COUNT(card_id) FROM player_cards WHERE account_id = '" + getcharid(3) + "'");
        mes "[Card Album]";
        mes "Here, let me open";
        mes "your Card record.";
        mes "You have collected " + totalCards + " cards out of 1009.";
        mes "Thank you for using";
        mes "the Kafra Service.";
        close;
}

(I am using PHPMYADMIN to Run the server locally)this table records when you get a card, the name of the table is player_cards and is together with the other tables of Rathena_DB
it looks like this:
image.png.6679ee150dbf437cbcb009ae4099f48e.png

what I am doing wrong?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   122
  • Joined:  07/11/14
  • Last Seen:  

2 hours ago, KeiGardev said:

Hello I made a Script, the idea is to have a NPC, maybe later a @command , that counts the number of cards that the Player adquired for the first time.
but total cards is always returning 1

I have tried using ("SELECT COUNT(DISTINCT card_id) an then I got -1 


 

prontera,140,174,4	script	Personal storage2#prt	113,{
OnInit:
        // Query of obtained cards
        totalCards = query_sql("SELECT COUNT(*) FROM player_cards WHERE account_id = '" + getcharid(3) + "'");
        // totalCards = query_sql("SELECT COUNT(card_id) FROM player_cards WHERE account_id = '" + getcharid(3) + "'");
        mes "[Card Album]";
        mes "Here, let me open";
        mes "your Card record.";
        mes "You have collected " + totalCards + " cards out of 1009.";
        mes "Thank you for using";
        mes "the Kafra Service.";
        close;
}

(I am using PHPMYADMIN to Run the server locally)this table records when you get a card, the name of the table is player_cards and is together with the other tables of Rathena_DB
it looks like this:
image.png.6679ee150dbf437cbcb009ae4099f48e.png

what I am doing wrong?

 

Let's use in here script_commands.txt example: https://github.com/rathena/rathena/blob/master/doc/script_commands.txt#L9179

you use it like this:

totalCards = query_sql("SELECT COUNT(*) FROM player_cards WHERE account_id = '" + getcharid(3) + "'");

basically totalCards will receive 1 if the query_sql is executed successfully or 0 in case of failure, now the values to which you are doing the SELECT need a scope in which they will always be an array of values, in your case as a sum of all the values in the table referring to the account id, so the array will only have one index with the result, so you would have to do it like this:

prontera,140,174,4	script	Personal storage2#prt	113,{
OnInit:
        // Query of obtained cards
        query_sql("SELECT COUNT(*) FROM player_cards WHERE account_id = '" + getcharid(3) + "'",.@totalCards);
        // totalCards = query_sql("SELECT COUNT(card_id) FROM player_cards WHERE account_id = '" + getcharid(3) + "'");
        mes "[Card Album]";
        mes "Here, let me open";
        mes "your Card record.";
  	//Ex1
        mes "You have collected " + .@totalCards + " cards out of 1009.";
  	//Ex2
        mes "You have collected " + .@totalCards[0] + " cards out of 1009.";
        mes "Thank you for using";
        mes "the Kafra Service.";
        close;
}

Remembering that you cannot use the OnInit label and then use commands that are common to rid (player) without attaching rid (player) as in the case of the "mes","getcharid(3)" and "close" commands, this will cause an error on the stating emulator  that there is no rid attached, I hope you understand what I tried to explain 🙂

  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.01
  • Content Count:  6
  • Reputation:   0
  • Joined:  05/26/24
  • Last Seen:  

1 hour ago, Hyroshima said:

 

Remembering that you cannot use the OnInit label and then use commands that are common to rid (player) without attaching rid (player) as in the case of the "mes","getcharid(3)" and "close" commands, this will cause an error on the stating emulator  that there is no rid attached, I hope you understand what I tried to explain 🙂

Yeah that explains "[Error]: buildin_getcharid: fatal error ! player not attached!" I thought it was unrelated to the NPC haha

I understant now that On Init "speaks" from the NPC Context not the player


Thank You it works
image.png.1322a29aa7f2f54b7e3911b4374e1416.png

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