Advertisement
Guest User

Untitled

a guest
Sep 26th, 2012
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define ORDER_ASC 0
  4. #define ORDER_DES 1
  5.  
  6. new Float:t_Backup_Data[MAX_PLAYERS];
  7. new bool:t_IsDataEntered = false;
  8. new t_id[MAX_PLAYERS];
  9.  
  10. /*
  11. native t_FeedInfo(playerid,Float:info);
  12. native t_GetRank(playerid,order);
  13. native t_GetPlayer(rank,order);
  14. */
  15. stock t_FeedInfo(playerid,Float:info)
  16. {
  17. t_Backup_Data[playerid] = info;
  18. t_id[playerid] = playerid;
  19. t_IsDataEntered = true;
  20. return 1;
  21. }
  22.  
  23. stock t_GetRank(playerid,order)
  24. {
  25. if(t_IsDataEntered == false)
  26. {
  27. printf("TOP_PLAYER [ERROR] : Data is not entered\nAborting process.");
  28. return -1;
  29. }
  30. /*if(playerid==INVALID_PLAYER_ID || (!IsPlayerConnected(playerid)))
  31. {
  32. printf("TOP_PLAYER [ERROR] : Invalid ID || Player not connected\nAborting process.");
  33. return -1;
  34. }*/
  35.  
  36. if(order>1 || order < 0)
  37. {
  38. printf("TOP_PLAYER [ERROR] : Wrong Order (only 0,1 allowed)\nAborting process.");
  39. return -1;
  40. }
  41. else if(order == ORDER_ASC)//Ascending order 1,2,3,4,5
  42. {
  43. new Float:data[MAX_PLAYERS];
  44. new id[MAX_PLAYERS];
  45. for(new i=0;i<MAX_PLAYERS;++i)
  46. {
  47. // if(!IsPlayerConnected(i)) continue;
  48. data[i] = t_Backup_Data[i];
  49. id[i] = t_id[i];
  50.  
  51. }
  52.  
  53. for(new i=0;i<MAX_PLAYERS;++i)
  54. {
  55. //if(!IsPlayerConnected(i)) continue;
  56. for(new j=i;j<MAX_PLAYERS;++j)
  57. {
  58. //if(!IsPlayerConnected(j)) continue;
  59. if(data[j]<data[i])
  60. {
  61. new Float:temp = data[i];
  62. data[i] = data[j];
  63. data[j] = temp;
  64.  
  65. new temp1 = id[i];
  66. id[i] = id[j];
  67. id[j] = temp1;
  68.  
  69.  
  70. }
  71. }
  72. }
  73.  
  74. new r;
  75. for(new i=0;i<MAX_PLAYERS;++i)
  76. {
  77. //if(!IsPlayerConnected(i)) continue;
  78. if(id[i] == playerid)
  79. {
  80. r = i+1;
  81. break;
  82. }
  83. }
  84. return r;
  85. }
  86.  
  87. else if(order == ORDER_DES)//Descending order 5,4,3,2,1
  88. {
  89. new Float:data[MAX_PLAYERS];
  90. new id[MAX_PLAYERS];
  91. for(new i=0;i<MAX_PLAYERS;++i)
  92. {
  93. // if(!IsPlayerConnected(i)) continue;
  94. data[i] = t_Backup_Data[i];
  95. id[i] = t_id[i];
  96.  
  97. }
  98.  
  99. for(new i=0;i<MAX_PLAYERS;++i)
  100. {
  101. // if(!IsPlayerConnected(i)) continue;
  102. for(new j=i;j<MAX_PLAYERS;++j)
  103. {
  104. // if(!IsPlayerConnected(j)) continue;
  105. if(data[j]>data[i])
  106. {
  107. new Float:temp = data[i];
  108. data[i] = data[j];
  109. data[j] = temp;
  110.  
  111. new temp1 = id[i];
  112. id[i] = id[j];
  113. id[j] = temp1;
  114.  
  115. }
  116. }
  117. }
  118. new r;
  119. for(new i=0;i<MAX_PLAYERS;++i)
  120. {
  121. // if(!IsPlayerConnected(i)) continue;
  122. if(id[i] == playerid)
  123. {
  124. r = i+1;
  125. break;
  126. }
  127. }
  128. return r;
  129. }
  130. return 0;
  131. }
  132. stock t_GetPlayer(rank,order)
  133. {
  134. if(t_IsDataEntered == false)
  135. {
  136. printf("TOP_PLAYER [ERROR] : Data is not entered\nAborting process.");
  137. return -1;
  138. }
  139. if(rank<1)
  140. {
  141. printf("TOP_PLAYER [ERROR] : Rank can not be less than 1.\nAborting process.");
  142. return -1;
  143. }
  144.  
  145. if(order>1 || order < 0)
  146. {
  147. printf("TOP_PLAYER [ERROR] : Wrong Order (only 0,1 allowed)\nAborting process.");
  148. return -1;
  149. }
  150. else if(order == ORDER_ASC)//Ascending order 1,2,3,4,5
  151. {
  152. new Float:data[MAX_PLAYERS];
  153. new id[MAX_PLAYERS];
  154. for(new i=0;i<MAX_PLAYERS;++i)
  155. {
  156. // if(!IsPlayerConnected(i)) continue;
  157. data[i] = t_Backup_Data[i];
  158. id[i] = t_id[i];
  159.  
  160.  
  161. }
  162.  
  163. for(new i=0;i<MAX_PLAYERS;++i)
  164. {
  165. // if(!IsPlayerConnected(i)) continue;
  166. for(new j=i;j<MAX_PLAYERS;++j)
  167. {
  168. // if(!IsPlayerConnected(j)) continue;
  169. if(data[j]<data[i])
  170. {
  171. new Float:temp = data[i];
  172. data[i] = data[j];
  173. data[j] = temp;
  174.  
  175. new temp1 = id[i];
  176. id[i] = id[j];
  177. id[j] = temp1;
  178.  
  179.  
  180. }
  181. }
  182. }
  183. return id[rank-1];
  184. }
  185.  
  186. else if(order == ORDER_DES)//Descending order 5,4,3,2,1
  187. {
  188. new Float:data[MAX_PLAYERS];
  189. new id[MAX_PLAYERS];
  190. for(new i=0;i<MAX_PLAYERS;++i)
  191. {
  192. // if(!IsPlayerConnected(i)) continue;
  193. data[i] = t_Backup_Data[i];
  194. id[i] = t_id[i];
  195.  
  196.  
  197. }
  198.  
  199. for(new i=0;i<MAX_PLAYERS;++i)
  200. {
  201. // if(!IsPlayerConnected(i)) continue;
  202. for(new j=i;j<MAX_PLAYERS;++j)
  203. {
  204. //if(!IsPlayerConnected(j)) continue;
  205. if(data[j]>data[i])
  206. {
  207. new Float:temp = data[i];
  208. data[i] = data[j];
  209. data[j] = temp;
  210.  
  211. new temp1 = id[i];
  212. id[i] = id[j];
  213. id[j] = temp1;
  214.  
  215. }
  216. }
  217. }
  218. return id[rank-1];
  219. }
  220. return 0;
  221. }
  222.  
  223.  
  224.  
  225. main()
  226. {
  227. new p[5];
  228. p[0]=10;
  229. p[1]=130;
  230. p[2]=15;
  231. p[3]=-10;
  232. p[4]=100;
  233.  
  234. for(new i=5;i<MAX_PLAYERS;++i) t_FeedInfo(i,9999);
  235. t_FeedInfo(0,p[0]);
  236. t_FeedInfo(1,p[1]);
  237. t_FeedInfo(2,p[2]);
  238. t_FeedInfo(3,p[3]);
  239. t_FeedInfo(4,p[4]);
  240.  
  241. for(new i=0;i<5;++i) printf("Rank for id %d = %d",i,t_GetRank(i,0));
  242.  
  243. printf("\n\n");
  244. for(new i=0;i<5;++i) printf("Id wih rank %d = %d",i+1,t_GetPlayer(i+1,0));
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement