S
Slothagami
Guest
I am making a leaderboard for my game (using networking, GMS:2) and I'm new to ds_grids
I want to sort it so that the player with the highest killcount is at the top, and if two or more players have the same score their order is decided by health e.g:
player1 has score of 2 and 6 hp
player2 has score of 2 and 4 hp
player3 has score of 1 and 1 hp
player4 has score of 1 and 4 hp
I want it to be:
player1
player2
player4
player3
there will be not too many more than 4 players once the game is finished, I am open to making my own sorting script if I have to.
I have no idea how to though, here's my best attempt:
(the hard coded numbers are temporary until I can get this to work)
Thanks in advance!
I want to sort it so that the player with the highest killcount is at the top, and if two or more players have the same score their order is decided by health e.g:
player1 has score of 2 and 6 hp
player2 has score of 2 and 4 hp
player3 has score of 1 and 1 hp
player4 has score of 1 and 4 hp
I want it to be:
player1
player2
player4
player3
there will be not too many more than 4 players once the game is finished, I am open to making my own sorting script if I have to.
I have no idea how to though, here's my best attempt:
Code:
// o_remote_entity - draw GUI event
if(o_client.target == id){ // if this is the player you're controlling
// create and sort grid
var
scores = ds_grid_create(2, instance_number(o_remote_entity));
for(var i = 0; i < instance_number(o_remote_entity); i++){
var p = instance_find(o_remote_entity, i);
ds_grid_add(scores, 0, i, p.killcount);
ds_grid_add(scores, 1, i, p.name);
ds_grid_add(scores, 2, i, p.hp);
}
ds_grid_sort(scores, 2, false);
ds_grid_sort(scores, 0, false);
// draw leaderboard
var
xx = camera_get_view_width(view_camera[0]) / 2 - 52,
yy = 20,
y2 = 6;
draw_set_font(ft_small);
draw_set_halign(fa_left);
draw_set_color(c_black);
draw_set_alpha(0.4);
draw_rectangle(xx * SCREEN_RATIO, (yy - 2) * SCREEN_RATIO, (xx + 104) * SCREEN_RATIO, (yy + 2 + (y2 * ds_grid_height(scores))) * SCREEN_RATIO, false);
draw_set_color(c_white);
draw_set_alpha(1);
for(var j = 0; j < ds_grid_height(scores); j++){
draw_text((xx + 2) * SCREEN_RATIO, (yy + (y2 * j)) * SCREEN_RATIO, "#" + string(j + 1) + " (" + string(scores[# 0, j]) + ") " + scores[# 1, j]);
}
// destroy data
ds_grid_destroy(scores);
}
Thanks in advance!
Last edited by a moderator: