SA-MP Forums Archive
Use strcmp to compare 2 strings - 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: Use strcmp to compare 2 strings (/showthread.php?tid=73925)



Use strcmp to compare 2 strings - TimBuk.Ekh - 18.04.2009

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


Re: Use strcmp to compare 2 strings - yom - 18.04.2009

GetPlayerTeam don't return a string.


Re: Use strcmp to compare 2 strings - TimBuk.Ekh - 18.04.2009

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


Re: Use strcmp to compare 2 strings - Francis[French] - 18.04.2009

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: 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


Re: Use strcmp to compare 2 strings - TimBuk.Ekh - 18.04.2009

Thanks


Re: Use strcmp to compare 2 strings - Francis[French] - 18.04.2009

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


Re: Use strcmp to compare 2 strings - Stakline - 21.06.2010

Thaks! you helpe-me!


Re: Use strcmp to compare 2 strings - Joe_ - 21.06.2010

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