0 Members and 2 Guests are viewing this topic.
// Show the best players overallelse if(strcmp(cmd, "topoverall", true) == 0){ // Declare some variables that we'll need new topUser1[2][128], topUser2[2][128], topUser3[2][128], userFile[64], Float:deaths, Float:kills, Float:ratio, sRatio[10], nick[128], i, j; // Set the default ratios for our top users topUser1[1] = "0.00"; topUser2[1] = "0.00"; topUser3[1] = "0.00"; // Get the total number of known users. j = dini_Int("/AllUsers.ini", "Index"); // Iterate through all known users for(i = 1; i < j + 1; i++) { // Get this person's nickname. nick = dini_Get("/AllUsers.ini", IntToStr(i)); // Find this user's file. format ( // String formatting userFile, sizeof(userFile), "/Users/%s.ini", // Variables, respectively nick ); // Get their kills and deaths. kills = dini_Int(userFile, "Kills"); deaths = dini_Int(userFile, "Deaths"); // Now find their K/D ratio. ratio = floatdiv(kills, deaths); // Is this ratio better than the current first-place holder's? if(ratio > floatstr(topUser1[1])) { // Is there a person in first place? if(floatstr(topUser1[1]) > 0) { // Is there a person in second place? if(floatstr(topUser2[1]) > 0) { // Move the previous second place winner to third place topUser3 = topUser2; // Move the previous first place winner to second place topUser2 = topUser1; } // Nope else { // Move the previous first place winner to second place topUser2 = topUser1; } } // Set them as first-place. topUser1[0] = nick; // Convert their ratio to a string format ( // String formatting sRatio, sizeof(sRatio), "%f", // Variables, respectively ratio ); // Set their ratio as the ratio string topUser1[1] = sRatio; // Done here. continue; } // No, but is it better than second-place? else if(ratio > floatstr(topUser2[1])) { // Is there a person in second place? if(floatstr(topUser2[1]) > 0) { // Move the previous second place winner to third place topUser3 = topUser2; } // Set them as second-place. topUser2[0] = nick; // Convert their ratio to a string format ( // String formatting sRatio, sizeof(sRatio), "%f", // Variables, respectively ratio ); // Set their ratio as the ratio string topUser2[1] = sRatio; // Done here. continue; } // No, but is it better than third-place? else if(ratio > floatstr(topUser3[1])) { // Yes. Set them as third-place. topUser3[0] = nick; // Convert their ratio to a string format ( // String formatting sRatio, sizeof(sRatio), "%f", // Variables, respectively ratio ); // Set their ratio as the ratio string topUser3[1] = sRatio; // Done here. continue; } // They did not rank in the Top 3. else { continue; } } // Start posting the top three SendClientMessageToAll(COLOR_YELLOW, "** Top Three Players **"); // Format a message string for first place. format ( // String formatting szMsg, sizeof(szMsg), "1. %s - %.2f", // Variables, respectively topUser1[0], floatstr(topUser1[1]) ); // Send to everyone SendClientMessageToAll(COLOR_YELLOW, szMsg); // Format a message for second place. format ( // String formatting szMsg, sizeof(szMsg), "2. %s - %.2f", // Variables, respectively topUser2[0], floatstr(topUser2[1]) ); // Send to everyone SendClientMessageToAll(COLOR_YELLOW, szMsg); // Format a message for third place. format ( // String formatting szMsg, sizeof(szMsg), "3. %s - %.2f", // Variables, respectively topUser3[0], floatstr(topUser3[1]) ); // Send to everyone SendClientMessageToAll(COLOR_YELLOW, szMsg); // Done. return 1;}
// Create the all users INI if it does not existif(!dini_Exists("/AllUsers.ini")){ // Create it with an index of 0 for no users dini_Create("/AllUsers.ini"); dini_IntSet("/AllUsers.ini", "Index", 0);}
// Add them to the All Users INI if they aren't in itnew j = dini_Int("/AllUsers.ini", "Index"), i, found = 0, result[128];// Iterate through all usersfor(i = 1; i < j + 1; i++){ // Get this user's nick. result = dini_Get("/AllUsers.ini", IntToStr(i)); // This is them. if(strcmp(result, gPlayers[playerid], true) == 0) { // Found them! found = 1; // Stop break; }} // They're not there.if(found == 0){ // Increment the index. j++; // Add them to the index. dini_Set("/AllUsers.ini", IntToStr(j), gPlayers[playerid]); // Reset the index to variable "j" dini_IntSet("/AllUsers.ini", "Index", j);}
All users overall(warning: this will become more resource intensive as more users sign up)Put this code in OnPlayerCommandText():Code: [Select]// Show the best players overallelse if(strcmp(cmd, "topoverall", true) == 0){ // Declare some variables that we'll need new topUser1[2][128], topUser2[2][128], topUser3[2][128], userFile[64], Float:deaths, Float:kills, Float:ratio, sRatio[10], nick[128], i, j; // Set the default ratios for our top users topUser1[1] = "0.00"; topUser2[1] = "0.00"; topUser3[1] = "0.00"; // Get the total number of known users. j = dini_Int("/AllUsers.ini", "Index"); // Iterate through all known users for(i = 1; i < j + 1; i++) { // Get this person's nickname. nick = dini_Get("/AllUsers.ini", IntToStr(i)); // Find this user's file. format ( // String formatting userFile, sizeof(userFile), "/Users/%s.ini", // Variables, respectively nick ); // Get their kills and deaths. kills = dini_Int(userFile, "Kills"); deaths = dini_Int(userFile, "Deaths"); // Now find their K/D ratio. ratio = floatdiv(kills, deaths); // Is this ratio better than the current first-place holder's? if(ratio > floatstr(topUser1[1])) { // Is there a person in first place? if(floatstr(topUser1[1]) > 0) { // Is there a person in second place? if(floatstr(topUser2[1]) > 0) { // Move the previous second place winner to third place topUser3 = topUser2; // Move the previous first place winner to second place topUser2 = topUser1; } // Nope else { // Move the previous first place winner to second place topUser2 = topUser1; } } // Set them as first-place. topUser1[0] = nick; // Convert their ratio to a string format ( // String formatting sRatio, sizeof(sRatio), "%f", // Variables, respectively ratio ); // Set their ratio as the ratio string topUser1[1] = sRatio; // Done here. continue; } // No, but is it better than second-place? else if(ratio > floatstr(topUser2[1])) { // Is there a person in second place? if(floatstr(topUser2[1]) > 0) { // Move the previous second place winner to third place topUser3 = topUser2; } // Set them as second-place. topUser2[0] = nick; // Convert their ratio to a string format ( // String formatting sRatio, sizeof(sRatio), "%f", // Variables, respectively ratio ); // Set their ratio as the ratio string topUser2[1] = sRatio; // Done here. continue; } // No, but is it better than third-place? else if(ratio > floatstr(topUser3[1])) { // Yes. Set them as third-place. topUser3[0] = nick; // Convert their ratio to a string format ( // String formatting sRatio, sizeof(sRatio), "%f", // Variables, respectively ratio ); // Set their ratio as the ratio string topUser3[1] = sRatio; // Done here. continue; } // They did not rank in the Top 3. else { continue; } } // Start posting the top three SendClientMessageToAll(COLOR_YELLOW, "** Top Three Players **"); // Format a message string for first place. format ( // String formatting szMsg, sizeof(szMsg), "1. %s - %.2f", // Variables, respectively topUser1[0], floatstr(topUser1[1]) ); // Send to everyone SendClientMessageToAll(COLOR_YELLOW, szMsg); // Format a message for second place. format ( // String formatting szMsg, sizeof(szMsg), "2. %s - %.2f", // Variables, respectively topUser2[0], floatstr(topUser2[1]) ); // Send to everyone SendClientMessageToAll(COLOR_YELLOW, szMsg); // Format a message for third place. format ( // String formatting szMsg, sizeof(szMsg), "3. %s - %.2f", // Variables, respectively topUser3[0], floatstr(topUser3[1]) ); // Send to everyone SendClientMessageToAll(COLOR_YELLOW, szMsg); // Done. return 1;}Put this code in OnGameModeInit():Code: [Select]// Create the all users INI if it does not existif(!dini_Exists("/AllUsers.ini")){ // Create it with an index of 0 for no users dini_Create("/AllUsers.ini"); dini_IntSet("/AllUsers.ini", "Index", 0);}Put this code in OnPlayerConnect() under if(dini_Exists(file)):Code: [Select]// Add them to the All Users INI if they aren't in itnew j = dini_Int("/AllUsers.ini", "Index"), i, found = 0, result[128];// Iterate through all usersfor(i = 1; i < j + 1; i++){ // Get this user's nick. result = dini_Get("/AllUsers.ini", IntToStr(i)); // This is them. if(strcmp(result, gPlayers[playerid], true) == 0) { // Found them! found = 1; // Stop break; }} // They're not there.if(found == 0){ // Increment the index. j++; // Add them to the index. dini_Set("/AllUsers.ini", IntToStr(j), gPlayers[playerid]); // Reset the index to variable "j" dini_IntSet("/AllUsers.ini", "Index", j);}Screenshot