SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 07/01/2016, 09:48 PM   #1
Aa12
Big Clucker
 
Join Date: Feb 2015
Posts: 58
Reputation: 0
Default Comparing 2 strings

Code:
CMD:kill(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1, "match");
else SendClientMessage(playerid, -1, "dont match");
return 1;
}
What am I doing wrong? I get message dont match, even though I'm sure that name matches?
Aa12 is offline   Reply With Quote
Old 07/01/2016, 10:00 PM   #2
Darkwood17
Huge Clucker
 
Join Date: Oct 2014
Posts: 305
Reputation: 52
Default Re: Comparing 2 strings

Code:
CMD:kill(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(name,HouseInfo[79][hOwner], true) == 0) return SendClientMessage(playerid, -1, "match");
else SendClientMessage(playerid, -1, "dont match");
return 1;
}
Simple
Darkwood17 is offline   Reply With Quote
Old 07/01/2016, 10:16 PM   #3
saffierr
High-roller
 
saffierr's Avatar
 
Join Date: Jul 2013
Location: GetPlayerGirlHouse(targetplayer);
Posts: 1,156
Reputation: 39
Default Re: Comparing 2 strings

or
PHP Code:
if(!strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1"match"); 
saffierr is offline   Reply With Quote
Old 07/01/2016, 10:25 PM   #4
Darkwood17
Huge Clucker
 
Join Date: Oct 2014
Posts: 305
Reputation: 52
Default Re: Comparing 2 strings

It should be
Code:
if(!strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1, "match");
It will work same as
Code:
if(strcmp(name,HouseInfo[79][hOwner], true) == 0) return SendClientMessage(playerid, -1, "match");
Darkwood17 is offline   Reply With Quote
Old 07/01/2016, 10:40 PM   #5
saffierr
High-roller
 
saffierr's Avatar
 
Join Date: Jul 2013
Location: GetPlayerGirlHouse(targetplayer);
Posts: 1,156
Reputation: 39
Default Re: Comparing 2 strings

Quote:
Originally Posted by Darkwood17 View Post
It should be
Code:
if(!strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1, "match");
It will work same as
Code:
if(strcmp(name,HouseInfo[79][hOwner], true) == 0) return SendClientMessage(playerid, -1, "match");
Quote:
Originally Posted by saffierr View Post
or
PHP Code:
if(!strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1"match"); 
Yeah, whats wrong with mine then?
saffierr is offline   Reply With Quote
Old 08/01/2016, 09:31 AM   #6
Aa12
Big Clucker
 
Join Date: Feb 2015
Posts: 58
Reputation: 0
Default Re: Comparing 2 strings

But doesnt "!" mean opposite value? If so, then if(!strcmp(...) would check if strings dont match? I could be wrong
Aa12 is offline   Reply With Quote
Old 08/01/2016, 09:50 AM   #7
Rufio
Huge Clucker
 
Join Date: May 2011
Location: Turkey
Posts: 415
Reputation: 40
Default Re: Comparing 2 strings

Quote:
Originally Posted by Aa12 View Post
But doesnt "!" mean opposite value? If so, then if(!strcmp(...) would check if strings dont match? I could be wrong
strcmp gives 0 if strings match each other on given lengths and gives 1 or -1 if strings don't match each other.

In this case, you want them to match so you should get a "0", hence why you are using !strcmp.
Rufio is offline   Reply With Quote
Old 08/01/2016, 03:07 PM   #8
Aa12
Big Clucker
 
Join Date: Feb 2015
Posts: 58
Reputation: 0
Default Re: Comparing 2 strings

oh ok, thanks
Aa12 is offline   Reply With Quote
Old 08/01/2016, 06:20 PM   #9
Aa12
Big Clucker
 
Join Date: Feb 2015
Posts: 58
Reputation: 0
Default Re: Comparing 2 strings

deleted
Aa12 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
comparing strings HondaCBR Scripting Help 2 02/01/2012 03:15 PM
Comparing strings error HondaCBR Scripting Help 6 21/11/2011 05:19 PM
Help with comparing two strings OUL Scripting Help 2 02/11/2011 06:11 PM
Comparing. Exsite Help Archive 2 25/05/2011 04:23 PM
[Help] Comparing strings (strcmp) Maxips2 Help Archive 2 03/08/2010 10:46 AM


All times are GMT. The time now is 04:32 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.