AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Read minus and zero number (https://forums.alliedmods.net/showthread.php?t=320850)

OnePL 01-12-2020 11:51

Read minus and zero number
 
How to read a minus, zero number from string?
is_str_num return false if string have a minus/zero number

Napoleon_be 01-12-2020 11:55

Re: Read minus and zero number
 
Show your code

OnePL 01-12-2020 13:40

Re: Read minus and zero number
 
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;



fysiks 01-12-2020 20:54

Re: Read minus and zero number
 
What string is in szSaid when it's not working?

OnePL 01-13-2020 10:42

Re: Read minus and zero number
 
eg. -1, -2, -545335 or 0

Napoleon_be 01-13-2020 11:25

Re: Read minus and zero number
 
Use charsmax() instead of hardcoding your arrays

FYI: this won't fix your issue though lol

JocAnis 01-13-2020 11:39

Re: Read minus and zero number
 
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 ?

^SmileY 01-13-2020 11:53

Re: Read minus and zero number
 
If you want to compare number, try read_argv_int native.
I guess that will solve the problem.

georgik57 01-13-2020 18:01

Re: Read minus and zero number
 
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)



Napoleon_be 01-14-2020 08:34

Re: Read minus and zero number
 
why does everyone still hardcore their arrays when charsmax' there to make it easy for you?


All times are GMT -4. The time now is 02:40.

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