AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   contatini() and its realisation in some plugin (https://forums.alliedmods.net/showthread.php?t=100526)

Owyn 08-15-2009 12:05

some question about contatini() and its realisation in some plugin
 
PHP Code:


stock 
const CheatReports[128][128

public 
CheckCheatReport(id)
{
    new 
said[192]
    
cheater_banned 0
    
new ij
    
new cheatername[32]
    
get_user_name(idcheatername32)
    
read_args(said192)
    for(
sizeof (CheatReports) ; i++)
    {
         if(
containi(saidCheatReports[i][j]) != -1)
        {
            if(
cheater_banned == 0)
            {
                
Ban(id)                        
            }
        }
    }        



was wondering what is "j" about? what it does?
i is the line number and j is allways null, thougt it's a size, means that only 1st symbol is checking but it's not, maybe it is becose of the array type? i'm not really into data types

Xanimos 08-15-2009 12:16

Re: some question about contatini() and its realisation in some plugin
 
The way that small c parses strings in function calls is why this works.
Basically if you have a string of: new hi[5] = "Hello". That's
[0]: h
[1]: e
...
[4]: o
[5]: ^0 //null terminated string

If you pass to a function check( hi[2] ), what gets passes is check( "llo" ).

So in your example since j is null aka. 0 its passing a starting point of the string at 0.
There was a good post about this in snippets/tutorial by Twilight Suzuka.

Bugsy 08-15-2009 12:27

Re: contatini() and its realisation in some plugin
 
Is the CheatReports array an array of strings containing the strings you are checking for? If so you can remove the [j] from the containi() check. Hope this helps

Little example:

PHP Code:

#include <amxmodx>

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

//Array of strings for words you are checking for
new const CheatReports[][] = { "hello" "my" "friend" };

//What the person said in chat
new said[] = "say hello to my little friend.";

//Check what person said with all words in CheatReports array.
//You will see 3 "Message found" msgs for "hello", "my", and "friend"
for ( new sizeof CheatReports i++ )
    if( 
containisaid CheatReports[i] ) != -)
        
server_print"Message found" ); 


Owyn 08-15-2009 12:38

Re: contatini() and its realisation in some plugin
 
yes my array is only strings and i don't need [j], in what condition will i needit ? still don't get the [j] thing

Bugsy 08-15-2009 12:51

Re: contatini() and its realisation in some plugin
 
Quote:

Originally Posted by .Owyn. (Post 901197)
yes my array is only strings and i don't need [j], in what condition will i needit ? still don't get the [j] thing

CheatReports is a 2-dimension array which means it is an array of arrays ... or in this case it can be referred to an array of strings.

A 1-dimension array is like so:
new TheArray[] = { 5 , 33 , 55 , 66 , 102 };

If we wanted to access 55 in this array, we would refer to it with TheArray[ 2 ] because the elements start at 0 for index and we want the 3rd element which is the number 55. 0=5, 1=33, 2=55 3=66 4=102

A 2-dimension array (array of strings).

new TheArray[][] = { "hello" , "my" , "friend" };

What this does is creates an array sized @ [ 3 ][ 7 ], the second dimension is 7 because it is automatically allocated to be large enough to store the largest string specified plus a null character, in this case "friend" which is 6 chars long + 1 so 7.

The array looks like this as far as memory is concerned:
0 = "hello**"
1 = "my*****"
2 = "friend*"
* = NULL or 0

To access the word "my" you use TheArray[ 1 ] because the word "my" is the 2nd element in the array and again, the array begins at a 0 index. 0="hello", 1="my", 2="friend".

About [j]:

If you want to access only a portion of the string you can specify the 2nd dimension. Example, suppose you wanted to access only "end" in the word "friend" you would do TheArray[ 2 ][ 3 ]. This is because the word "friend" is located at index 2 of the string array and "end" is found at index 3 of the word "friend"; 0=f 1=r 2=i 3=e.

See the Strings section in this tutorial.


All times are GMT -4. The time now is 15:00.

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