Array must be indexed (variable "pName")
#1

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?
Reply
#2

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

Strcmp
pawn Код:
for(new i; i < MAX_VEHICLES; i++)
    {
if(!strcmp(AVehicleData[i][Owner],pName))
        {
        }
    }
Reply
#4

Dark_rain doesnt that mean if it does NOT match?
Reply
#5

Quote:
Originally Posted by thimo
Посмотреть сообщение
Dark_rain doesnt that mean if it does NOT match?
.no.
Reply
#6

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?
Reply
#7

Seems like it.
Try maybe?
Reply
#8

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

Код:
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.
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)