Comparing strings error - 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)
+--- Thread: Comparing strings error (
/showthread.php?tid=298582)
Comparing strings error -
HondaCBR - 21.11.2011
I want to check if owner name is the same as player name but im getting an error there, any ideas?
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
new file[256], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(file,sizeof(file),"Cars/%s.ini",name);
if(dini_Exists(file))
{
new owner[24];
new veh = GetPlayerVehicleID(playerid);
GetPlayerName(OwnerID[veh], owner, sizeof(owner));
if(owner == name) // THIS LINE
{
SendClientMessage(playerid, COLOR_ORANGE, "Just to test this script (THIS IS YOUR CAR).");
return 1;
}
else
{
SendClientMessage(playerid, COLOR_ORANGE, "Just to test this script (NOT YOUR CAR).");
RemovePlayerFromVehicle(playerid);
}
}
return 1;
}
Re: Comparing strings error -
Psymetrix - 21.11.2011
You can't compare strings like that. Use strcmp.
https://sampwiki.blast.hk/wiki/Strcmp
Re: Comparing strings error -
HondaCBR - 21.11.2011
could you write in that sctrcmp in to my veh check, because idk how to do it.
or rewrite it so it checks the file name if its the same as player name, maybe there is a better way to do it.
Re: Comparing strings error -
Neavorce - 21.11.2011
Код:
if( strcmp( owner, name, true) )
{
// whatever
}
else
{
// whatever
}
More info.
https://sampwiki.blast.hk/wiki/Strcmp
Re: Comparing strings error -
[MG]Dimi - 21.11.2011
Quote:
Originally Posted by Neavorce
|
Wrong. That would continue if strings are different. Use:
PHP код:
if(!strcmp(owner,name,true))
{
// whatever
}
else
{
// whatever
}
Re: Comparing strings error -
HondaCBR - 21.11.2011
it only works for id 0
Re: Comparing strings error -
HondaCBR - 21.11.2011
And also it doesnt matter if I enter my car or car with like name JOE, it still goes trhought the first line like my name and car name is correct, but its not.