PDA

View Full Version : Check for string text?


Amel_PAtomAXx
22/05/2014, 11:20 PM
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...


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;
}

Ramoboss
22/05/2014, 11:49 PM
Try like this ;)


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

}

Amel_PAtomAXx
23/05/2014, 12:09 AM
Alright, that worked, but I cannot turn on owned vehicles now.

this part doesn't work now -.-

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


INI_String("Owner", VehicleInfo[vehicleID][vOwner], 32);

SickAttack
23/05/2014, 12:19 AM
Try this:

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

Ramoboss
23/05/2014, 12:26 AM
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 ^^


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

SickAttack
23/05/2014, 12:30 AM
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 ^^


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.

Threshold
23/05/2014, 01:54 AM
else if(!strcmp(name, VehicleInfo[vid][vOwner], true) == 0)
is the same as:
if(!(!strcmp(name, VehicleInfo[vid][vOwner], true)))

The correct code would be:
if(!strcmp(name, VehicleInfo[vid][vOwner], false))

SickAttack
23/05/2014, 01:58 AM
So basically your doing it backwards (same result but backwards). Why would you want to do it backwards?
if(!strcmp(name, VehicleInfo[vid][vOwner], false))

This will work also:
if(strcmp(name, VehicleInfo[vid][vOwner], true) == 0)

Threshold
23/05/2014, 02:03 AM
They both mean the exact same thing. if(!var) is the same as if(var == 0).

SickAttack
23/05/2014, 02:05 AM
So why in the world would you want to do it backwards if you can do it forwards?

Threshold
24/05/2014, 05:49 AM
What do you mean by backwards? 0 == var is the same as var == 0, so it really doesn't matter either way.
Besides, !var is shorter than var == 0, so why 'shouldn't' you do it that way?