Jump to content
  • 0

Top Rank points #MVP


Kawacito

Question


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

I'm trying to create a code for an NPC to tell me the name of the user with the most #MVP points generated so far, I'm using a points system called #HEROPOINT which goes to an SQL table called acc_reg_num with the following values account_id, key , index and value, what I need is that from that table I take the user (account_id) with the most points (value) and as a result the NPC tells me the NAME OF THE CHAR with the most points and the amount of points I generated to mention it as champion of the event... maybe someone can help me with this issue since I don't understand how to bind the SQL to an NPC

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  65
  • Reputation:   10
  • Joined:  08/02/18
  • Last Seen:  

-	script	JM_MVPTR	FAKE_NPC,{
	
	.@npcname$ = "[ TOP MvP ]";
	query_sql "SELECT name, value, date FROM JM_MVPTR ORDER BY value DESC, date DESC LIMIT 1",.@rpname$,.@value;
  	mes .@npcname$;
	if(.@value){
		mes "Player: "+.@rpname$,
		(.@value>1? "Points ":"Point: ")+.@value;
		close;
	} else {
		mes "There is no top MVP at the moment.";
		close;
	}
	end;
	
	OnInit:
	query_sql "CREATE TABLE IF NOT EXISTS JM_MVPTR (char_name VARCHAR(50) UNIQUE, value FLOAT, date DATETIME)";
	end;
}
prontera,100,100,4	duplicate(JM_MVPTR)	TOP MvP#prt	565

 

I think there's an issue with #HEROPOINT; it belongs to the account, and there are multiple characters in the account. I wrote this script quickly, so it's good to test it as I'm not sure if it will work correctly. The SQL table will be imported automatically once the NPC is added to the game.

Below is what you should add in place of #HEROPOINTS:

.@mkname$ = strcharinfo(0);
query_sql "INSERT INTO JM_MVPTR (name, value, date) VALUES ('"+scape_sql(.@mkname$)+"', 1, NOW()) ON DUPLICATE KEY UPDATE value = value + 1, date = NOW()";

That English was from a correction tool, haha. If you need anything, just let me know

Edited by Mahiro
Duplicates
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

23 hours ago, Mahiro said:

	
	  
	
		 
	  
	
	
	

 

Creo que hay un problema con #HEROPOINT; pertenece a la cuenta y hay varios personajes en la cuenta. Escribí este script rápidamente, así que es bueno probarlo ya que no estoy seguro de si funcionará correctamente. La tabla SQL se importará automáticamente una vez que se agregue el NPC al juego.

A continuación se muestra lo que debe agregar en lugar de #HEROPOINTS:

 

Ese inglés era de una herramienta de corrección, jaja. Si necesitas algo, solo házmelo saber.

 

 

 

The last part is not understood, in my script I have the following:

-    script    MobDeathMvP    -1,{
OnMyMobDead:
    set .i, .Items$[rand(getarraysize(.Items$))];
    set @rand,rand(10,10);
    getitem 11512,3;
    getitem .i,1;
    set #HEROPOINT , #HEROPOINT + 1;

 

 

Right there I must add the points system but I don't know how to add it

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

Just now, Kawacito said:

 

 

 

The last part is not understood, in my script I have the following:

-    script    MobDeathMvP    -1,{
OnMyMobDead:
    set .i, .Items$[rand(getarraysize(.Items$))];
    set @rand,rand(10,10);
    getitem 11512,3;
    getitem .i,1;
    set #HEROPOINT , #HEROPOINT + 1;

 

 

Right there I must add the points system but I don't know how to add it

I did a test, manually add points to the SQL with name and date but the npc keeps telling me that there is no top MVP
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  65
  • Reputation:   10
  • Joined:  08/02/18
  • Last Seen:  

-	script	JM_MVPCP	FAKE_NPC,{
	
	OnNPCKillEvent:
	if(getmonsterinfo(killedrid,MOB_MVPEXP)){
		.@mkname$ = strcharinfo(0);
		query_sql "INSERT INTO JM_MVPTR (name, value, date) VALUES ('"+escape_sql(.@mkname$)+"', 1, NOW()) ON DUPLICATE KEY UPDATE value = value + 1, date = NOW()";
		dispbottom "You gained 1 point for killing an MvP.";
	}
	end;
}
-	script	JM_MVPTR	FAKE_NPC,{
	
	.@npcname$ = "[ TOP MvP ]";
	query_sql "SELECT name, value FROM JM_MVPTR ORDER BY value DESC, date DESC LIMIT 1",.@rpname$,.@value;
	mes .@npcname$,
	" ";
	if(.@value){
		mes "Player: "+.@rpname$,
		(.@value>1? "Points: ":"Point: ")+.@value;
		close;
	} else {
		mes "There is no top MVP at the moment.";
		close;
	}
	end;
	
	OnInit:
	query_sql "CREATE TABLE IF NOT EXISTS JM_MVPTR (char_name VARCHAR(50) UNIQUE, value FLOAT, date DATETIME)";
	end;
}
prontera,100,100,4	duplicate(JM_MVPTR)	TOP MvP#prt	565

Remove everything I asked you to add and add the one above.

See if it works correctly.

Try using smaller text fonts here in rAthena. It doesn't look good on my screen.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

Just now, Mahiro said:
-	script	JM_MVPCP	FAKE_NPC,{
	
	OnNPCKillEvent:
	if(getmonsterinfo(killedrid,MOB_MVPEXP)){
		.@mkname$ = strcharinfo(0);
		query_sql "INSERT INTO JM_MVPTR (name, value, date) VALUES ('"+escape_sql(.@mkname$)+"', 1, NOW()) ON DUPLICATE KEY UPDATE value = value + 1, date = NOW()";
		dispbottom "You gained 1 point for killing an MvP.";
	}
	end;
}
-	script	JM_MVPTR	FAKE_NPC,{
	
	.@npcname$ = "[ TOP MvP ]";
	query_sql "SELECT name, value FROM JM_MVPTR ORDER BY value DESC, date DESC LIMIT 1",.@rpname$,.@value;
	mes .@npcname$,
	" ";
	if(.@value){
		mes "Player: "+.@rpname$,
		(.@value>1? "Points: ":"Point: ")+.@value;
		close;
	} else {
		mes "There is no top MVP at the moment.";
		close;
	}
	end;
	
	OnInit:
	query_sql "CREATE TABLE IF NOT EXISTS JM_MVPTR (char_name VARCHAR(50) UNIQUE, value FLOAT, date DATETIME)";
	end;
}
prontera,100,100,4	duplicate(JM_MVPTR)	TOP MvP#prt	565

Remove everything I asked you to add and add the one above.

See if it works correctly.

Try using smaller text fonts here in rAthena. It doesn't look good on my screen.

ready now if it works perfectly, a small detail for everyone to know in the insert part says: instead name replace by char_name since when creating the tables it is created as char_name and not as name, other than that it works perfectly!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

8 hours ago, Kawacito said:

 

I have a small question, the event is held every 2 hours, how do I reset the points each time the event is entered?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  65
  • Reputation:   10
  • Joined:  08/02/18
  • Last Seen:  

13 hours ago, Kawacito said:

ready now if it works perfectly, a small detail for everyone to know in the insert part says: instead name replace by char_name since when creating the tables it is created as char_name and not as name, other than that it works perfectly!

Strange.

Search for:

query_sql "INSERT INTO JM_MVPTR (name, value, date) VALUES ('"+escape_sql(.@mkname$)+"', 1, NOW()) ON DUPLICATE KEY UPDATE value = value + 1, date = NOW()";

And replace it with:

query_sql "INSERT INTO JM_MVPTR (char_name, value, date) VALUES ('"+escape_sql(.@mkname$)+"', 1, NOW()) ON DUPLICATE KEY UPDATE value = value + 1, date = NOW()";

 

1 hour ago, Kawacito said:

I have a small question, the event is held every 2 hours, how do I reset the points each time the event is entered?

I thought you wanted a new script. You would have to send your complete script to understand.
the one I sent you just counts kills on Boss type monsters everywhere in the game, and inserts the information in SQL to a query on the npc you specified to me, apparently you need it to be counting only in one event. Upload your complete script.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

Just now, Mahiro said:

Extraño.

Buscar:

Y reemplazarlo con:

 

Pensé que querías un nuevo guión. Tendrías que enviar tu guión completo para entender.
el que te envié solo cuenta las muertes de los monstruos tipo Boss en todas partes del juego, e inserta la información en SQL en una consulta sobre el npc que me especificaste, aparentemente necesitas que cuente solo en un evento. Sube tu guión completo.

If in any case I managed to create what I needed with that information, now I only have the part where I can only deliver the prize to the champion user of that event and that he can claim it only once until the event is generated again, which is every 2 hours

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

Just now, Kawacito said:

Si en todo caso logré crear lo que necesitaba con esa información, ahora solo me queda la parte donde solo puedo entregar el premio al usuario campeón de ese evento y que lo puede reclamar solo una vez hasta que se genere nuevamente el evento, que es cada 2 horas

It would be something like the following:


            .@mkname$ = strcharinfo(0);
            query_sql "SELECT * FROM JM_MVPTR WHERE char_name = .@mkname$",.@charname;
    
            if(.@charname != .@mkname$){ mes" Tu no eres el campeon de HERO."; close;
            } else {
             mes"toma toma tu premio";
            getitem 40300,1;
             close;    



but that does not work for me, I must also add that I can only request it 1 time for each event that takes place every 2 hours

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

Ready I solved it, then I leave my own solution!

 

 

 

-    script    Hero_c    -1,{
OnInit:

    bindatcmd "campeon", strnpcinfo(0)+"::OnCampeon",60,60;
    
OnCampeon:

    query_sql "SELECT char_name, value, date FROM JM_MVPTR ORDER BY value DESC, date DESC LIMIT 1",.@rpname$,.@value;
  
    if(.@value){
        mes "[HERO MVP]";
        mes "El campeon de Hero es "+.@rpname$+" con un total de "+.@value+" Puntos";
        switch(select("Reclamar Premio:Cancelar")){
        
        case 1:
            .@mkname$ = strcharinfo(0);
    
            if(.@rpname$ != .@rpname$){
            mes" Tu no eres el campeon de HERO."; 
            close;
            }
             else 
            {

            if ( #CAMPEON >= 1 ) {
            mes "Lo siento pero tu ya reclamaste el el permio del Campeon";
            close;
            }
            mes"toma toma tu premio";
            getitem 40300,1;
            set #CAMPEON , #CAMPEON + 1;
             close;    

        case 2:
            mes "Ok, nos vemos";
            close;
    }
        
}
}

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.01
  • Content Count:  33
  • Reputation:   2
  • Joined:  04/16/21
  • Last Seen:  

 

Now I have a question, how would I make it show me the first 5 users in descending order?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  65
  • Reputation:   10
  • Joined:  08/02/18
  • Last Seen:  

If it works the way you want, great.

To reset it, just make sure that when starting the event it uses this here:

query_sql "SELECT value FROM acc_reg_num WHERE key = '#CAMPEON'",.@hcv;
if(.@hcv)
	query_sql "DELETE FROM acc_reg_num WHERE key = '#CAMPEON'";

 

3 hours ago, Kawacito said:

 

Now I have a question, how would I make it show me the first 5 users in descending order?

Here:

-	script	HERO_C	-1,{
	
	OnCampeon:
    query_sql "SELECT char_name, value FROM JM_MVPTR ORDER BY value DESC, date DESC LIMIT 5",.@rpname$,.@value;
	
	.@npcname$ = "[ HERO MVP ]";
	mes .@npcname$;
	if(.@value){
        mes "El campeon de Hero es "+.@rpname$+" con un total de "+.@value+" Puntos";
        switch(select("Reclamar Premio:TOP 5:Cancelar")){
			clear;
			mes .@npcname$;
			case 1:
			.@mkname$ = strcharinfo(0);
			if(.@rpname$ != .@rpname$){
				mes" Tu no eres el campeon de HERO."; 
				close;
			} else {
				if(#CAMPEON){
					mes "Lo siento pero tu ya reclamaste el el permio del Campeon";
					close;
				}
				mes"toma toma tu premio";
				getitem 40300,1;
				set #CAMPEON , #CAMPEON + 1;
				close;
			}
			
			case 2:
			if(!.@value){
				mes "Not ranking at moment";
				close;
			}
			mes " ";
			for(.@i=0;.@i<getarraysize(.@value);.@i++)
				mes (.@i+1)+"°/ "+.@rpname$[.@i]+", "+.@value[.@i]+"";
			close;
			
			case 3:
			mes "Ok, nos vemos";
            close;
		}
	}
	end;
	
	OnInit:
    bindatcmd "campeon", strnpcinfo(0)+"::OnCampeon",60,60;
	end;
}

I have not tested.

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