Comparing strings error
#1

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;
}
Reply
#2

You can't compare strings like that. Use strcmp. https://sampwiki.blast.hk/wiki/Strcmp
Reply
#3

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.
Reply
#4

Код:
if( strcmp( owner, name, true) )
{
     // whatever
}
else
{
    // whatever
}
More info. https://sampwiki.blast.hk/wiki/Strcmp
Reply
#5

Quote:
Originally Posted by Neavorce
Посмотреть сообщение
Код:
if( strcmp( owner, name, true) )
{
     // whatever
}
else
{
    // whatever
}
More info. https://sampwiki.blast.hk/wiki/Strcmp
Wrong. That would continue if strings are different. Use:
PHP код:
if(!strcmp(owner,name,true))
{
     
// whatever
}
else
{
    
// whatever

Reply
#6

it only works for id 0
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)