Guest User

Untitled

a guest
Apr 30th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.10 KB | None | 0 0
  1.     if(!strcmp(cmdtext, "topscore", true))
  2.     {
  3.         mysql_function_query(1, "SELECT `Name`, `Score` FROM `players` ORDER BY `Score` DESC LIMIT 10", false, "QUERY_OnTopScoreRet", "");
  4.         return 1;
  5.     }
  6.     if(!strcmp(cmdtext, "topscorecache", true))
  7.     {
  8.         mysql_function_query(1, "SELECT `Name`, `Score` FROM `players` ORDER BY `Score` DESC LIMIT 10", true, "QUERY_OnTopScoreRetCache", "");
  9.         return 1;
  10.     }
  11.     if(!strcmp(cmdtext, "topscorecache2", true))
  12.     {
  13.         mysql_function_query(1, "SELECT `Name`, `Score` FROM `players` ORDER BY `Score` DESC LIMIT 10", true, "QUERY_OnTopScoreRetCache2", "");
  14.         return 1;
  15.     }
  16.     return 0;
  17. }
  18.  
  19. forward QUERY_OnTopScoreRet();
  20. public QUERY_OnTopScoreRet()
  21. {
  22.     mysql_store_result();
  23.     new iIterator = 1, iScore, szName[MAX_PLAYER_NAME+1], szUnload[64];
  24.     while(mysql_fetch_row_format(szUnload))
  25.     {
  26.         // This code will repeat ten times.
  27.         sscanf(szUnload, "p<|>s[24]i", szName, iScore);
  28.         format(szUnload, sizeof(szUnload), "#%d - %s (%i)", iIterator, szName, iScore);
  29.         print(szUnload);
  30.         iIterator++;
  31.     }
  32.     mysql_free_result();
  33. }
  34.  
  35. forward QUERY_OnTopScoreRetCache();
  36. public QUERY_OnTopScoreRetCache()
  37. {
  38.     new rows, fields;
  39.     cache_get_data(rows, fields);
  40.  
  41.     new iIterator, iScore, szName[MAX_PLAYER_NAME+1], szUnload[64];
  42.     while(iIterator < rows)
  43.     {
  44.         cache_get_row(iIterator, 1, szName); // Get score first
  45.         iScore = strval(szName);
  46.         cache_get_row(iIterator, 0, szName);
  47.  
  48.         format(szUnload, sizeof(szUnload), "#%d - %s (%i)", iIterator+1, szName, iScore);
  49.         print(szUnload);
  50.         iIterator++;
  51.     }
  52. }
  53.  
  54. forward QUERY_OnTopScoreRetCache2();
  55. public QUERY_OnTopScoreRetCache2()
  56. {
  57.     new rows, fields;
  58.     cache_get_data(rows, fields);
  59.  
  60.     new iIterator, iScore, szName[MAX_PLAYER_NAME+1], szUnload[64];
  61.     while(iIterator < rows)
  62.     {
  63.         // Get score first
  64.         cache_get_field_content(iIterator, "Score", szName);
  65.         iScore = strval(szName);
  66.  
  67.         // Now we can re-use the szName string
  68.         cache_get_field_content(iIterator, "Name", szName);
  69.  
  70.         format(szUnload, sizeof(szUnload), "#%d - %s (%i)", iIterator+1, szName, iScore);
  71.         print(szUnload);
  72.         iIterator++;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment