SA-MP Forums Archive
How to check if string1 = string2? - 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: How to check if string1 = string2? (/showthread.php?tid=266696)



How to check if string1 = string2? - Dirkon - 05.07.2011

Hey everyone,

Maybe I'm kinda dumb, but I don't really know how to check if string1 = string2.

This is how I do:
Quote:

new IsOwner[20];
GetPlayerName(playerid, IsOwner, sizeof(IsOwner));

if(CarInfo[vehicleid][owner] = IsOwner)
{
SendClientMessage(playerid, 0xFFFFFFFF, "This is your vehicle.");
}
else
{
SendClientMessage(playerid, 0xFFFFFFFF, "You don't own this vehicle!");
RemovePlayerFromVehicle(playerid);
}

But it doesn't really work. When I try to sit into the car it allways says: "This is your vehicle" and let's me drive.
This is what compilier gives:
Quote:

...\car.pwn(125) : warning 211: possibly unintended assignment

Can anyone help me, please?


Re: How to check if string1 = string2? - [NoV]LaZ - 05.07.2011

https://sampwiki.blast.hk/wiki/Strcmp


Re: How to check if string1 = string2? - SchurmanCQC - 05.07.2011

Use strcmp.


Re: How to check if string1 = string2? - [L3th4l] - 05.07.2011

You can use this convenient function:
pawn Код:
stock strmatch(const String1[], const String2[])
{
    if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
    {
        return true;
    }
    else
    {
        return false;
    }
}
pawn Код:
if(strmatch(CarInfo[vehicleid][owner], IsOwner))
{
    // Names match
}



Re: How to check if string1 = string2? - Dirkon - 05.07.2011

Thanks You guys.