SA-MP Forums Archive
Check for string text? - 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: Check for string text? (/showthread.php?tid=514728)



Check for string text? - Amel_PAtomAXx - 22.05.2014

This is how I made it, but when I try to start vehicle owned by State, it tells me that I don't have a key's...

pawn Код:
CMD:start(playerid, params[])
{
    #pragma unused params
    new vid = GetPlayerVehicleID(playerid);
    if(GetPlayerState(playerid) == 2)
    {
        if(EngineStarted[vid] == 0)
        {
            if(vid != INVALID_VEHICLE_ID)
            {
                new name[MAX_PLAYER_NAME];

                if(strcmp(VehicleInfo[vid][vOwner], "State", true))
                {
                    SendClientMessage(playerid, coloryellow, "Starting vehicle engine...");
                    SetTimerEx("StartingEngine", 2500, false, "i", playerid);
             
                }
                else if(GetPlayerName(playerid, name, sizeof(name)) == VehicleInfo[vid][vOwner])
                {
                    SendClientMessage(playerid, coloryellow, "Starting vehicle engine...");
                    SetTimerEx("StartingEngine", 2500, false, "i", playerid);
             
                }
               
                else
                {
                    SendClientMessage(playerid, colorgrey, "You don't have a keys of this vehicle.");
                }

            }
        }
    }
    return 1;
}



Re : Check for string text? - Ramoboss - 22.05.2014

Try like this

pawn Код:
if(!strcmp(VehicleInfo[vid][vOwner], "State", true))
                {
                    SendClientMessage(playerid, coloryellow, "Starting vehicle engine...");
                    SetTimerEx("StartingEngine", 2500, false, "i", playerid);
             
                }



Re: Check for string text? - Amel_PAtomAXx - 23.05.2014

Alright, that worked, but I cannot turn on owned vehicles now.

this part doesn't work now -.-
pawn Код:
else if(GetPlayerName(playerid, name, sizeof(name)) == VehicleInfo[vid][vOwner])
                {
                    SendClientMessage(playerid, coloryellow, "Starting vehicle engine...");
                    SetTimerEx("StartingEngine", 2500, false, "i", playerid);
             
                }
It is loaded correctly from file

pawn Код:
INI_String("Owner", VehicleInfo[vehicleID][vOwner], 32);



Re: Check for string text? - SickAttack - 23.05.2014

Try this:

pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name);
else if(strcmp(name, VehicleInfo[vid][vOwner], true) == 0)



Re : Check for string text? - Ramoboss - 23.05.2014

pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name);
else if(strcmp(name, VehicleInfo[vid][vOwner], true) == 0)
same error dude --'
do like that ^^

pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name);
else if(!strcmp(name, VehicleInfo[vid][vOwner], true) == 0)



Re: Re : Check for string text? - SickAttack - 23.05.2014

Quote:
Originally Posted by Ramoboss
Посмотреть сообщение
pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name);
else if(strcmp(name, VehicleInfo[vid][vOwner], true) == 0)
same error dude --'
do like that ^^

pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name);
else if(!strcmp(name, VehicleInfo[vid][vOwner], true) == 0)
Why in the world do you have to put a "!" in it? If it should work perfectly how it is.


Re: Check for string text? - Threshold - 23.05.2014

pawn Код:
else if(!strcmp(name, VehicleInfo[vid][vOwner], true) == 0)
is the same as:
pawn Код:
if(!(!strcmp(name, VehicleInfo[vid][vOwner], true)))
The correct code would be:
pawn Код:
if(!strcmp(name, VehicleInfo[vid][vOwner], false))



Re: Check for string text? - SickAttack - 23.05.2014

So basically your doing it backwards (same result but backwards). Why would you want to do it backwards?
pawn Код:
if(!strcmp(name, VehicleInfo[vid][vOwner], false))
This will work also:
pawn Код:
if(strcmp(name, VehicleInfo[vid][vOwner], true) == 0)



Re: Check for string text? - Threshold - 23.05.2014

They both mean the exact same thing. if(!var) is the same as if(var == 0).


Re: Check for string text? - SickAttack - 23.05.2014

So why in the world would you want to do it backwards if you can do it forwards?