Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stock AddGroupRank(const groupid, const rank, rank_name[32])
- {
- if (!IsValidGroup(groupid))
- {
- LOG_ERROR_F("Couldn't add group rank for id %d, invalid group!", groupid);
- return 1;
- }
- if (rank > MAX_GROUP_RANKS)
- {
- 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);
- return 1;
- }
- if (rank > groupSpawns[groupid][grSpawn_maxRank])
- {
- 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);
- return 1;
- }
- if (rank < 1)
- {
- LOG_ERROR_F("Couldn't add rank %s(%d) to group %s(%d), less than 1!", rank, rank_name, groupSpawns[groupid][grSpawn_name], groupid);
- return 1;
- }
- groupRanks[groupid][rank][0] = rank;
- format(groupRanks[groupid][rank][1], 32, rank_name);
- 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]);
- return 1;
- }
- stock GetGroupRankName(const groupid, const rank)
- {
- new debugmsg[128], null[32] = "NULL", string[32];
- if (!IsValidGroup(groupid))
- {
- LOG_ERROR_F("Couldn't get group rank for id %d, invalid group!", groupid);
- return null;
- }
- if (rank > groupSpawns[groupid][grSpawn_maxRank])
- {
- LOG_ERROR_F("Couldn't fetch rank %d for group id %d, rank higher than maximum group rank.", rank, groupid);
- return null;
- }
- if (groupRanks[groupid][rank][0] != rank)
- {
- LOG_ERROR_F("Couldn't fetch rank %d for group id %d, didn't match array!", rank, groupid);
- return null;
- }
- format(string, sizeof(string), groupRanks[groupid][rank][1]);
- format(debugmsg, sizeof(debugmsg), "Getting (GID: %d, rank %d) - result: %s(%d)", groupid, rank, groupRanks[groupid][rank][1], groupRanks[groupid][rank][0]);
- SendDebugMessage(COLOR_ORANGE, debugmsg);
- LOG_DEBUG(debugmsg);
- return string;
- }
- stock LoadGroupRanks()
- {
- new query[120];
- mysql_format(db, query, sizeof(query), "SELECT * FROM `group_ranks`");
- mysql_pquery(db, query, "mysql_onGroupRankLoaded");
- return 1;
- }
- public mysql_onGroupRankLoaded()
- {
- new rows, fields, index;
- cache_get_data(rows, fields);
- if (rows < 1)
- {
- LOG_ERROR("Failed to load any group ranks - zero rows returned!");
- return 1;
- }
- else
- {
- new group_id, rank, name[32];
- new startTick = GetTickCount();
- while (index != rows)
- {
- group_id = cache_get_field_content_int(index, "group_id") - 1;
- rank = cache_get_field_content_int(index, "rank");
- cache_get_field_content(index, "name", name);
- AddGroupRank(group_id, rank, name);
- index++;
- }
- LOG_INFO_F("Group ranks loaded: %d (took %d ms)", index, GetTickCount() - startTick);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement