M
MrTkila
Guest
Hi,
I'm having trouble making a position system in a race game.
What I was expecting is that if any of the four players, for example Player A, hits the lap detection zone first he will be in first place and if Player B hits the lap detection zone next and both have the same ammount of laps Player B will be second place and if Player C hits the detection zone and has the same ammount of laps as A and B, he will be third, so Player D if he has less or the same amount of laps will be fourth place.
I have this code, and the problem is that if Player A and Player B have the same amount of laps I will get two players in the same position (1st place, 2nd place, 3rd place, 4rd place).
Hope I can get some help! Thank you.
I'm having trouble making a position system in a race game.
What I was expecting is that if any of the four players, for example Player A, hits the lap detection zone first he will be in first place and if Player B hits the lap detection zone next and both have the same ammount of laps Player B will be second place and if Player C hits the detection zone and has the same ammount of laps as A and B, he will be third, so Player D if he has less or the same amount of laps will be fourth place.
I have this code, and the problem is that if Player A and Player B have the same amount of laps I will get two players in the same position (1st place, 2nd place, 3rd place, 4rd place).
Code:
car_pos = ds_list_create();
//Assing Positions taking laps as reference (laps are stored in global.lapsa for player a, global.lapsb for player b, etc)
ds_list_add(car_pos, global.lapsa);
ds_list_add(car_pos, global.lapsb);
ds_list_add(car_pos, global.lapsc);
ds_list_add(car_pos, global.lapsd);
ds_list_sort(car_pos, false);
//convert 0 to 3 position values to 1 to 4 (global.posa determines position for player a, global.lapsb for player b, etc)
global.posa = ds_list_find_index(car_pos,global.lapsa)+1;
global.posb = ds_list_find_index(car_pos,global.lapsb)+1;
global.posc = ds_list_find_index(car_pos,global.lapsc)+1;
global.posd = ds_list_find_index(car_pos,global.lapsd)+1;
ds_list_destroy(car_pos);
Hope I can get some help! Thank you.