Raised This Month: $ Target: $400
 0% 

tokens


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ProIcons
Senior Member
Join Date: Jan 2009
Location: Greece - Salonica
Old 02-04-2010 , 09:16   tokens
Reply With Quote #1

how can i take the first word of a variabled (from the : Lines[i] i want to take the first word, how can i take it?

example on mirc we have $gettok(This is a Sentence,2,32) = is
$gettok(SENTENCE,NUMBER OF WORD,CHARACTER (32 = space))
__________________
function rb return $regsubex($$1-,/(.)/g,$+($chr(2) $+ $chr(3),$r(2,15),$chr(2),\1))

Last edited by ProIcons; 02-04-2010 at 09:19.
ProIcons is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 02-04-2010 , 09:42   Re: tokens
Reply With Quote #2

Untested:
PHP Code:
stock gettok(string[], output[], nbOfWordchar) {
    new 
wordCountcurrentCharstart = -1i;
    for (
0strlen(string); ++i) {
        
currentChar string[i];
        if (
currentChar == char)
            
wordCount++;
        if (
wordCount == nbOfWord) {
            
start i;
            break;
        }
    }

    if (
start == -1)
        return -
1;

    while(
currentChar != char)
        
currentChar string[i++];

    
formatex(outputstart"%s"string[start]);
    return 
0;

new szTok[128];
gettok("this is a sequence", szTok, 2, 32);

Last edited by Seta00; 02-04-2010 at 09:44.
Seta00 is offline
ProIcons
Senior Member
Join Date: Jan 2009
Location: Greece - Salonica
Old 02-04-2010 , 09:52   Re: tokens
Reply With Quote #3

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Error: Invalid function or declaration on line 184
Error: Invalid expression, assumed zero on line 188
Error: Invalid expression, assumed zero on line 199
Error: Number of arguments does not match definition on line 221

4 Errors.



Could not locate output file D:\E\Backup STORE F\Counter Strike Servers\elajtjumperz\cstrike\addons\amxmodx\A mxx Script\Gather-Test.amx (compile failed).

Line: 184
PHP Code:
stock gettok(string[], output[], nbOfWordchar) { 
Line: 188
PHP Code:
if (currentChar == char
Line: 199
PHP Code:
while(currentChar != char
Line: 221
PHP Code:
gettok(lines[i], subtitue232); 
__________________
function rb return $regsubex($$1-,/(.)/g,$+($chr(2) $+ $chr(3),$r(2,15),$chr(2),\1))
ProIcons is offline
ProIcons
Senior Member
Join Date: Jan 2009
Location: Greece - Salonica
Old 02-04-2010 , 10:09   Re: tokens
Reply With Quote #4

PHP Code:
stock gettok(string[], output[], nbOfWordchsar) {
    new 
wordCountcurrentCharstart = -1i;
    for (
0strlen(string); ++i) {
        
currentChar string[i];
        if (
currentChar == chsar)
            
wordCount++;
        if (
wordCount == nbOfWord) {
            
start i;
            break;
        }
    }

    if (
start == -1)
        return -
1;

    while(
currentChar != chsar)
        
currentChar string[i++];

    
formatex(outputstart"%s"string[start]);
    return 
0;

Because Char was green when i am replaced it with chsar it worked on Compiling but in the game is not working

PHP Code:
new subtitue[32];
            
gettok(lines[i], subtitue232); 
            
client_print(0,print_chat,"[Gather] Substitution Found, (%s) Has recived the password and connecting to the server",subtitue
__________________
function rb return $regsubex($$1-,/(.)/g,$+($chr(2) $+ $chr(3),$r(2,15),$chr(2),\1))
ProIcons is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-04-2010 , 15:42   Re: tokens
Reply With Quote #5

This should work.
PHP Code:
stock GetToken( const szString[ ], const iToken, const cDelimiterszOutput[ ], const iLen )
{
    if( !
szString]
    || !
iToken
    
|| !( 0x01 <= cDelimiter <= 0xFF )
    {
        return 
0;
    }
    
    new 
iStart = -1iStop = -1;
    if( 
iToken )
    {
        new 
iCount;
        
        new 
cChariIndex = -1;
        while( ( 
cChar szString[ ++iIndex ] ) )
        {
            if( 
cChar == cDelimiter )
            {
                
iCount++;
            }
        }
        
        new 
iStringLen iIndex;
        
        if( 
iCount iToken )
        {
            
iCount iToken;
        }
        
        
iIndex 0;
        
        while( ( 
cChar szString[ ++iIndex ] ) )
        {
            if( 
cChar == cDelimiter )
            {
                if( !
iCount )
                {
                    
iStop iIndex;
                    
                    break;
                }
                else if( !--
iCount )
                {
                    
iStart iIndex 1;
                }
            }
        }
        
        if( 
iStart != -&& iStop == -)
        {
            
iStop iStringLen;
        }
    }
    else
    {
        new 
iCount;
        
        new 
cChariIndex = -1;
        while( ( 
cChar szString[ ++iIndex ] ) )
        {
            if( 
cChar == cDelimiter )
            {
                
iCount--;
            }
        }
        
        new 
iStringLen iIndex;
        
        if( 
iCount iToken )
        {
            
iCount iToken;
        }
        
        
iCount absiCount );
        
        while( ( 
cChar szString[ --iIndex ] ) )
        {
            if( 
cChar == cDelimiter )
            {
                if( !
iCount )
                {
                    
iStart iIndex 1;
                    
                    break;
                }
                else if( !--
iCount )
                {
                    
iStop iIndex;
                }
            }
        }
        
        if( 
iStop != -&& iStart == -)
        {
            
iStart 0;
        }
    }
    
    return 
copyszOutputminiStop iStartiLen ), szStringiStart ] );

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 02-04-2010 , 18:05   Re: tokens
Reply With Quote #6

Simplified (working) version:
PHP Code:
stock gettok(output[], string[], nbOfWorddelimiter) {
    if (!
string[0]|| !(0x01 <= delimiter <= 0xFF) || !nbOfWord// does Pawn support unicode???
        
return 0;
        
    new 
iendwordCount 1;
    for (
0strlen(string); i++) {
        if (
string[i] == delimiter)
            
wordCount++;
        if (
wordCount == nbOfWord)
            break;
    }
    
    for (
end = ++iend strlen(string); end++) {
        if (
string[end] == delimiter)
            break;
    }
    
    return 
copy(outputend-i+1string[i]);

nbOfWord starts at 1, so to get the first token: gettok(output, string, 1, 32)

Last edited by Seta00; 02-04-2010 at 18:20.
Seta00 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-04-2010 , 21:38   Re: tokens
Reply With Quote #7

Quote:
Originally Posted by Seta00 View Post
Simplified (working) version:
If you try to retrieve the first token with your code the first letter gets dropped and spaces are left on words.
Code:
"This is an example"

Word 1 | "his " | Length=4
Word 2 | "is " | Length=3
Word 3 | "an " | Length=3
Word 4 | "example" | Length=7
Here's a working version
PHP Code:
stock GetTokenszOutput[] , const szSource[] , iWordNumber cDelimiter 
{
    if ( !
szSource] || !( <= cDelimiter <= 255 ) || !iWordNumber )
        return 
0;
        
    new 
iPos iStart iLen strlenszSource ) , iWordCount 1;
    
    for ( 
iPos iPos iLen iPos++ ) 
    {
        if ( 
szSourceiPos ] == cDelimiter 
        {
            if ( 
iWordCount == iWordNumber )
            {
                 break;
            }
            else 
            {
                
iWordCount++;
                
iStart iPos 1;
            }
        }
    }
    
    return 
copyszOutput , ( iPos iStart ) , szSourceiStart ] );

Example:
PHP Code:
new szTest[] = "This is an example";
new 
szWord];
    
for ( new 
<= i++ )
    
server_print"Word %d | ^"%s^" | Length=%d" szWord GetTokenszWord szTest ' ' ) ); 
Result:
Code:
Word 1 | "This" | Length=4
Word 2 | "is" | Length=2
Word 3 | "an" | Length=2
Word 4 | "example" | Length=7
__________________

Last edited by Bugsy; 02-04-2010 at 23:15.
Bugsy is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 02-05-2010 , 07:13   Re: tokens
Reply With Quote #8

I forgot to put quotes around the string, so I didn't see the extra space. Sorry
The problem was the check for nbOfWords, here's the correct code:
PHP Code:
stock gettok(output[], string[], nbOfWorddelimiter) {
    if (!
string[0]|| !(0x01 <= delimiter <= 0xFF) || !nbOfWord// does Pawn support unicode???
        
return 0;
        
    new 
iendwordCount 1;
    for (
0strlen(string); i++) {
        if (
wordCount == nbOfWord)
            break;
        if (
string[i] == delimiter)
            
wordCount++;
    }
    
    for (
end i+1end strlen(string); end++) {
        if (
string[end] == delimiter)
            break;
    }
    
    return 
copy(outputend-istring[i]);

Attached Thumbnails
Click image for larger version

Name:	tknzr.png
Views:	166
Size:	64.5 KB
ID:	59097  

Last edited by Seta00; 02-05-2010 at 07:24.
Seta00 is offline
Old 02-08-2010, 11:39
ProIcons
This message has been deleted by ProIcons. Reason: My Wrong
ProIcons
Senior Member
Join Date: Jan 2009
Location: Greece - Salonica
Old 11-25-2010 , 10:21   Re: tokens
Reply With Quote #9

PHP Code:
stock gettok(output[], string[], nbOfWorddelimiter) {
    if (!
string[0]|| !(0x01 <= delimiter <= 0xFF) || !nbOfWord// does Pawn support unicode???
        
return 0;
        
    new 
iendwordCount 1;
    for (
0strlen(string); i++) {
        if (
wordCount == nbOfWord)
            break;
        if (
string[i] == delimiter)
            
wordCount++;
    }
    
    for (
end i+1end strlen(string); end++) {
        if (
string[end] == delimiter)
            break;
    }
    
    return 
copy(outputend-istring[i]);
}  



if (
equali(arg1,"ADDGAME"))
    {
       
set_variables();
       new 
targetmap[32],temp[32],targetplayers[2];
       
gettok(targetmap,botcmd,1,32);
       
gettok(Admin,botcmd,2,32);
       
gettok(targetplayers,botcmd,3,32);
       
players targetplayers[1];
       
server_cmd("amx_map %s",targetmap);
       for( new 
1<= playersi++ )
       {
           
gettok(temp,botcmdi,32)
           
format(player[i],31,temp);
       }
    } 

Line 380: if (string[end] == delimiter)

Quote:

[Gather] ADDGAME de_aztec ProIcons 4 ProIcons Casanova GaMeMaSteR Dev
L 11/25/2010 - 17:182: [AMXX] Displaying debug trace (plugin "gather.amxx")
L 11/25/2010 - 17:182: [AMXX] Run time error 5: memory access
L 11/25/2010 - 17:182: [AMXX] [0] Gather.sma::gettok (line 380)
L 11/25/2010 - 17:182: [AMXX] [1] Gather.sma::socket_read (line 484)
__________________
function rb return $regsubex($$1-,/(.)/g,$+($chr(2) $+ $chr(3),$r(2,15),$chr(2),\1))
ProIcons is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-25-2010 , 10:23   Re: tokens
Reply With Quote #10

Try http://forums.alliedmods.net/showpos...53&postcount=7 ?
__________________
Bugsy is offline
Old 11-25-2010, 10:29
ProIcons
This message has been deleted by ProIcons. Reason: My Wrong
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 07:24.


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