Use strcmp to compare 2 strings
#1

Hey
Now I know how to use GameTextForPlayer,I tryied to make a different text if the cop kill you (GTA style )
Si,I got that:
Code:
	new string[50];
	if(GetPlayerTeam(killerid) == "TEAM_COP")
	{
	  format(string, sizeof(string), "BUSTED");
	}
	else
	{
	  format(string, sizeof(string), "WASTED");
	}
  GameTextForPlayer(playerid, string, 3000, 2);
It gives me
Code:
error 033: array must be indexed (variable "-unknown-")
on the If line

I read that i got to use strcmp to compare 2 strings,but how can i do it?
Code:
if(strcmp(I don't know what to put here))
Thanks in advance
Reply
#2

GetPlayerTeam don't return a string.
Reply
#3

I just tried with the team id,it returns...an ID coz' it works.Thanks
Reply
#4

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:
  • String number 1
  • String number 2
  • Case sensitivity (boolean) (NOT REQUIRED, will give false if not specified)
  • Length (NOT REQUIRED)
You may use it like that:
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.
That is how you use strcmp. Strcmp is also used for creating commands such as /kill, here is an example:
pawn Code:
if(strcmp(cmdtext, "/kill", true) == 0) // You may also use "!strcmp(cmdtext, "/kill", true))".
  {
    SetPlayerHealth(playerid, 0.0);
    return 1;
  }
Have fun scripting.

Kind regards,

Francis Morissette
SA-MP Scripter
http://sa-mp.com
Reply
#5

Thanks
Reply
#6

Quote:
Originally Posted by TimBuk.Ekh
Thanks
Hi there,

No problem, don't hesitate to post again if you need more help.

Have fun scripting.

Kind regards,

Francis Morissette
SA-MP Scripter
http://sa-mp.com
Reply
#7

Thaks! you helpe-me!
Reply
#8

Y0 dawg........Nais bump brah.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)