Dealership help,
#1

Hi guys,
so I have this code when a player buys a car:
pawn Код:
CarInfo[idx][vModel] = 560;
            CarInfo[idx][vLocationx] = 559.5988;
            CarInfo[idx][vLocationy] = -1267.7670;
            CarInfo[idx][vLocationz] = 17.2422;
            CarInfo[idx][vAngle] = 90.00;
            CarInfo[idx][vColorOne] = 0;
            CarInfo[idx][vColorTwo] = 0;
            strmid(CarInfo[idx][vOwner], PlayerName(playerid), 0, strlen(PlayerName(playerid)), 255);
            strmid(CarInfo[idx][vDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            CarInfo[idx][vValue] = 20000;
            CarInfo[idx][vLicense] = 1;
            CarInfo[idx][vOwned] = 1;
            CarInfo[idx][vLock] = 0;
And I get undefined sysmbol idx, because idx isn't defined but I don't know how to define it with this code...
pawn Код:
public LoadCar()
{
    new arrCoords[13][64];
    new strFromFile2[256];
    new File: file = fopen("CarOwnership.cfg", io_read);
    if (file)
    {
        new idx = 0;
        while (idx < sizeof(CarInfo))
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, ',');
            CarInfo[idx][vModel] = strval(arrCoords[0]);
            CarInfo[idx][vLocationx] = floatstr(arrCoords[1]);
            CarInfo[idx][vLocationy] = floatstr(arrCoords[2]);
            CarInfo[idx][vLocationz] = floatstr(arrCoords[3]);
            CarInfo[idx][vAngle] = floatstr(arrCoords[4]);
            CarInfo[idx][vColorOne] = strval(arrCoords[5]);
            CarInfo[idx][vColorTwo] = strval(arrCoords[6]);
            strmid(CarInfo[idx][vOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
            strmid(CarInfo[idx][vDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            CarInfo[idx][vValue] = strval(arrCoords[9]);
            CarInfo[idx][vLicense] = strval(arrCoords[10]);
            CarInfo[idx][vOwned] = strval(arrCoords[11]);
            CarInfo[idx][vLock] = strval(arrCoords[12]);
            printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][vOwner],CarInfo[idx][vLicense]);
            idx++;
        }
    }
    return 1;
}
Please help.
Reply
#2

Try this:

pawn Код:
public LoadCar()
{
    new arrCoords[13][64];
    new strFromFile2[256];
    new File: file = fopen("CarOwnership.cfg", io_read);
    if (file)
    {
        for(new idx = 0; idx < sizeof(CarInfo); idx ++)
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, ',');
            CarInfo[idx][vModel] = strval(arrCoords[0]);
            CarInfo[idx][vLocationx] = floatstr(arrCoords[1]);
            CarInfo[idx][vLocationy] = floatstr(arrCoords[2]);
            CarInfo[idx][vLocationz] = floatstr(arrCoords[3]);
            CarInfo[idx][vAngle] = floatstr(arrCoords[4]);
            CarInfo[idx][vColorOne] = strval(arrCoords[5]);
            CarInfo[idx][vColorTwo] = strval(arrCoords[6]);
            strmid(CarInfo[idx][vOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
            strmid(CarInfo[idx][vDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            CarInfo[idx][vValue] = strval(arrCoords[9]);
            CarInfo[idx][vLicense] = strval(arrCoords[10]);
            CarInfo[idx][vOwned] = strval(arrCoords[11]);
            CarInfo[idx][vLock] = strval(arrCoords[12]);
            printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][vOwner],CarInfo[idx][vLicense]);
            idx++;
        }
    }
    return 1;
}
I'm not familiar with this file saving method but I think it's very old and slow.
Reply
#3

Quote:
Originally Posted by Tee
Посмотреть сообщение
pawn Код:
public LoadCar()
{
    new arrCoords[13][64];
    new strFromFile2[256];
    new File: file = fopen("CarOwnership.cfg", io_read);
    if (file)
    {
        for(new idx = 0; idx < sizeof(CarInfo); idx ++)
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, ',');
            CarInfo[idx][vModel] = strval(arrCoords[0]);
            CarInfo[idx][vLocationx] = floatstr(arrCoords[1]);
            CarInfo[idx][vLocationy] = floatstr(arrCoords[2]);
            CarInfo[idx][vLocationz] = floatstr(arrCoords[3]);
            CarInfo[idx][vAngle] = floatstr(arrCoords[4]);
            CarInfo[idx][vColorOne] = strval(arrCoords[5]);
            CarInfo[idx][vColorTwo] = strval(arrCoords[6]);
            strmid(CarInfo[idx][vOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
            strmid(CarInfo[idx][vDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            CarInfo[idx][vValue] = strval(arrCoords[9]);
            CarInfo[idx][vLicense] = strval(arrCoords[10]);
            CarInfo[idx][vOwned] = strval(arrCoords[11]);
            CarInfo[idx][vLock] = strval(arrCoords[12]);
            printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][vOwner],CarInfo[idx][vLicense]);
            idx++;
        }
    }
    return 1;
}
.. Yes, that's my LoadCar function that I have under OnGameModeInit so I can use my enums? But I don't know how to make the buy car command which is what I'm trying to do..


I have:
pawn Код:
CarInfo[idx][vModel] = 560;
            CarInfo[idx][vLocationx] = 559.5988;
            CarInfo[idx][vLocationy] = -1267.7670;
            CarInfo[idx][vLocationz] = 17.2422;
            CarInfo[idx][vAngle] = 90.00;
            CarInfo[idx][vColorOne] = 0;
            CarInfo[idx][vColorTwo] = 0;
            strmid(CarInfo[idx][vOwner], PlayerName(playerid), 0, strlen(PlayerName(playerid)), 255);
            strmid(CarInfo[idx][vDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            CarInfo[idx][vValue] = 20000;
            CarInfo[idx][vLicense] = 1;
            CarInfo[idx][vOwned] = 1;
            CarInfo[idx][vLock] = 0;
But I haven't defined idx because I don't know how..
Reply
#4

new idx; ?
Reply
#5

But that wouldn't link it within the LoadCar function?
Reply
#6

Ok now I'm confused, tell me what you want to do, exactly what you want to do.
Reply
#7

So I have the LoadCar() function that loads and gets linked with CarInfo, Which is this:
pawn Код:
enum vInfo
{
    vModel,
    Float:vLocationx,
    Float:vLocationy,
    Float:vLocationz,
    Float:vAngle,
    vColorOne,
    vColorTwo,
    vOwner[MAX_PLAYER_NAME],
    vDescription[MAX_PLAYER_NAME],
    vValue,
    vLicense,
    vRegistration,
    vOwned,
    vLock,
    ownedvehicle,
};
new CarInfo[456][vInfo];
So looking at the LoadCar() function, I need to practically make a buycar command, I have a SaveCars() function also, which uses the vInfo enums', which get set when you buy a car...

SaveCars:
pawn Код:
public SaveCars()
{
    new idx;
    new File: file2;
    while (idx < sizeof(CarInfo))
    {
        new coordsstring[256];
        format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%s,%d,%d\n",
        CarInfo[idx][vModel],
        CarInfo[idx][vLocationx],
        CarInfo[idx][vLocationy],
        CarInfo[idx][vLocationz],
        CarInfo[idx][vAngle],
        CarInfo[idx][vColorOne],
        CarInfo[idx][vColorTwo],
        CarInfo[idx][vOwner],
        CarInfo[idx][vDescription],
        CarInfo[idx][vValue],
        CarInfo[idx][vLicense],
        CarInfo[idx][vOwned],
        CarInfo[idx][vLock]);
        if(idx == 0)
        {
            file2 = fopen("CarOwnership.cfg", io_write);
        }
        else
        {
            file2 = fopen("CarOwnership.cfg", io_append);
        }
        fwrite(file2, coordsstring);
        idx++;
        fclose(file2);
    }
    return 1;
}
Reply
#8

Oh so you want to create a vehicle buy command, lol, the bad thing is that I don't really know how to use the "File Functions" all I used was dini and MySQL so, sorry bro. I really hope someone helps you with this. BTW change it to another file saving system.
Reply
#9

It's not really about knowing file system, because that's already done.. I wish i could explain so you'd understand.. I need to learn how to link the player id with the enum.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)