Raised This Month: $51 Target: $400
 12% 

Read minus and zero number


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 01-12-2020 , 11:51   Read minus and zero number
Reply With Quote #1

How to read a minus, zero number from string?
is_str_num return false if string have a minus/zero number
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-12-2020 , 11:55   Re: Read minus and zero number
Reply With Quote #2

Show your code
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 01-12-2020 , 13:40   Re: Read minus and zero number
Reply With Quote #3

PHP Code:
public client_command(id) {
    static 
szCommand[32];
    
read_argv(0szCommand31);

    if(!(
equal(szCommand"say") || equal(szCommand"say_team"))) return 0;

    static 
szSaid[192];
    
read_argv(1szSaid191);
    
remove_quotes(szSaid);

    if(
g_szQuestQuery[0] != EOS && is_str_num(szSaid)) {
        if(
str_to_num(szSaid) == g_iAnswerNum) {
            
ColorChat(0"Obliczenia""Gracz^3 %s^1 podal poprawny wynik (^4%i^1)."g_iszPlayerData[id][szName], g_iAnswerNum);

            
g_iAnswerNum 0;
            
g_szQuestQuery[0] = EOS;
            return 
1;
        }
    }

    return 
0;

OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-12-2020 , 20:54   Re: Read minus and zero number
Reply With Quote #4

What string is in szSaid when it's not working?
__________________
fysiks is offline
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 01-13-2020 , 10:42   Re: Read minus and zero number
Reply With Quote #5

eg. -1, -2, -545335 or 0
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-13-2020 , 11:25   Re: Read minus and zero number
Reply With Quote #6

Use charsmax() instead of hardcoding your arrays

FYI: this won't fix your issue though lol
__________________

Last edited by Napoleon_be; 01-13-2020 at 11:25.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
JocAnis
Veteran Member
Join Date: Jun 2010
Old 01-13-2020 , 11:39   Re: Read minus and zero number
Reply With Quote #7

Maybe a solution:
- check if [0] character is '-'
- if so, replace '-' with '' (to be EOS or just a emtpy space?)
- then use is_str_num ?
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 01-13-2020 at 11:40.
JocAnis is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-13-2020 , 11:53   Re: Read minus and zero number
Reply With Quote #8

If you want to compare number, try read_argv_int native.
I guess that will solve the problem.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 01-13-2020 , 18:01   Re: Read minus and zero number
Reply With Quote #9

Hope this helps you.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <zp50_colorchat>
#include <zombieplaguenightmare>

public plugin_init()
{
    
register_plugin("[ZPNM] Donate Ammo Packs""1.0""D i 5 7 i n c T")
    
    
register_dictionary("zpnm_special_chat.txt")
    
register_dictionary("zpnm_donate_ampks.txt")
    
register_dictionary("zombie_plague.txt")
    
    
register_clcmd("say""verify_keywords")
    
register_clcmd("say_team""verify_keywords")
}

public 
verify_keywords(id)
{
    static 
arg[52]
    
read_args(arg51)
    
    
trim(arg)
    
remove_quotes(arg)
    
replace_all(arg51"%""")
    
replace_all(arg51"/""")
    
    if (!
arg[0])
        return;
    
    static 
arg1[7], arg2[32], arg3[10], arg4[2]
    
arg2 ""
    
arg3 ""
    
arg4 ""
    
parse(argarg16arg231arg39arg41)
    
    if (!
equali(arg1"donate") && !equali(arg1"give"))
        return;
    
    
replace_all(arg39"+""")
    
replace_all(arg39"-""")
    
replace_all(arg39"*""")
    
    if (!
arg2[0] || !arg3[0] || arg4[0])
    {
        
zp_colored_print(id"%L"id"ZPNM_DONATE_USAGE")
        
        return;
    }
    
    static 
target
    target 
cmd_target(idarg2CMDTARGET_ALLOW_SELF)
    
    if (!
target)
    {
        
zp_colored_print(id"%L"id"ZPNM_NOT_FOUND")
        
        return;
    }
    else if (
id == target)
    {
        
zp_colored_print(id"%L"id"ZPNM_YOURSELF")
        
        return;
    }
    
    static 
ampks_donatoramount
    ampks_donator 
zp_get_user_ammo_packs(id)
    
    if (!
equali(arg3"all"))
    {
/*        static i, invalid
        invalid = false
        
        for (i = 0; i < 10; i++)
        {
            if (arg3[i] && !isdigit(arg3[i]))
            {
                invalid = true
                
                break;
            }
        }
        
        if (invalid)
        {
            zp_colored_print(id, "%L", id, "ZPNM_INVALID_AMOUNT")
            
            return;
        }
        */
        
amount str_to_num(arg3)
        
        if (
amount ampks_donator)
        {
            
zp_colored_print(id"%L"id"NOT_ENOUGH_AMMO")
            
            return;
        }
    }
    else
        
amount ampks_donator
    
    
if (amount 1)
    {
        
zp_colored_print(id"%L"id"ZPNM_INVALID_AMOUNT"amount)
        
        return;
    }
    
    
zp_set_user_ammo_packs(idampks_donator amount)
    
zp_set_user_ammo_packs(targetzp_get_user_ammo_packs(target) + amount)
    
    static 
rname[32]
    
get_user_name(targetrname31)
    
    
zp_colored_print(id"^3%L"id"ZPNM_DONATE_GIVE"amountrname)
    
    static 
dname[32]
    
get_user_name(iddname31)
    
    
zp_colored_print(target"^3%L"target"ZPNM_DONATE_RECEIVE"dnameamount)

__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-14-2020 , 08:34   Re: Read minus and zero number
Reply With Quote #10

why does everyone still hardcore their arrays when charsmax' there to make it easy for you?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
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 06:18.


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