AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   in_array(); => pawn (https://forums.alliedmods.net/showthread.php?t=93213)

Sn!ff3r 05-25-2009 19:01

in_array(); => pawn
 
As title, I need replacment for in_array(); function from PHP. Anybody know ?

Exolent[jNr] 05-25-2009 19:02

Re: in_array(); => pawn
 
What does the function do, what are its arguments, and what does it return?

Bugsy 05-25-2009 21:25

Re: in_array(); => pawn
 
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "bugsy"

new iArray[] = { 23 55 56 122 }
new 
szArray[] = { "hello" "world" "amxmodx" }

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    if ( 
InArray23 iArray sizeof iArray ) )
        
server_print("found it integer" )
    else
        
server_print("not found integer" );
        
    if ( 
InArrayString"world" szArray ) )
        
server_print("found it string" )
    else
        
server_print("not found string" );
}

//Integer
public InArray( const iValue , const iArray[] , const iArraySize )
{
    for ( new 
<  iArraySize i++ )
        if ( 
iValue == iArray[i] )
            return 
1;

    return 
0;
}

//String
public InArrayString( const szValue[] , const szArray[] , const iArraySize )
{
    for ( new 
iArraySize i++ )
        if ( 
equaliszValue szArray[i] ) )
            return 
1;
    
    return 
0;



stupok 05-25-2009 21:29

Re: in_array(); => pawn
 
Quote:

Originally Posted by Bugsy (Post 834793)
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "bugsy" new iArray[] = { 1 , 23 , 55 , 56 , 122 } new szArray[][] = { "hello" , "world" , "amxmodx" } public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         if ( InArray( 23 , iArray , sizeof iArray ) )         server_print("found it integer" )     else         server_print("not found integer" );             if ( InArrayString( "world" , szArray , sizeof szArray[] ) )         server_print("found it string" )     else         server_print("not found string" ); } //Integer public InArray( const iValue , const iArray[] , const iArraySize ) {     for ( new i = 0 ; i <  iArraySize ; i++ )         if ( iValue == iArray[i] )             return 1;     return 0; } //String public InArrayString( const szValue[] , const szArray[][] , const iArraySize ) {     for ( new i = 0 ; i < iArraySize ; i++ )         if ( equali( szValue , szArray[i] ) )             return 1;         return 0; }


Exolent[jNr] 05-25-2009 21:41

Re: in_array(); => pawn
 
Quote:

Originally Posted by stupok (Post 834795)
Quote:

Originally Posted by Bugsy (Post 834793)
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "bugsy" new iArray[] = { 1 , 23 , 55 , 56 , 122 } new szArray[][] = { "hello" , "world" , "amxmodx" } public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         if ( InArray( 23 , iArray , sizeof iArray ) )         server_print("found it integer" )     else         server_print("not found integer" );             if ( InArrayString( "world" , szArray , sizeof szArray ) )         server_print("found it string" )     else         server_print("not found string" ); } //Integer public InArray( const iValue , const iArray[] , const iArraySize ) {     for ( new i = 0 ; i <  iArraySize ; i++ )         if ( iValue == iArray[i] )             return 1;     return 0; } //String public InArrayString( const szValue[] , const szArray[][] , const iArraySize ) {     for ( new i = 0 ; i < iArraySize ; i++ )         if ( equali( szValue , szArray[i] ) )             return 1;         return 0; }



Bugsy 05-25-2009 21:53

Re: in_array(); => pawn
 
Thanks Exolent, pardon my typo, I just got in from playing horse-shoes and drinking beer.

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "bugsy"

new iArray[] = { 23 55 56 122 }
new 
szArray[][] = { "hello" "world" "amxmodx" }

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    if ( 
InArray23 iArray sizeof iArray ) )
        
server_print("found it integer" )
    else
        
server_print("not found integer" );
        
    if ( 
InArrayString"world" szArray sizeof szArray ) )
        
server_print("found it string" )
    else
        
server_print("not found string" );
}

//Integer
public InArray( const iValue , const iArray[] , const iArraySize )
{
    for ( new 
<  iArraySize i++ )
        if ( 
iValue == iArray[i] )
            return 
1;

    return 
0;
}

//String
public InArrayString( const szValue[] , const szArray[][] , const iArraySize )
{
    for ( new 
iArraySize i++ )
        if ( 
equaliszValue szArray[i] ) )
            return 
1;
    
    return 
0;


@stupok

:)

Code:

Warning: Indeterminate array size in "sizeof" expression (symbol "") on line 19

found it integer
not found string


stupok 05-25-2009 22:51

Re: in_array(); => pawn
 
oops


All times are GMT -4. The time now is 01:29.

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