I have more stats, this is just an example. How it should be done so that the float parameters work well?
PHP Code:
#include <amxmodx>
enum _: structStats
{
Float: statDamage,
statKills
}
new g_iStats[structStats];
new g_iStatsRound[structStats];
public plugin_init()
{
register_concmd("float_test", "commandTest")
}
public commandTest( iPlayerID )
{
console_print(iPlayerID, "[0] statDamage: %.2f - statKills: %d", g_iStats[statDamage], g_iStats[statKills]);
new szStat[2], szValue[12];
read_argv(1, szStat, charsmax(szStat));
read_argv(2, szValue, charsmax(szValue));
if (str_to_num(szStat) == 0)
{
UpdateStats(statDamage, str_to_float(szValue));
}
else
{
UpdateStats(statKills, str_to_num(szValue));
}
console_print(iPlayerID, "[1] statDamage: %.2f - statKills: %d", g_iStats[statDamage], g_iStats[statKills]);
}
UpdateStats( const iStatID, const {Float, _}: iValue = 1.0 )
{
g_iStats[iStatID] += _: iValue;
g_iStatsRound[iStatID] += _: iValue;
}
Output:
PHP Code:
11:50:41 float_test 0 "12.1"
11:50:41 [0] statDamage: 0.00 - statKills: 0
[1] statDamage: 12.10 - statKills: 0
11:50:43 float_test 0 "12.1"
11:50:44 [0] statDamage: 12.10 - statKills: 0
[1] statDamage: -0.00 - statKills: 0
11:52:44 float_test 0 "12.1"
11:52:44 [0] statDamage: -0.00 - statKills: 0
[1] statDamage: -393.60 - statKills: 0
11:55:54 float_test 1 "1"
11:55:54 [0] statDamage: -393.60 - statKills: 0
[1] statDamage: -393.60 - statKills: 1
11:56:00 float_test 1 "3"
11:56:00 [0] statDamage: -393.60 - statKills: 1
[1] statDamage: -393.60 - statKills: 4
11:56:03 float_test 1 "12.1"
11:56:04 [0] statDamage: -393.60 - statKills: 4
[1] statDamage: -393.60 - statKills: 16