Calculate a K/D Ratio [+REP]
#1

Hey guys, I'd like to calculate the K/D ratio of families in war, however I'm having a hardtime building the k/d ratio.
Been trying several options and it keeps rounding the score (2.0000 for e.g) I know why it happens(due to me using the int dini, but I'm having a hard time realising on how to convert it into a double or what so over.
Here's what you'll need:

PHP код:
stock WarInfo(playerid)
{
    if(
dini_Int(warfile"faction1") != -1)
    {
        new 
string164 ],
            
factionex1 dini_Int(warfile,"faction1"),
            
factionex2 dini_Int(warfile,"faction2");
         new 
T1KDRT2KDR;
            if(
dini_Int(warfile"faction1deaths")!=0)
            
T1KDR = (dini_Int(warfile"faction1kills")/dini_Int(warfile"faction1deaths"));
            else
   
T1KDR =  (dini_Int(warfile"faction1kills"));
   if(
dini_Int(warfile"faction2deaths")!=0)
            
T2KDR =  (dini_Int(warfile"faction2kills")/dini_Int(warfile"faction2deaths"));
            else
T2KDR =  (dini_Int(warfile"faction2kills"));
/*int aa = (dini_Int(warfile, "faction1kills") + (dini_Int(warfile, "faction2kills");
int bb = (dini_Int(warfile, "faction1deaths") + (dini_Int(warfile, "faction2deaths");
int cc = aa+bb;
*/
   
//    "{52565f}[WAR]{52565f} A war between %s and %s has been started", teams[ GetTeam(f1) ][teamname], teams[ GetTeam(f2) ][teamname]);
        
SendClientMessage(playeridCOLOR_WHITE"{52565f}==============================================================================");
        
format(stringsizeof(string), "{9da8b9} %s vs. %s"teamsGetTeam(factionex1) ][teamname],teamsGetTeam(factionex2) ][teamname]);
        
SendClientMessage(playeridCOLOR_WHITEstring);
        
format(stringsizeof(string), "{9da8b9} %s points: %d. Kills: %d, Deaths: %d, K/D Ratio: %f"teamsGetTeam(factionex1) ][teamname], dini_Int(warfile"faction1points"),
        
dini_Int(warfile"faction1kills"), dini_Int(warfile"faction1deaths"), T1KDR);
        
SendClientMessage(playeridCOLOR_WHITEstring);
        
format(stringsizeof(string), "{9da8b9} %s points: %d. Kills: %d, Deaths: %d, K/D Ratio: %f "teamsGetTeam(factionex2) ][teamname], dini_Int(warfile"faction2points"), dini_Int(warfile"faction2kills"),dini_Int(warfile"faction2deaths"), T2KDR);
        
SendClientMessage(playeridCOLOR_WHITEstring);
        
format(stringsizeof(string), "{9da8b9} Points needed: %d. Total Kills: %d, Total Deaths: %d"dini_Int(warfile"pointsgoal"),(dini_Int(warfile"faction1kills")+dini_Int(warfile"faction2kills")),(dini_Int(warfile"faction2deaths")+dini_Int(warfile"faction1deaths")));
        
SendClientMessage(playeridCOLOR_WHITEstring);
        
SendClientMessage(playeridCOLOR_WHITE"{52565f}==============================================================================");
        return 
1;
    }
    else return 
SendClientInfo(playerid"There is no war at the moment.");

+ REPing the helper(in 24 hrs tho)
Reply
#2

You are doing integer division which no programming language likes,
Try this?
new Float: T1KDR, Float: T2KDR;
T2KDR = (float(dini_Int(warfile, "faction2kills"))/(float(dini_Int(warfile, "faction2deaths"))));
T1KDR = (float(dini_Int(warfile, "faction1kills"))/(float(dini_Int(warfile, "faction1deaths"))));
Reply
#3

1st off, get rid of dini.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)