Array must be indexed (variable "pName") -
thimo - 04.07.2013
Okay this is my code:
pawn Код:
for(new i; i < MAX_VEHICLES; i++)
{
if(AVehicleData[i][Owner] == pName)
{
}
}
My error says that array must be indexed. But i just want to compare every cars owner if it matches with his name. How to fix this?
Respuesta: Array must be indexed (variable "pName") -
Gryphus One - 04.07.2013
Player names are text, and all texts are strings. To store strings you need arrays with many cells, each cell storing a single character. To compare two strings you shouldn't use == but the function strcmp instead.
Re: Array must be indexed (variable "pName") -
DaRk_RaiN - 04.07.2013
Strcmp
pawn Код:
for(new i; i < MAX_VEHICLES; i++)
{
if(!strcmp(AVehicleData[i][Owner],pName))
{
}
}
Re: Array must be indexed (variable "pName") -
thimo - 04.07.2013
Dark_rain doesnt that mean if it does NOT match?
Re: Array must be indexed (variable "pName") -
jamesbond007 - 04.07.2013
Quote:
Originally Posted by thimo
Dark_rain doesnt that mean if it does NOT match?
|
.no.
Re: Array must be indexed (variable "pName") -
thimo - 04.07.2013
Okay. I got this now:
pawn Код:
for(new i; i < MAX_VEHICLES; i++)
{
if(!strcmp(AVehicleData[i][Owner],pName))
{
DestroyVehicle(i);
continue;
}
}
Would this delete all vehicles that have the same owner?
Re: Array must be indexed (variable "pName") -
DaRk_RaiN - 04.07.2013
Seems like it.
Try maybe?
Re: Array must be indexed (variable "pName") -
thimo - 04.07.2013
Its working but now the loading how do i assign anything to a vehicleid on OnPlayerConnect?
Thats impossible how to do it anyway?
pawn Код:
GetPlayerName(playerid, name, sizeof(name));
//new xPosVeh[60], yPosVeh[60], zPosVeh[60], ModelID[10], Rotation[20];
format(str, sizeof(str), "SELECT `HouseID` FROM `Houses` WHERE `Owner`='%s'", name);
mysql_query(str); //Send the query to the SQLite system integrated in SA:MP
mysql_get_field("HouseID", str); //Gets the first field of the row returned (HouseID)
mysql_free_result(); //No need to explain...
if(!sscanf(str, "d", integer))
{
if(integer != 0) //Player has a house...
{
format(str, sizeof(str), "SELECT * FROM `Vehicles` WHERE `HouseID`= '%d'", integer);
mysql_query(str);
if(mysql_num_rows() != 0)
{
while(mysql_num_rows()) //Loop xD
{
//Do what you want with the vehicle :P
//Use db_get_field or db_get_field_assoc
//Remember to store the vehicle IDs in a variable so you can delete them in OnPlayerDisconnect
mysql_get_field("Model", AVehicle[playerid][CarModel]);
mysql_get_field("X", AVehicle[playerid][CarPos_X]);
mysql_get_field("Y", AVehicle[playerid][CarPos_Y]);
mysql_get_field("Z", AVehicle[playerid][CarPos_Z]);
mysql_get_field("Rot", AVehicle[playerid][CarPos_Rot]);
mysql_get_field("Color1", AVehicle[playerid][Color1]);
mysql_get_field("Color2", AVehicle[playerid][Color2]);
AVehicle[playerid][numId] = Vehicle_Create(AVehicle[playerid][CarModel], AVehicle[playerid][CarPos_X], AVehicle[playerid][CarPos_Y], AVehicle[playerid][CarPos_Z],
AVehicle[playerid][CarPos_Rot], AVehicle[playerid][Color1], AVehicle[playerid][Color2], 300);
}
}
}
}
Re: Array must be indexed (variable "pName") -
gtakillerIV - 04.07.2013
Код:
vehicleid = Random(10);
https://sampwiki.blast.hk/wiki/Random
That'll assign it to a number that is 9 or lower than 10.
You can change 'vehicleid' to any other car id.
Re: Array must be indexed (variable "pName") -
thimo - 04.07.2013
I do not think you understood my message. My question was how do i save the ID after spawning the car by using this:
pawn Код:
AVehicle[playerid][numId] = Vehicle_Create(AVehicle[playerid][CarModel], AVehicle[playerid][CarPos_X], AVehicle[playerid][CarPos_Y], AVehicle[playerid][CarPos_Z],
AVehicle[playerid][CarPos_Rot], AVehicle[playerid][Color1], AVehicle[playerid][Color2], 300);
Now i want to assign the owner to the vehicle using this: AVehicleData[vehicleid][Owner]
But since i cant use vehicle id on onplayerconnect how should i do this?