Raised This Month: $ Target: $400
 0% 

Help with float/int enum params


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-15-2015 , 20:38   Re: Help with float/int enum params
Reply With Quote #2

Floating-point math and integer math are two very different operations. This is why you have to tag your floating-point variable with "Float:". So, you are doing integer math on floating-point values which will corrupt the floating-point value.

You should do something like this:

PHP Code:
#include <amxmodx>

enum _structStats
{
    
FloatstatDamage,
    
statKills
}

new 
g_iStats[structStats];
new 
g_iStatsRound[structStats];

public 
plugin_init()
{
    
register_concmd("float_test""commandTest")
}

public 
commandTestiPlayerID )
{
    
console_print(iPlayerID"[0] statDamage: %.2f - statKills: %d"g_iStats[statDamage], g_iStats[statKills]);

    new 
szStat[2], szValue[12];
    
read_argv(1szStatcharsmax(szStat));
    
read_argv(2szValuecharsmax(szValue));

    
server_print("%s (%d) ... %s (%f)"szStatstr_to_num(szStat), szValuestr_to_float(szValue))
    
    if (
str_to_num(szStat) == 0)
    {
        
AddDamage(str_to_float(szValue))
    }
    else
    {
        
AddKills(str_to_num(szValue))
    }

    
console_print(iPlayerID"[1] statDamage: %.2f - statKills: %d"g_iStats[statDamage], g_iStats[statKills]);
}

stock AddKills(iKills)
{
    
g_iStats[statKills]      += iKills;
    
g_iStatsRound[statKills] += iKills;
}

stock AddDamage(Float:fDamage)
{
    
g_iStats[statDamage]      += fDamage;
    
g_iStatsRound[statDamage] += fDamage;

__________________

Last edited by fysiks; 12-15-2015 at 20:41.
fysiks is offline
 



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 17:51.


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