AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Percentage problem (https://forums.alliedmods.net/showthread.php?t=135351)

mazmaajinsh 08-15-2010 08:02

Percentage problem
 
Hello. I cant seem to figure out the problem, why I cant get the script to calculate percentages. You see, it should calculate number / totalnumbers * 100 , to get percentage, but it doesnt. it only shows 100, when I have reached totalnumbers. Well, if you didnt understand what I ment, just check these lines please, and I am sure you will find the mistake immediatly. I have bolded the line, that I think is the problem. Thanks :)

Code:

public timer_task(Float:kreedztime)
{
        if (get_pcvar_num(kz_show_timer) == 1 )
        {
                for(new i=1;i<=MaxPlayers;i++)
                {
                        if (is_user_alive(i))
                        {
                                if( is_user_connected(i) && timer_started[i])
                                {
                                        kreedztime = thetime() - timer_time[i]
                                        new nearest = get_nearest_marker(i);
                                        new totalmarkers = gMarkerCount

                                        new percent = floatround(nearest / totalmarkers * 100.0)
                                        new imin = floatround(kreedztime / 60.0,floatround_floor)
                                        new isec = floatround(kreedztime - imin * 60.0,floatround_floor)
                                        new colors[12], r[4], g[4], b[4];
                                        get_pcvar_string(kz_hud_color, colors, 11)
                                        parse(colors, r, 3, g, 3, b, 4)
                       
                                        set_hudmessage(str_to_num(r), str_to_num(g), str_to_num(b), 0.40, 0.10, 0, 0.0, 1.0, 0.0, 0.0, 1)
                                        if ( ShowTime[i] )
                                                if (IsPaused[i])       
                                                        show_hudmessage(i, "Timer is paused, type /unpause to continue")       
                                                else
                                                        show_hudmessage(i, "Time: %s%d:%s%d | CPs: %d | TPs: %d | Done: %d",imin < 10 ? "0" : "",imin, isec < 10 ? "0" : "", isec, checknumbers[i], gochecknumbers[i], percent)
                }
}


Bugsy 08-15-2010 09:59

Re: Percentage problem
 
Try
PHP Code:

//always do a debug check to see if your numbers are correct.
client_printprint_chat "debug: %d %d" get_nearest_marker(i) , gMarkerCount );

new 
Float:nearest floatget_nearest_marker(i) );
new 
Float:totalmarkers floatgMarkerCount );

new 
percent floatround( (nearest totalmarkers) * 100.0)[/b



All times are GMT -4. The time now is 21:54.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.