Jump to content
  • 0

Character rank and sort script (sql/in-game NPC)


jTynne

Question


  • Group:  Members
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  399
  • Reputation:   198
  • Joined:  11/09/11
  • Last Seen:  

I don't usually publicly ask for assistance, but I figure that such a script could inspire others with their own creations if I did ask for support on this publicly. :)

In this script, I want players to earn temporary "value" points that get stored in an SQL table (or a global array) along with their character ID. In this particular example, a GM must enable the sorting mechanism, but in the final iteration it will be automatically called upon by an external script via "donpcevent "Ides Sort::OnSort";" which will then run an SQL query that orders the players with the highest "value" in descending order and warps the results into two places in a 1 2 1 2 1 2 1 2 fashion. This is to essentially provide as much balance as possible for a PVP-based event.

The problem I face presently is that the script is not teleporting players past a certain point, and at times does not even make it past the "for" loop to reach the truncate queries and erasing the array and temporary global variables.

The console shows no errors, and even when the script runs, no errors display.

What I'm requesting is the script's sorting feature at the very least, to be optimized and changed to allow it to work. If players are offline when it activates, it simply skips over them and continues sorting the remaining players.

If anyone can assist with this, I'd be most grateful as this has been trying my nerves for the greater portion of the past 48 hours.

ides01,100,144,0 script Ides Sort -1,5,5,{


if(getgroupid() >= 95) { 
mes "Continue Sort?";
next;
menu "Yes",-;
close2;
donpcevent "Ides Sort::OnSort";

end; }
if(idessorted < 1) {
warp "ides01",
set idessorted,1;
set .@char_id,getcharid(0);

// Value 1-10 for Base Level
if(BaseLevel < 70) { set .@value,.@values+1;}
if(BaseLevel >= 70 && BaseLevel < 80) { set .@value,.@values+2;}
if(BaseLevel >= 80 && BaseLevel < 90) { set .@value,.@values+3;}
if(BaseLevel >= 90 && BaseLevel < 100) { set .@value,.@values+4;}
if(BaseLevel >= 100 && BaseLevel < 110) { set .@value,.@values+5;}
if(BaseLevel >= 110 && BaseLevel < 120) { set .@value,.@values+6;}
if(BaseLevel >= 120 && BaseLevel < 130) { set .@value,.@values+7;}
if(BaseLevel >= 130 && BaseLevel < 140) { set .@value,.@values+8;}
if(BaseLevel >= 140 && BaseLevel < 150) { set .@value,.@values+9;}
if(BaseLevel == 150) { set .@value,.@values+10;}
set .@value,.@value+BaseLevel;

// Class Points Based On 
if(Class >= 0 && Class <= 25 || Class >= 4046 && Class <= 4049) { set .@value,.@value+0;} // First Jobs & Extended Jobs
if(Class >= 4001 && Class <= 4022) { set .@value,.@value+10;} // Trans Classes
if(Class >= 4023 && Class <= 4045) { set .@value,.@value+0;} // Baby First/Second Jobs
if(Class >= 4054 && Class <= 4087) { set .@value,.@value+25;} // 3rd Jobs
if(Class >= 4096 && Class <= 4112) { set .@value,.@value+15;} // Baby 3rd Jobs
if(Class >= 4211) { set .@value,.@value+15;} // Kagerou/Oboro Place Holder

// Role Specific Values 


query_sql("INSERT INTO `rune_rankings`.`ides_sorting` values ('"+.@char_id+"', '"+.@value+"')");
}
mes "Success";
close;
end;

OnSort:
set $@nb1, query_sql("SELECT char_id,value FROM `rune_rankings`.`ides_sorting` ORDER BY value DESC", $@char_id[1], $@value[1]);
set $@nb2,query_sql("SELECT COUNT(*) AS size FROM rune_rankings.ides_sorting", $@size);

for( set .@i, 0; .@i <= $@size; set .@i, .@i +1 ) {

if($ideswitch == 0) {
set $ideswitch,1;
warpchar "ides01",50,146,$@char_id[.@i];
goto L_skip;
}
set $ideswitch,0;
warpchar "ides01",154,146,$@char_id[.@i];
L_skip:
}
//mapannounce "ides01","[ides] Teams have been sorted!",0;
query_sql("TRUNCATE `rune_rankings`.`ides_sorting`");
deletearray $@char_id[0],$@size;
set $@nb2,0;
set $@size,0;
end;

}

3:20pm EST: Since I've not received any assistance on this yet, $10.00 USD via Paypal to whoever can get it working properly.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  20
  • Topics Per Day:  0.00
  • Content Count:  243
  • Reputation:   206
  • Joined:  11/28/11
  • Last Seen:  

This isn't tested but you can try:

OnSort:
 // Create an array of char_ids of the players that are logged in but also in the ides_sorting table
 query_sql("SELECT sort.char_id FROM `rune_rankings`.`ides_sorting` AS sort LEFT JOIN `database`.`char` AS ch ON sort.char_id = ch.char_id WHERE ch.online = 1 ORDER BY sort.value DESC",.@char_id);
 for( set .@i,0; .@i < getarraysize(.@char_id); set .@i,.@i+1 ) {
  if(.@i%2 == 0)
warpchar "ides01",50,146,.@char_id[.@i];
  else
warpchar "ides01",154,146,.@char_id[.@i];
 }
 //mapannounce "ides01","[ides] Teams have been sorted!",0;
 end;

Please make sure to change `database` to the schema name of where the table char exists.

EDIT: Full script @ http://artistic-coder.com/paste/2 (link valid only for a day)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  399
  • Reputation:   198
  • Joined:  11/09/11
  • Last Seen:  

Thanks, now testing. Will let you know the results ASAP

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  341
  • Reputation:   43
  • Joined:  01/10/12
  • Last Seen:  

I found a problem..

warp "ides01",

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  399
  • Reputation:   198
  • Joined:  11/09/11
  • Last Seen:  

OH! Thank you! That was leftover from another test of mine. Got it! Testing..

Xantara-- it works! PM me your Paypal e-mail address so that I may submit payment. :)

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