SA-MP Forums Archive
[Include] fcmd - command handler - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] fcmd - command handler (/showthread.php?tid=347888)



fcmd - command handler - dexi - 03.06.2012

Hy everyone!
Im sorry for my bad English, I am Hungarian.

I needed an simple command handler, for this i write this.

An other command handler(zcmd,ycmd..) not have been using an accent character (б,й..).

Include (in code):

Код:
    stock fParamsNotUsed( params[][], maxparams ) {
            maxparams--;
           
            if( params[maxparams][0] == '\0' ) return true;
           
            return false;
    }
     
    stock fNull(params[][], maxparams) {
            for( new i = 0; i < maxparams; i++ ) {
                for( new a = 0; a < strlen(params[i]); a++ ) {
                            params[i][a] = 0;
                    }
            }
    }
     
    stock fCommand(cmdtext[], cmd[] ) {
            new ok;
            new karakterek;
     
     
            for( new i = 0; i < strlen(cmd); i++ ) {
                if( cmd[i] == cmdtext[i] ) {
                        ok++;
                    }
                    karakterek++;
            }
     
            // ----------------------------------
            new FP = fGetFirstDelim( cmdtext );
            new felhasz[128 + 1];
            format( felhasz, sizeof(felhasz), "%s", cmdtext );
     
            strdel( felhasz, FP, strlen(felhasz) );
            if( strlen(felhasz) != strlen(cmd) ) return false;
            // ----------------------------------
     
            if( ok == strlen(cmd) && karakterek == strlen(cmd) ) return true;
            return false;
    }
     
    stock fGetFirstDelim(txt[], const delim=' ') {
            new space = strlen(txt);
     
            for( new i = 0; i < strlen(txt); i++ ) {
                if( txt[i] == delim && i < space ) {
                    space = i;
                    }
            }
            return space;
    }
     
    stock fSliceParams(command[], params[][], maxparams, const delim=' ') {
            fNull( params, maxparams );
     
            new pNum = 0;
            new idxNum;
            new len;
            new idxNumPLUS;
     
            new delimeter[16 + 1];
            format( delimeter, sizeof(delimeter), "%s", delim );
     
            strdel( command, 0, fGetFirstDelim(command) + 1 );
            strins( command, delimeter, strlen(command), (128 + 1) );
     
            while( idxNum <= strlen(command) ) {
                if( command[idxNum] == delim && pNum < maxparams ) {
                            len = strmid( params[pNum], command, idxNumPLUS, idxNum , (128 + 1) );
     
     
                            if( maxparams != 1 ) {
                                    if( (maxparams-pNum) != 1 ) {
                                            pNum++;
     
                                            idxNumPLUS = idxNum + 1;
                                            params[pNum][len] = 0;
                                    }
                            }
                    }
                    idxNum++;
            }
            return 1;
    }
Usage(example):

Код:
public OnPlayerCommandText( playerid, cmdtext[] ) {
	new params[8][64 + 1];

	if( fCommand(cmdtext, "/cmd") ) {
		fSliceParams( cmdtext, params, 2 );

		if( fParamsNotUsed(params, 2) ) return SendClientMessage( playerid, -1, "Usage: /cmd (param1) [param2]" );


		printf( "%s | %s", params[0], params[1] );
	}

	return 1;
}
CREDITS:

dexi(Fl0rian) - Create the include
Kalcor - SAMP


Re: fcmd - command handler - Niko_boy - 03.06.2012

good work
how's it better then any other Command Processsors?
Quote:

...not have been using an accent character

what ya mean by that :P?


Re: fcmd - command handler - SkL_MD - 03.06.2012

Good


Re: fcmd - command handler - TheArcher - 03.06.2012

W.T.F?


Re: fcmd - command handler - dexi - 03.06.2012

accent character example: б, й, ő, у, ь, д, ъ...

Sorry... online translator powa.


Re: fcmd - command handler - Kathleen - 03.06.2012

Good job


Re: fcmd - command handler - Georgi166 - 03.06.2012

Seems good but I think people barely would use it...=\