Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define ORDER_ASC 0
- #define ORDER_DES 1
- new Float:t_Backup_Data[MAX_PLAYERS];
- new bool:t_IsDataEntered = false;
- new t_id[MAX_PLAYERS];
- /*
- native t_FeedInfo(playerid,Float:info);
- native t_GetRank(playerid,order);
- native t_GetPlayer(rank,order);
- */
- stock t_FeedInfo(playerid,Float:info)
- {
- t_Backup_Data[playerid] = info;
- t_id[playerid] = playerid;
- t_IsDataEntered = true;
- return 1;
- }
- stock t_GetRank(playerid,order)
- {
- if(t_IsDataEntered == false)
- {
- printf("TOP_PLAYER [ERROR] : Data is not entered\nAborting process.");
- return -1;
- }
- /*if(playerid==INVALID_PLAYER_ID || (!IsPlayerConnected(playerid)))
- {
- printf("TOP_PLAYER [ERROR] : Invalid ID || Player not connected\nAborting process.");
- return -1;
- }*/
- if(order>1 || order < 0)
- {
- printf("TOP_PLAYER [ERROR] : Wrong Order (only 0,1 allowed)\nAborting process.");
- return -1;
- }
- else if(order == ORDER_ASC)//Ascending order 1,2,3,4,5
- {
- new Float:data[MAX_PLAYERS];
- new id[MAX_PLAYERS];
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- // if(!IsPlayerConnected(i)) continue;
- data[i] = t_Backup_Data[i];
- id[i] = t_id[i];
- }
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- //if(!IsPlayerConnected(i)) continue;
- for(new j=i;j<MAX_PLAYERS;++j)
- {
- //if(!IsPlayerConnected(j)) continue;
- if(data[j]<data[i])
- {
- new Float:temp = data[i];
- data[i] = data[j];
- data[j] = temp;
- new temp1 = id[i];
- id[i] = id[j];
- id[j] = temp1;
- }
- }
- }
- new r;
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- //if(!IsPlayerConnected(i)) continue;
- if(id[i] == playerid)
- {
- r = i+1;
- break;
- }
- }
- return r;
- }
- else if(order == ORDER_DES)//Descending order 5,4,3,2,1
- {
- new Float:data[MAX_PLAYERS];
- new id[MAX_PLAYERS];
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- // if(!IsPlayerConnected(i)) continue;
- data[i] = t_Backup_Data[i];
- id[i] = t_id[i];
- }
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- // if(!IsPlayerConnected(i)) continue;
- for(new j=i;j<MAX_PLAYERS;++j)
- {
- // if(!IsPlayerConnected(j)) continue;
- if(data[j]>data[i])
- {
- new Float:temp = data[i];
- data[i] = data[j];
- data[j] = temp;
- new temp1 = id[i];
- id[i] = id[j];
- id[j] = temp1;
- }
- }
- }
- new r;
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- // if(!IsPlayerConnected(i)) continue;
- if(id[i] == playerid)
- {
- r = i+1;
- break;
- }
- }
- return r;
- }
- return 0;
- }
- stock t_GetPlayer(rank,order)
- {
- if(t_IsDataEntered == false)
- {
- printf("TOP_PLAYER [ERROR] : Data is not entered\nAborting process.");
- return -1;
- }
- if(rank<1)
- {
- printf("TOP_PLAYER [ERROR] : Rank can not be less than 1.\nAborting process.");
- return -1;
- }
- if(order>1 || order < 0)
- {
- printf("TOP_PLAYER [ERROR] : Wrong Order (only 0,1 allowed)\nAborting process.");
- return -1;
- }
- else if(order == ORDER_ASC)//Ascending order 1,2,3,4,5
- {
- new Float:data[MAX_PLAYERS];
- new id[MAX_PLAYERS];
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- // if(!IsPlayerConnected(i)) continue;
- data[i] = t_Backup_Data[i];
- id[i] = t_id[i];
- }
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- // if(!IsPlayerConnected(i)) continue;
- for(new j=i;j<MAX_PLAYERS;++j)
- {
- // if(!IsPlayerConnected(j)) continue;
- if(data[j]<data[i])
- {
- new Float:temp = data[i];
- data[i] = data[j];
- data[j] = temp;
- new temp1 = id[i];
- id[i] = id[j];
- id[j] = temp1;
- }
- }
- }
- return id[rank-1];
- }
- else if(order == ORDER_DES)//Descending order 5,4,3,2,1
- {
- new Float:data[MAX_PLAYERS];
- new id[MAX_PLAYERS];
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- // if(!IsPlayerConnected(i)) continue;
- data[i] = t_Backup_Data[i];
- id[i] = t_id[i];
- }
- for(new i=0;i<MAX_PLAYERS;++i)
- {
- // if(!IsPlayerConnected(i)) continue;
- for(new j=i;j<MAX_PLAYERS;++j)
- {
- //if(!IsPlayerConnected(j)) continue;
- if(data[j]>data[i])
- {
- new Float:temp = data[i];
- data[i] = data[j];
- data[j] = temp;
- new temp1 = id[i];
- id[i] = id[j];
- id[j] = temp1;
- }
- }
- }
- return id[rank-1];
- }
- return 0;
- }
- main()
- {
- new p[5];
- p[0]=10;
- p[1]=130;
- p[2]=15;
- p[3]=-10;
- p[4]=100;
- for(new i=5;i<MAX_PLAYERS;++i) t_FeedInfo(i,9999);
- t_FeedInfo(0,p[0]);
- t_FeedInfo(1,p[1]);
- t_FeedInfo(2,p[2]);
- t_FeedInfo(3,p[3]);
- t_FeedInfo(4,p[4]);
- for(new i=0;i<5;++i) printf("Rank for id %d = %d",i,t_GetRank(i,0));
- printf("\n\n");
- for(new i=0;i<5;++i) printf("Id wih rank %d = %d",i+1,t_GetPlayer(i+1,0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement