• Welcome to Vice City Multiplayer.
 

Top Three Players (by K/D ratio)

Started by stormeus, April 18, 2011, 08:04:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stormeus

This command (/c topoverall) was written for a help topic and is being moved to the Pawn showroom for anyone looking for it in the future. This command will get the three best players according to kill/death ratio.

Warning
As more people play on your server, this command will become more resource intensive.

Note
This command was made based off of a GUPS script. It likely will not work on a blank gamemode and the instructions might not be the same.

Screenshot



Include:

#include <dini>
#include <float>


Put this code in OnPlayerCommandText():

// Show the best players overall
else 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():

// Create the all users INI if it does not exist
if(!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)):

// Add them to the All Users INI if they aren't in it
new j = dini_Int("/AllUsers.ini", "Index"),
i,
found = 0,
result[128];

// Iterate through all users
for(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);
}

tato






<!-- Facebook Badge START --><a href="http://es-es.facebook.com/eduardoeslindo" target="_TOP" style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Eduardo Estrada">Eduardo Estrada</a><br/><a href="http://es-es.facebook.com/eduardoeslindo" target="_TOP" title="Eduardo Estrada"><img src="http://badge.facebook.com/badge/697470158.6069.1979465113.png" width="120" height="272" style="b

heekz.shadow

Nice work. It may help begginers or avengers in DM or TDM scripts.

PS: Oooooo!!! My name there? Under MORPHINE? Thats cuz I dont play VC anymore cuz I dont got internet and I use my parents JOB computers :D

** heekz.shadow feels underestimated.


Pro Scripter[/b][/i][/u]

Morphine

Quote from: heekz.shadow on April 20, 2011, 09:04:11 AM
Nice work. It may help begginers or avengers in DM or TDM scripts.

PS: Oooooo!!! My name there? Under MORPHINE? Thats cuz I dont play VC anymore cuz I dont got internet and I use my parents JOB computers :D

** heekz.shadow feels underestimated.

What is your emphasis on my name?
We both know I kick more ass than you, always did, always will.


The command is great but I think people would feel more special if it would be increased to top 5 or 10. :P

Klaus_Meine

Quote from: Morphine on April 23, 2011, 02:30:46 AM
We both know I kick more ass than you, always did, always will.
Defiantly. Shadow sux