Jump to content
  • 0

pvp ladder ranking not working.


Question

Posted (edited)

why this script ladder like most highiest kill will be on top 1. its rumble. anybody can fix this? thanks!

prontera,164,170,2 script PvP Ladder 786,{
while(1) {
set .@nb, query_sql("select name, kills, deaths, class from pvpladder order by kills"+( (@menu == 2)?"/deaths":" desc" )+" limit 10", .@name$, .@kills, .@deaths, .@class );
if ( .@nb == 0 )
  mes "ladder is empty";
else {
  for ( set .@i, 0; .@i < .@nb; set .@i, .@i +1 )
 mes "^0000FF"+ (.@i+1) +": ^228B22"+ .@name$[.@i] +" ^606060"+ jobname(.@class[.@i]) +" ^006699"+ .@kills[.@i] +" / ^C80000"+ .@deaths[.@i] +"^000000";
close;
  }
}
end; // I dont think can get here anyway
OnInit:
delwaitingroom strnpcinfo(1);
set .@nb, query_sql("select name, kills, deaths, class from pvpladder order by kills desc limit 1", .@name$, .@kills, .@deaths, .@class );
waitingroom (.@nb)? ( .@name$ +" ("+ jobname(.@class[.@i]) +") : "+ .@kills[.@i] +" / "+ .@deaths[.@i] +"" ):"PVP Ladder !", 0;
end;
}

Edited by Cisqua

12 answers to this question

Recommended Posts

Posted (edited)

try this one instead

/*
create table pvpladder (
cid int(11) primary key,
name varchar(23),
kills int(11),
deaths int(11),
class int(11),
key (kills)
) engine = myisam;
*/

prontera,164,170,2    script    PvP Ladder    786,{
   .@nb = query_sql( "select name, kills, deaths, class from pvpladder order by kills desc limit 10", .@name$, .@kills, .@deaths, .@class );
   if ( !.@nb ) {
       mes "ladder is empty";
       close;
   }
   for ( .@i = 0; .@i < .@nb; .@i++ )
       mes "^0000FF"+ (.@i+1) +": ^228B22"+ .@name$[.@i] +" ^606060"+ jobname(.@class[.@i]) +" ^006699"+ .@kills[.@i] +" / ^C80000"+ .@deaths[.@i] +"^000000";
   close;
OnPCKillEvent:
   query_sql "insert into pvpladder values ( "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) ) +"', 1, 0, "+ class +" ) on duplicate key update kills = kills +1, name = '"+ escape_sql( strcharinfo(0) ) +"', class = "+ class;
   attachrid killedrid;
   query_sql "insert into pvpladder values ( "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) ) +"', 0, 1, "+ class +" ) on duplicate key update deaths = deaths +1, name = '"+ escape_sql( strcharinfo(0) ) +"', class = "+ class;    
   delwaitingroom; // continue read
OnInit:
   if ( query_sql( "select name, kills, deaths, class from pvpladder order by kills desc limit 1", .@name$, .@kills, .@deaths, .@class ) )
       waitingroom .@name$ +" ("+ jobname(.@class) +") : "+ .@kills +" / "+ .@deaths, 0;
   else
       waitingroom "PVP Ladder !", 0;
   end;
}

EDIT: fix a typo on table creation

Edited by AnnieRuru
  • Upvote 1
Posted

try

for ( .@i = 0; .@i < .@nb; .@i++ )
 mes "^0000FF"+ (.@i+1) +": ^228B22"+ .@name$[.@i] +" ^606060"+ jobname(.@class[.@i]) +" ^006699"+ .@kills[.@i] +" / ^C80000"+ .@deaths[.@i] +"^000000";
if( getgmlevel() > 90 ){
 next;
 if( select("Close","Clear Ladder") == 2 ){
  if( query_sql( "TRUNCATE `pvpladder`" ) ){
   mes "Ladder Cleared.";
 }
}
close;

Posted

so that there is a need to re-run it if the table already implemented...and of course there are still have uses for this...like auto fix the problem if table missing..

but i dun like to write the table structure in "one line"

and some ppl might not "notice" there is a SQL Table for the scripts.....

and...it's easier to view the table structure when it's formatted correctly...

  • Upvote 1
Posted

just to confirm with the SQL Machine before it create a new table...so that there wont be any error shown in map server when you try to create another table with same name...

Posted

No, that's not what I mean.

I mean why not create a check by using the 'query_sql', so the users don't have to do the query manually on the SQL.

explained my point of view here.....

so that there is a need to re-run it if the table already implemented...and of course there are still have uses for this...like auto fix the problem if table missing..

but i dun like to write the table structure in "one line"

and some ppl might not "notice" there is a SQL Table for the scripts.....

and...it's easier to view the table structure when it's formatted correctly...

Posted

I mean why not create a check by using the 'query_sql', so the users don't have to do the query manually on the SQL.

because I prefer to use query_sql as few times as possible

access query_sql once = 0.01 second (won't feel lag)

access query_sql 100 times = 1 second (start to feel lag)

OnInit will trigger every time the server start up or @reloadscript

and that has already using a lot resources

query_sql so much is just like a waste of energy

since this kinda stuff is just need to run once and forget, why run it so many times ?

reason 2:

if you previously have a table

create table test (

id int(11) primary key

count int(11)

);

and you want to edit this table

alter table test add column name varchar(23) after id;

there is no way you can do this with OnInit

that's why its better to let the user learn to create the table manually,

and they will remember that they have already created it

so when you updated the script plus update the sql database,

they will run this alter table syntax in their SQL browser

maybe you say can do it with certain tricks

select name from test limit 1 .... this will display an error on the user,

and might just bombard your release topic with replies with negative opinions on your topic

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