Jump to content
  • 0

Need help [ SQL ]


PandaLovesHamster

Question


  • Group:  Members
  • Topic Count:  51
  • Topics Per Day:  0.01
  • Content Count:  452
  • Reputation:   33
  • Joined:  12/18/14
  • Last Seen:  

prontera,155,175,5	script	Ranking#pvp	123,{

if(getgmlevel() >= 99){
	mes "[ Ranking ]";
	mes "What do you want to do?";
	menu "View Ranking",-,"Reset Ranking",OnResetRanking,"Update Ranking",OnRankingUpdate;
}
	mes "[ Ranking ]";
	mes "Top Players - Kills / Deaths";
	
	while(.@i < 10){
		mes .@i+1+". "+.top_name$[.@i]+" "+.kill_count[.@i]+" "+.top_death[.@i];
		.@i++;
	}
	
	close;
	end;
	
OnResetRanking:
	query_sql "DELETE FROM `main`.`char_reg_num` WHERE `key`='kill_count'"; //update this line
	query_sql "DELETE FROM `main`.`char_reg_num` WHERE `key`='death_count'"; //update this line
	deletearray .top_name$,getarraysize(.top_name$);
	deletearray .top_death,getarraysize(.top_death);
	deletearray .id,getarraysize(.id);
	deletearray .kill_count,getarraysize(.kill_count);
	mes "Ranking reset confirmed.";
	close;
	end;

	
OnRankingUpdate:
	mes "Ranking updated.";
	close2;
OnMinute30:
OnInit:
	query_sql(" SELECT `char_id`,`value` FROM `char_reg_num` WHERE `key` = 'kill_count' ORDER BY value DESC LIMIT 10 ",.id,.kill_count);
		for(set .@i,0; .@i < getarraysize(.id); .@i++){
			query_sql(" SELECT `name` FROM `char` WHERE `char_id` = '"+.id[.@i]+"'",.name$);
			query_sql(" SELECT `value` FROM `char_reg_num` WHERE `key` = 'death_count' AND `char_id` = '"+.id[.@i]+"'",.death_count);
			setarray .top_name$[.@i],.name$[.@i];
			setarray .top_death[.@i],.death_count[.@i];
		}
end;
}

Well, the issue with the script is that it does not show the proper output.

I suspect it's because of this line:

query_sql(" SELECT `char_id`,`value` FROM `char_reg_num` WHERE `key` = 'kill_count' ORDER BY value DESC LIMIT 10 ",.id,.kill_count);

But I have no idea how to manipulate the ORDER BY <column name>, will it be more appropriate to just use a new table for this? I hope that there can be a solution.

Thanks.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  51
  • Topics Per Day:  0.01
  • Content Count:  452
  • Reputation:   33
  • Joined:  12/18/14
  • Last Seen:  

Fixed by using:

			setarray .top_name$[.@i],.name$;
			setarray .top_death[.@i],.death_count;
Edited by PandaLovesHamster
Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

It could be optimized but the query seems correct. However the correct value of the variable for players online may differ from the sql variable value. You need to check the variable value for players offline differently from players online.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  51
  • Topics Per Day:  0.01
  • Content Count:  452
  • Reputation:   33
  • Joined:  12/18/14
  • Last Seen:  

How do I go about it? Or would it be better if I just add a new database? But I'd really prefer if I can just limit it to what's already available rather than adding another database.

Link to comment
Share on other sites

  • 0

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

perhaps you should show us the "output" that you get.

and describe what should be the "proper output" you looking for.

 

the script itself update every hour.

but the database update every short interval, 300 seconds if i recall correctly.

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