Raised This Month: $ Target: $400
 0% 

contatini() and its realisation in some plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Owyn
Veteran Member
Join Date: Nov 2007
Old 08-15-2009 , 12:05   some question about contatini() and its realisation in some plugin
Reply With Quote #1

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
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 08-15-2009 , 12:16   Re: some question about contatini() and its realisation in some plugin
Reply With Quote #2

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.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-15-2009 , 12:27   Re: contatini() and its realisation in some plugin
Reply With Quote #3

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" ); 
__________________
Bugsy is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 08-15-2009 , 12:38   Re: contatini() and its realisation in some plugin
Reply With Quote #4

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
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-15-2009 , 12:51   Re: contatini() and its realisation in some plugin
Reply With Quote #5

Quote:
Originally Posted by .Owyn. View Post
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.
__________________

Last edited by Bugsy; 08-15-2009 at 13:02.
Bugsy 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 15:00.


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