18.04.2009, 21:38
Hi there,
The use of strcmp (string compare) is easy. But, it can be a little bit tricky for beginners. There is 4 parameters in the function:
That is how you use strcmp. Strcmp is also used for creating commands such as /kill, here is an example:
Have fun scripting.
Kind regards,
Francis Morissette
SA-MP Scripter
http://sa-mp.com
The use of strcmp (string compare) is easy. But, it can be a little bit tricky for beginners. There is 4 parameters in the function:
- String number 1
- String number 2
- Case sensitivity (boolean) (NOT REQUIRED, will give false if not specified)
- Length (NOT REQUIRED)
pawn Code:
String1 = "Hello";
String2 = "hello";
printf("%d", strcmp(String1, String2, false)); // will print "-1" as it is case sensitive because of the third parameter which is false.
printf("%d", strcmp(String1, String2, true)); // will print "0" as the strings are matching.
pawn Code:
if(strcmp(cmdtext, "/kill", true) == 0) // You may also use "!strcmp(cmdtext, "/kill", true))".
{
SetPlayerHealth(playerid, 0.0);
return 1;
}
Kind regards,
Francis Morissette
SA-MP Scripter
http://sa-mp.com