Jump to content
  • 0

Blacksmith/Alchemist NPC Ranker


WhiteEagle

Question


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  461
  • Reputation:   61
  • Joined:  08/28/12
  • Last Seen:  

Hi guys,

know anyone how to script a npc, which display

the /blacksmith and /alchemist ranking.

Because I want give the first 3 ppls a bonus effect.

Like:

if (blacksmithrank == 3) {

He got a luck bonus of 3

}

if (blacksmithrank == 2) {

He got a luck bonus of 4

}

if (blacksmithrank == 1) {

He got a luck bonus of 5

}

Thanks in advance.

Link to comment
Share on other sites

13 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

That's not too hard, all the information needed is stored in the sale files if I'm not mistaken. The only tricky part is giving them the bonus indefinitely. But this is only because rA's current script engine will make those bonus reset upon adding stats. But thankfully we have freeloop() command.

So we can just do: freeloop(bonus bLuk, 3;);

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  461
  • Reputation:   61
  • Joined:  08/28/12
  • Last Seen:  

Thanks for your answer.

Thats help me much. But the question is, how I can do that the npc

display the ranking.

Example:

if (blacksmithrank == 3) {

I don't know the value to check this.

Sorry for my questions. x_X

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

Well, at my I'm at work, so I can't really go looking through my sql files. But, there is a database which stores ranking information.

So try and run a sql query for the information and store it like that.

eg: query_sql( "SELECT * FROM 'table' ORDER BY DESC LIMIT='3'",.@char_id,.@ranking);

Something like that, I'd be able to help more when I get home.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  461
  • Reputation:   61
  • Joined:  08/28/12
  • Last Seen:  

query_sql( "SELECT * FROM 'table' ORDER BY DESC LIMIT='3'",.@char_id,.@ranking);

Something like this I searching, but nothing found.

Many thanks that you try to help me.

I hope you find a solution.

Link to comment
Share on other sites


  • Group:  Development Manager
  • Topic Count:  56
  • Topics Per Day:  0.01
  • Content Count:  732
  • Reputation:   525
  • Joined:  12/13/11
  • Last Seen:  

// Blacksmith ranking list
query_sql "SELECT `fame`,`name` FROM `char` WHERE `fame`>0 AND (`class`='10' OR `class`='4011' OR `class`='4033' OR `class`='4058' OR `class`='4064' OR `class`='4100') ORDER BY `fame` DESC LIMIT 0,3", .@fame, .@name);
for( set .@i,0; .@i < 3; set .@i,.@i + 1 )
{
   mes "Top 3 Blacksmiths";
   mes .@i + 1 + ". " + .@name + " with fame of: " + .@fame + ".";
}

// Alchemist ranking list
query_sql "SELECT `fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='18' OR `class`='4019' OR `class`='4041' OR `class`='4071' OR `class`='4078' OR `class`='4107') ORDER BY `fame` DESC LIMIT 0,3", .@fame, .@name);
for( set .@i,0; .@i < 3; set .@i,.@i + 1 )
{
   mes "Top 3 Blacksmiths";
   mes .@i + 1 + ". " + .@name + " with fame of: " + .@fame + ".";
}

That prints out the top 3 Blacksmith and Alchemist classes from the fame list. You can do whatever you want with it from there. The two important parts are the queries.

Edited by Aleos
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  461
  • Reputation:   61
  • Joined:  08/28/12
  • Last Seen:  

Wow nice. Thank you.

I have test it now and added some own changes that it work. (.@name$ and .@fame$)

algaia,205,161,4 script Test Rank 100,{

mes "[Ranker]";
mes "Which ranking you want to see?";
next;
switch(select("Blacksmith:Alchemist")){
case 1:
query_sql "SELECT `fame`,`name` FROM `char` WHERE `fame`>0 AND (`class`='10' OR `class`='4011' OR `class`='4033' OR `class`='4058' OR `class`='4064' OR `class`='4100') ORDER BY `fame` DESC LIMIT 0,3", .@fame$, .@name$;
for( set .@i,0; .@i < 3; set .@i,.@i + 1 ) {

mes "=======================";
mes "Top 1 Blacksmith";
mes .@i + 1 + ". " + .@name$ + " with fame of: " + .@fame$ + ".";
mes "=======================";
mes "Top 2 Blacksmith";
mes .@i + 1 + ". " + .@name$ + " with fame of: " + .@fame$ + ".";
mes "=======================";
mes "Top 3 Blacksmith";
mes .@i + 1 + ". " + .@name$ + " with fame of: " + .@fame$ + ".";
mes "=======================";
close;
}

My problem is now, only one person will be displayed.

2s6ugpi.png

Edited by WhiteEagle
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

That's because, those variables, are not just regular vars, they are arrays.

for( set .@i,0; .@i<3; set .@i,.@i+1){
mes "=======================";
mes "Top "+ ( .@i + 1 ) +" Blacksmith";
mes ( .@i + 1 ) +". "+ .@name$[.@i] +" with fame of: "+ .@fame$[.@i] +".";
mes "=======================";}
close;

Edit: Also, i could have sworn, ' fame ' was stored as an integer in the sql_db. So, I really don't think you need to have stored into a str_variable.

So, your sql_query should look like this:

query_sql "SELECT `fame`,`name` FROM `char` WHERE `fame`>0 AND (`class`='10' OR `class`='4011' OR `class`='4033' OR `class`='4058' OR `class`='4064' OR `class`='4100') ORDER BY `fame` DESC LIMIT 0,3", .fame, .name$;

The reason, i used .variables, is because you also said you wanted to give these players a bonus of 3 luk or w/e. So we'd need to be able to get this information. a .@scope variable, would dissapear as soon as the script ended.

For getting the bonuses, i suggest, you use the NPC to do it, for a set time, such as give the stats to those who are #1-3 for 1day, then check for the new people lol.

OnInit: //Just let it run to the next label =P
donpcevent "npcname::OnFameLoop";
OnClock0000:
query_sql "SELECT `fame`,`name` FROM `char` WHERE `fame`>0 AND (`class`='10' OR `class`='4011' OR `class`='4033' OR `class`='4058' OR `class`='4064' OR `class`='4100') ORDER BY `fame` DESC LIMIT 0,3", .fame, .name$;
end;
OnFameLoop:
freeloop(1);
while(1){
if( attachrid( getcharid(3, .name$[0]) ){ bonus bLuk,3; detachrid;}
if( attachrid( getcharid(3, .name$[1]) ){ bonus bLuk,3; detachrid;}
if( attachrid( getcharid(3, .name$[2]) ){ bonus bLuk,3; detachrid;}
}
end;

In regards to the looping for bonuses, yea, it's pretty bad, i know, but unless you use a src edit (which is already out: Extra Bonuses), almost all scripts like this are gonna be costly.

Edited by GmOcean
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  461
  • Reputation:   61
  • Joined:  08/28/12
  • Last Seen:  

It work perfectly. Thank you and thanks at all.

I will try now, to add the first 3 ppls the "freeloop(bonus bLuk, 3;);" bonus

per "OnPCLoginEvent:"

Link to comment
Share on other sites


  • Group:  Development Manager
  • Topic Count:  56
  • Topics Per Day:  0.01
  • Content Count:  732
  • Reputation:   525
  • Joined:  12/13/11
  • Last Seen:  

Sorry, glad you got it going.

I've been messing with PHP all day and switched over to eA NPC script and forgot some stuff. :P

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  461
  • Reputation:   61
  • Joined:  08/28/12
  • Last Seen:  

@Aleos Thanks.

I changed it now like this:

algaia,205,161,4 script Test Rank 100,{

mes "[blacksmith Ranking]";
query_sql "SELECT `fame`,`name` FROM `char` WHERE `fame`>0 AND (`class`='10' OR `class`='4011' OR `class`='4033' OR `class`='4058' OR `class`='4064' OR `class`='4100') ORDER BY `fame` DESC LIMIT 0,1", .@fame$, .@name$;
query_sql "SELECT `fame`,`name` FROM `char` WHERE `fame`>0 AND (`class`='10' OR `class`='4011' OR `class`='4033' OR `class`='4058' OR `class`='4064' OR `class`='4100') ORDER BY `fame` DESC LIMIT 1,2", .@fame2$, .@name2$;
query_sql "SELECT `fame`,`name` FROM `char` WHERE `fame`>0 AND (`class`='10' OR `class`='4011' OR `class`='4033' OR `class`='4058' OR `class`='4064' OR `class`='4100') ORDER BY `fame` DESC LIMIT 2,3", .@fame3$, .@name3$;
mes "=======================";
mes "Top 1 Blacksmith";
mes ""+ .@name$ +" with fame of: "+ .@fame$ +".";
set rank,1;
mes "=======================";
mes "Top 2 Blacksmith";
mes ""+ .@name2$ +" with fame of: "+ .@fame2$ +".";
set rank,2;
mes "=======================";
mes "Top 3 Blacksmith";
mes ""+ .@name3$ +" with fame of: "+ .@fame3$ +".";
mes "=======================";
set rank,3;
close;

OnPCLoginEvent:
if(rank == 1){
atcommand "@aura 701";
dispbottom "You are on the first place.";
}
if(rank == 2){
atcommand "@aura 701";
dispbottom "You are on the second place.";
}
if(rank == 3){
atcommand "@aura 701";
dispbottom "You are on the third place.";
}
end;
}

My problem is now, how to set

set rank,1; , set rank,2; and set rank,3;

each ppls without talking the npc.

If I speak with the npc, I get the set rank,3;

I need it to get automatic. X_X

Sry for my english.

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

try this..

http://pastebin.com/raw.php?i=rd1s8qid

Edit : Some Mistake...

change

mes ""+.Name[.@i]+" - Fame : "+.Fame;

into

mes ""+.Name[.@i]+" - Fame : "+.Fame[.@i];

Edited by Emistry
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  105
  • Topics Per Day:  0.02
  • Content Count:  390
  • Reputation:   27
  • Joined:  07/12/12
  • Last Seen:  

does it still need SQL in this script?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  461
  • Reputation:   61
  • Joined:  08/28/12
  • Last Seen:  

[/code]I don't know, what we do without you Emistry.

It make me happy, that I learned today new stuff.

Thanks :D

(It works exactly how I wanted it.)

@Emistry:

Edit : Some Mistake...

Yea, I have seen that. ^-^

But thanks. <3

And I need to change this:

mes ""+.Name[.@i]+" - Fame : "+.Fame[.@i]; 

to

mes ""+.Name$[.@i]+" - Fame : "+.Fame[.@i];

Edited by WhiteEagle
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...