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

converting a numeric string to an integer?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 02-01-2012 , 02:00   converting a numeric string to an integer?
Reply With Quote #1

I have a string that should be an integer, and I would like to incorporate this string into a switch, more specifically, this string is chat, is there some way of manipulating format do turn the string into a digit? I have tried it several different ways, but either it gives me wrong values or it fails to compile with thie error:
Code:
/amxx/sma/overkill.sma(279) : error 029: invalid expression, assumed zero
here is the code I was trying this with

PHP Code:
        else if( (containi(said,"health")) != -)
        {
            
replace(said,191,"health ","")
            
//buying health
            
new buffer[33]
            
format(buffer,32,"%i",said)
            
client_print(x,print_chat,"[DEBUG] %d %s %s",buffer[0],buffer[0],said)
            
            
// {
                // if(equali(said,"x") != -1)
                // {
                    
                // }
                // else if(equali(said,"x") != -1)
                // {
                    
                // }
            // }
        

I have tried everything possible, but I cannot get it to return a proper value :/
__________________
+|- KARMA Respectively

HLM is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-01-2012 , 02:02   Re: converting a numeric string to an integer?
Reply With Quote #2

Show the whole code.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 02-01-2012 , 02:04   Re: converting a numeric string to an integer?
Reply With Quote #3

PHP Code:
public say_help(id) {
    new 
said[192]
    
read_args(said,191)
    
remove_quotes(said)
    if( (
containi(said"!bank") != -1) || (containi(said"!blood") != -1) || (containi(said"!health") != -1) || (containi(said"!toggleinfo" ) != -1) )
    {
        new 
info[12]
        new 
name[34]
        new 
data[2]
        
data[0] = id
        
        parse
(saidinfo11name33)
        if(
equali(info"!blood"))
        {
            if(
equal(name[0],"")) 
            {
                
data[1] = id
                set_task
(0.1"printBloodInfo"iddata2)
                
DisplayHud(id)
            }
            else if(!
equal(name[0],""))
            {
                
data[1] = cmd_target(id,name,2// Don't block access...
                
if(data[1]) 
                    
set_task(0.1"printBloodInfo"iddata2)
                else 
                    
client_print(id,print_chat,"[OK] - There is no player with that name.")    
            }
        }
        else if(
equali(info"!health")) 
        {
            if(
equal(name[0],"")) 
            {
                
data[1] = id
                set_task
(0.1"printHealthInfo"iddata2)
                
DisplayHud(id)
            }
            else if(!
equal(name[0],""))
            {
                
data[1] = cmd_target(id,name,2// Don't block access...
                
if(data[1]) 
                    
set_task(0.1"printHealthInfo"iddata2)
                else 
                    
client_print(id,print_chat,"[OK] - There is no player with that name.")    
            }
        }
        else if(
equali(info"!bankhelp") || ((equali(info"!bank"))) )
        {
            if(
equal(name[0], "") && (info[6] == 0))
            {
                
client_cmd(id,"amx_bloodbank")
            }
            else if(!
equal(name[0],""))
            {
                
                
// data[1] = id
                // set_task(0.1,  "printBankInfo", id, data, 1)
                
set_task(0.1"printBankInfo"id)
            }
            else if(
equali(info,"!bankhelp"))
            {
                
                
// data[1] = id
                // set_task(0.1,  "printBankInfo", id, data, 1)
                
set_task(0.1"printBankInfo"id)
            }
        }
        else if(
equali(info"!toggleinfo"))
        {
            
            
// data[1] = id
            // set_task(0.1, "ToggleDisplayBlood", id, data, 2)
            
set_task(0.1"ToggleDisplayBlood"id)
            
            
        }
        
    }
    else if(
equali(said"!buy ",5))
    {
        
replace(said,191,"!buy ","")
        new 
teamsay[33]
        
read_argv(0,teamsay,32)
        new 
0
        
        
        x 
= (equali(teamsay,"say_team") ? id 0)
        
// if(equali(teamsay[0],"say_team"))
        // {
            // x = id
            // client_print(id,print_chat,"[DEBUG] %d",x)
        // }
        // else
        // {
            // x = 0
            // client_print(id,print_chat,"[DEBUG] %d",x)
        // }
        // BUYING CODE
        
client_print(id,print_chat,"[OK] Feature not yet implemented.")
        if( (
containi(said,"weapon") != -1) || (containi(said,"weapons")) != -1)
        {
            if(
containi(said,"weapons") != -1)
                
replace(said,191,"weapons ","")
            else
                
replace(said,191,"weapon ","")
            
//buying weapons
        
}
        else if( (
containi(said,"health")) != -)
        {
            
replace(said,191,"health ","")
            
//buying health
            
new buffer[33]
            
format(buffer,32,"%i",said)
            
client_print(x,print_chat,"[DEBUG] %d %s %s",buffer[0],buffer[0],said)
            
            
// {
                // if(equali(said,"x") != -1)
                // {
                    
                // }
                // else if(equali(said,"x") != -1)
                // {
                    
                // }
            // }
        
}
        else
        {
            
client_print(x,print_chat,"[DEBUG] %d no input!",x)
        }
    
        
        
    }
    return 
PLUGIN_CONTINUE

__________________
+|- KARMA Respectively

HLM is offline
Carlen20
Senior Member
Join Date: Jun 2011
Location: Sweden
Old 02-01-2012 , 02:19   Re: converting a numeric string to an integer?
Reply With Quote #4

dude.. go to www.privatepaste.com and send me the link i going to make your plugin work to compile..
__________________
Nothing are impossible if you just use your mind!

Quote:
Originally Posted by NiceGuyx View Post
P.S: i'm the best coder here

Carlen20 is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 02-01-2012 , 02:31   Re: converting a numeric string to an integer?
Reply With Quote #5

the plugin compiles, the problem is I don't know how to manipulate format() to turn a string to an integer.
__________________
+|- KARMA Respectively

HLM is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 02-01-2012 , 02:42   Re: converting a numeric string to an integer?
Reply With Quote #6

The format native is for formatting a string.

If you want to read an integer from a string, use str_to_num.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 02-01-2012 , 02:49   Re: converting a numeric string to an integer?
Reply With Quote #7

I was under the impression that str_to_num simply used an algorithm to convert the string to a unique number, this is not the case?

PHP Code:
        else if( (containi(said,"health")) != -)
        {
            
replace(said,191,"health ","")
            
//buying health
            
str_to_num(said)
            
client_print(x,print_chat,"[DEBUG] %d %i",str_to_num(said),str_to_num(said))
            
            
// {
                // if(equali(said,"x") != -1)
                // {
                    
                // }
                // else if(equali(said,"x") != -1)
                // {
                    
                // }
            // }
        

ahh, thank you Emp`!
__________________
+|- KARMA Respectively

HLM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-01-2012 , 02:54   Re: converting a numeric string to an integer?
Reply With Quote #8

Quote:
Originally Posted by HLM View Post
I was under the impression that str_to_num simply used an algorithm to convert the string to a unique number, this is not the case?
Well, yeah, it does! The unique number is the number represented by the string!!
__________________
fysiks is offline
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 11:07.


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