Raised This Month: $ Target: $400
 0% 

Divide


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
2t_rider
Junior Member
Join Date: Dec 2018
Location: Hungary
Old 04-04-2020 , 03:10   Divide
Reply With Quote #1

Hey guys,
I want to search the best Kill/Death ratio, and the worst, with these:
Code:
public best_swap_noob(const TeamName:team_best, const TeamName:team_noob)
{
    new iPlayers[32], iPlrNum, best_id, Float:best_kd = 0.0, noob_id, Float:noob_kd = 100.0;
    get_players( iPlayers, iPlrNum, "ch" );

    for ( new i, id; i < iPlrNum; ++i ) 
    {
        id = iPlayers[i];
        if(!moved[id] && is_user_connected(id))
        {   
            new death = get_member(id, m_iDeaths);
            new kill = get_entvar(id, var_frags);
            if(death == 0) death=1;
            if(kill<=0) kill=1;

            new Float:kd = floatdiv(float(kill),float(death));
            
            new TeamName:iTeam = get_member(id, m_iTeam);
            if(iTeam == team_best && kd>=best_kd)
            {
                best_kd=kd;
                best_id=id;
            }
            if(iTeam == team_noob && kd<=noob_kd)
            {
                noob_kd=kd;
                noob_id=id;
            }
        }
        
    }
    server_cmd("echo noob_id: %d | kd: %f",noob_id,noob_kd)
    server_cmd("echo best_id: %d | kd: %f",best_id,best_kd)

    //rg_set_user_team(best_id, team_noob, MODEL_UNASSIGNED);
   // rg_set_user_team(noob_id, team_best, MODEL_UNASSIGNED);
    

    moved[best_id]=true;
    moved[noob_id]=true;

}

I have problem with divide, because kd sometimes not float value.
I used echo to print in server console player id and his kill/death ratio, and this printed:
Code:
noob_id : 7 | kd : 1.000000 
best_id : 6 | kd : 121984344.000000 

or

noob_id : 7 | kd : 1.000000 
best_id : 6 | kd : 109943192.000000 

or
noob_id : 18 | kd : 0.500000 
best_id : 9 | kd : 1077936128.000000
I dont know why not work.
Thanks for reply.
2t_rider is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-04-2020 , 06:58   Re: Divide
Reply With Quote #2

Try:

Code:
new Float:kd = float(kill) / float(death);
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
2t_rider
Junior Member
Join Date: Dec 2018
Location: Hungary
Old 04-04-2020 , 09:50   Re: Divide
Reply With Quote #3

Code:
register_clcmd("say /kd", "mykd")
Code:
public mykd(id)
{
    new death = get_member(id, m_iDeaths);
    new kill = get_entvar(id, var_frags);
    if(death == 0) death=1;
    if(kill<=0) kill=1;

    new Float:kd = float(kill)/float(death);
    client_cmd(id, "echo id: %d  | kd: %f",id,kd)

}
Code:
id : 4 | kd : 1073741824.000000
same

Last edited by 2t_rider; 04-04-2020 at 09:52.
2t_rider is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-04-2020 , 09:56   Re: Divide
Reply With Quote #4

"var_frags" returns a float value though.

Code:
new Float:kill = get_entvar(id, var_frags); new Float:kd = kill/float(death);
__________________

Last edited by OciXCrom; 04-04-2020 at 09:57.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
2t_rider
Junior Member
Join Date: Dec 2018
Location: Hungary
Old 04-04-2020 , 10:44   Re: Divide
Reply With Quote #5

Working
Thanks
2t_rider is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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