Question - 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: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Question (
/showthread.php?tid=245798)
Question -
admantis - 02.04.2011
How do you do (with strcmp, preferred) to check if the params is not ANY of these?
pawn Код:
new szAvailableName[9][28];
szAvailableName[0] = "Meth";
szAvailableName[1] = "Cocaine";
szAvailableName[2] = "Heroin";
szAvailableName[3] = "Speed";
szAvailableName[4] = "Opium";
szAvailableName[5] = "Weed";
szAvailableName[6] = "Extacy";
szAvailableName[7] = "Crack";
szAvailableName[8] = "Glue";
If the params are not any of these it will return something.
Thanks.
Re: Question -
bigcomfycouch - 02.04.2011
pawn Код:
for ( new i, s = sizeof ( szAvailableName ); i < s; ++i ) {
if ( !strcmp( params, szAvailableName[ i ] ) ) {
// return so the code does not continue to the no-match-found block
return 1;
}
}
// no match found
I also felt I should point out that you spelt 'ecstasy' incorrectly.
Respuesta: Question -
admantis - 02.04.2011
Thank you for the correction and for the grammar correction. I feel satisfied with your help!
Re: Respuesta: Question -
mprofitt - 02.04.2011
Quote:
Originally Posted by admantis
Thank you for the correction and for the grammar correction. I feel satisfied with your help!
|
I love that translation...
Respuesta: Question -
admantis - 02.04.2011
But that will check if it detects ANY of the names, not one in specific?
@mprofitt: :P
Re: Question -
Donya - 02.04.2011
you should remove the "2" from the length, max length used there should be 8
pawn Код:
if ( !strcmp( params, szAvailableName[ id /*[0-9]?*/] ) )
this is for 1 check only
Re: Question -
bigcomfycouch - 02.04.2011
Yes, it checks if it matches any of the names. The code under the loop will only execute if no match is found.
Respuesta: Question -
admantis - 02.04.2011
Thanks.. I think I understood it.