get_pcvar_num returning different number?
I needed a way to detect when people are armed. To do this, and have a cvar for easier customisation, I used a sum of bits shifted using CSW_* constants. For some reason, this doesn't work for HE grenades. It works as expected for knife, smoke, flash.
PHP Code:
Code:
Armed: 4, Skip: 570425920Code:
Armed: 3, Skip: 570425920Is there any reason get_pcvar_num is giving me a different number from expected, and checked with amx_cvar and through the server console? Thanks. |
Re: get_pcvar_num returning different number?
That is very weird, I thought at first it was a problem with your code but I tested it myself and you're correct. get_pcvar_num() is not returning just that one bit yet the cvar is holding the correct value including the bit. I put together a small function for you which basically reads the cvar as a string then converts to a number. It's silly to have to do it that way but get_pcvar_num() isn't working properly so it'll have to do. I don't have time now but I will look into this further and report any findings.
Output: Code:
DEFAULT_SKIPWEAPONS=570425936PHP Code:
|
Re: get_pcvar_num returning different number?
I've searched/debugged a bit and the problem is most likely a loss of precision double -> float. Let me explain.
The bug is not from AMXX, all the native does is returning (int)ptr->value, so the float value converted to an integer. This float value is set when you register a cvar, in the engine, using Q_atof(). This function itself works fine. The functions looks like : PHP Code:
I don't know much why and how such things are handled but the problem is that. Since from the engine, you can't fix directly. It's possible to fix amxmodx by overwriting this value using atof() from the string, in register_cvar native, it will work. Another way is to use a common way where you use the letters as flags then you could use read_flags() to get the bits sum from the letters. I don't remember seeing a plugin dealing with such big number in a cvar. |
Re: get_pcvar_num returning different number?
Quote:
Quote:
And again, thanks for all the help :). |
| All times are GMT -4. The time now is 14:22. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.