Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1.  
  2. stock AddGroupRank(const groupid, const rank, rank_name[32])
  3. {
  4. if (!IsValidGroup(groupid))
  5. {
  6. LOG_ERROR_F("Couldn't add group rank for id %d, invalid group!", groupid);
  7. return 1;
  8. }
  9.  
  10. if (rank > MAX_GROUP_RANKS)
  11. {
  12. LOG_ERROR_F("Couldn't add rank %s(%d) to group %s(%d), exceeds defined max rank!", rank, rank_name, groupSpawns[groupid][grSpawn_name], groupid);
  13. return 1;
  14. }
  15.  
  16. if (rank > groupSpawns[groupid][grSpawn_maxRank])
  17. {
  18. LOG_ERROR_F("Couldn't add rank %s(%d) to group %s(%d), exceeds group max rank!", rank, rank_name, groupSpawns[groupid][grSpawn_name], groupid);
  19. return 1;
  20. }
  21.  
  22. if (rank < 1)
  23. {
  24. LOG_ERROR_F("Couldn't add rank %s(%d) to group %s(%d), less than 1!", rank, rank_name, groupSpawns[groupid][grSpawn_name], groupid);
  25. return 1;
  26. }
  27.  
  28. groupRanks[groupid][rank][0] = rank;
  29. format(groupRanks[groupid][rank][1], 32, rank_name);
  30. LOG_DEBUG_F("Added rank for group %s(%d) - rank %s(%d)", groupSpawns[groupid][grSpawn_name], groupid, groupRanks[groupid][rank][1], groupRanks[groupid][rank][0]);
  31. return 1;
  32. }
  33.  
  34. stock GetGroupRankName(const groupid, const rank)
  35. {
  36. new debugmsg[128], null[32] = "NULL", string[32];
  37.  
  38. if (!IsValidGroup(groupid))
  39. {
  40. LOG_ERROR_F("Couldn't get group rank for id %d, invalid group!", groupid);
  41. return null;
  42. }
  43.  
  44. if (rank > groupSpawns[groupid][grSpawn_maxRank])
  45. {
  46. LOG_ERROR_F("Couldn't fetch rank %d for group id %d, rank higher than maximum group rank.", rank, groupid);
  47. return null;
  48. }
  49.  
  50. if (groupRanks[groupid][rank][0] != rank)
  51. {
  52. LOG_ERROR_F("Couldn't fetch rank %d for group id %d, didn't match array!", rank, groupid);
  53. return null;
  54. }
  55.  
  56. format(string, sizeof(string), groupRanks[groupid][rank][1]);
  57.  
  58. format(debugmsg, sizeof(debugmsg), "Getting (GID: %d, rank %d) - result: %s(%d)", groupid, rank, groupRanks[groupid][rank][1], groupRanks[groupid][rank][0]);
  59. SendDebugMessage(COLOR_ORANGE, debugmsg);
  60. LOG_DEBUG(debugmsg);
  61.  
  62. return string;
  63. }
  64.  
  65.  
  66. stock LoadGroupRanks()
  67. {
  68. new query[120];
  69.  
  70. mysql_format(db, query, sizeof(query), "SELECT * FROM `group_ranks`");
  71. mysql_pquery(db, query, "mysql_onGroupRankLoaded");
  72.  
  73. return 1;
  74. }
  75.  
  76. public mysql_onGroupRankLoaded()
  77. {
  78. new rows, fields, index;
  79. cache_get_data(rows, fields);
  80.  
  81. if (rows < 1)
  82. {
  83. LOG_ERROR("Failed to load any group ranks - zero rows returned!");
  84. return 1;
  85. }
  86. else
  87. {
  88. new group_id, rank, name[32];
  89.  
  90. new startTick = GetTickCount();
  91.  
  92. while (index != rows)
  93. {
  94. group_id = cache_get_field_content_int(index, "group_id") - 1;
  95. rank = cache_get_field_content_int(index, "rank");
  96. cache_get_field_content(index, "name", name);
  97.  
  98. AddGroupRank(group_id, rank, name);
  99.  
  100. index++;
  101. }
  102.  
  103. LOG_INFO_F("Group ranks loaded: %d (took %d ms)", index, GetTickCount() - startTick);
  104. }
  105.  
  106. return 1;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement