strcmp function ! help me! [SOLVED] -
superrobot48 - 06.05.2014
i read the tutorials
THis
and i cant get this function to work
. this function is to check how many cars the player have.
pawn Код:
GetPlayerVehicles(playerid)
{
new playername[24];
GetPlayerName(playerid, playername, sizeof(playername));
new count;
for(new i = 0; i < MAX_VEHICLES; i++) // For every vehicles till the maximum amount
{
if((vCreated[i] == true) && strcmp(VehicleInfo[i][vOwner],playername == 0))
{
count++;
}
}
return count;
}
enum where vOwner is defined
pawn Код:
enum vInfo
{
vID, // The vehicle id used on the SA-MP to represent the vehicle.
vModel, // The vehicle model of the vehicle.
Float:xspawn,
Float:yspawn,
Float:zspawn,
Float:anglespawn, // The array which contains position and the rotation of the vehicle in 4 cells. So, basically {X = 0, Y = 1, Z = 2, R = 3}
vColor1, // The primary color of the vehicle.
vColor2, // The secondary color of the vehicle.
vOwner[MAX_PLAYER_NAME],
bombed, // The vehicle's owner name. Remember string is a group of literal characters and the cells you provide should be the maximum length for that string.
bool:vLocked // Bool representing if the vehicle is locked or not. (0 = False, 1 = True)
}
new VehicleInfo[MAX_VEHICLES][vInfo];
the error:
pawn Код:
E:\samp03x_svr_R2_win32\gamemodes\Untitled.pwn(4636) : error 033: array must be indexed (variable "playername")
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
1 Error.
PLEASE HELP GUYZ!
Re: strcmp function ! help me! -
Konstantinos - 06.05.2014
You first need to close with ")" so strcmp will return a value and then compare if it's equal to 0.
pawn Код:
strcmp(VehicleInfo[i][vOwner],playername) == 0
Note that if VehicleInfo[i][vOwner] is null/empty, it will return false. You can use isnull macro and check if it's not null and then compare to the player's name.
You don't need an array so you know if a vehicle is created or not. If the vehicle doesn't exist, GetVehicleModel returns 0 and there's a native as well which called IsValidVehicle (not defined so you should add it yourself).
Re: strcmp function ! help me! -
superrobot48 - 06.05.2014
Thanks
"Note that if VehicleInfo[i][vOwner] is null/empty, it will return false. You can use isnull macro and check if it's not null and then compare to the player's name.
You don't need an array so you know if a vehicle is created or not. If the vehicle doesn't exist, GetVehicleModel returns 0 and there's a native as well which called IsValidVehicle (not defined so you should add it yourself)."
i added vCreated[i] == true to check if vehicle is created
Re: strcmp function ! help me! -
superrobot48 - 06.05.2014
And Why doesnt this work ?
pawn Код:
if(newstate == PLAYER_STATE_DRIVER)
{
if((vCreated[vehicleid] == true) && strcmp(VehicleInfo[vehicleid][vOwner],PlayerName(playerid)) == 0)
{
SendClientMessage(playerid,COLOR_GREEN,"Welcome to your purchased vehicle");
return 1;
}
}
i added this on OnPlayerStateChange
Please help
and when i removed (vCreated[vehicleid] == true)
it showed the message while entering any car
thanks
Re: strcmp function ! help me! -
Konstantinos - 06.05.2014
OnPlayerStateChange is called with newstate as driver so the vehicle exist.
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER)
{
new
vehicleid = GetPlayerVehicleID(playerid);
if (!isnull(VehicleInfo[vehicleid][vOwner]) && !strcmp(VehicleInfo[vehicleid][vOwner], PlayerName(playerid)))
{
SendClientMessage(playerid,COLOR_GREEN,"Welcome to your purchased vehicle");
}
}
return 1;
}
pawn Код:
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
Re: strcmp function ! help me! -
superrobot48 - 06.05.2014
Not Working

it is not showing anything
Re: strcmp function ! help me! -
Konstantinos - 06.05.2014
If it doesn't show the message, then either VehicleInfo[vehicleid][vOwner] is null or it doesn't match with the player's name.
Debug it and go test it in-game. Post what it printed to the console/server log.
pawn Код:
printf("vOwner: \"%s\" & PlayerName: \"%s\"", VehicleInfo[vehicleid][vOwner], PlayerName(playerid));
if (!isnull(VehicleInfo[vehicleid][vOwner]) && !strcmp(VehicleInfo[vehicleid][vOwner], PlayerName(playerid)))
{
SendClientMessage(playerid,COLOR_GREEN,"Welcome to your purchased vehicle");
}
Re: strcmp function ! help me! -
superrobot48 - 06.05.2014
debugged. vowner is null
[17:22:09] vOwner: "" & PlayerName: "superrobot48"
Re: strcmp function ! help me! -
Konstantinos - 06.05.2014
How do you assign the owner's name to vOwner for each vehicleid?
Re: strcmp function ! help me! -
superrobot48 - 06.05.2014
pawn Код:
format(VehicleInfo[vehicleid][vOwner], MAX_PLAYER_NAME, vehicleOwner);
And the other code works
it checks how many cars i have