SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 09/08/2011, 09:44 AM   #1
Jack_Leslie
High-roller
 
Jack_Leslie's Avatar
 
Join Date: Feb 2011
Location: Australia
Posts: 1,197
Reputation: 98
Default Dealership help,

Hi guys,
so I have this code when a player buys a car:
pawn Code:
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 Code:
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.
__________________
lol
Jack_Leslie is offline  
Old 09/08/2011, 09:51 AM   #2
Tee
Gangsta
 
Join Date: Sep 2010
Posts: 836
Reputation: 81
Default Re: Dealership help,

Try this:

pawn Code:
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.
__________________
1.3 inch/360 - pretty high for precision
Tee is offline  
Old 09/08/2011, 09:53 AM   #3
Jack_Leslie
High-roller
 
Jack_Leslie's Avatar
 
Join Date: Feb 2011
Location: Australia
Posts: 1,197
Reputation: 98
Default Re: Dealership help,

Quote:
Originally Posted by Tee View Post
pawn Code:
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 Code:
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..
__________________
lol
Jack_Leslie is offline  
Old 09/08/2011, 09:54 AM   #4
Tee
Gangsta
 
Join Date: Sep 2010
Posts: 836
Reputation: 81
Default Re: Dealership help,

new idx; ?
__________________
1.3 inch/360 - pretty high for precision
Tee is offline  
Old 09/08/2011, 09:57 AM   #5
Jack_Leslie
High-roller
 
Jack_Leslie's Avatar
 
Join Date: Feb 2011
Location: Australia
Posts: 1,197
Reputation: 98
Default Re: Dealership help,

But that wouldn't link it within the LoadCar function?
__________________
lol
Jack_Leslie is offline  
Old 09/08/2011, 10:04 AM   #6
Tee
Gangsta
 
Join Date: Sep 2010
Posts: 836
Reputation: 81
Default Re: Dealership help,

Ok now I'm confused, tell me what you want to do, exactly what you want to do.
__________________
1.3 inch/360 - pretty high for precision
Tee is offline  
Old 09/08/2011, 10:09 AM   #7
Jack_Leslie
High-roller
 
Jack_Leslie's Avatar
 
Join Date: Feb 2011
Location: Australia
Posts: 1,197
Reputation: 98
Default Re: Dealership help,

So I have the LoadCar() function that loads and gets linked with CarInfo, Which is this:
pawn Code:
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 Code:
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;
}
__________________
lol
Jack_Leslie is offline  
Old 09/08/2011, 10:13 AM   #8
Tee
Gangsta
 
Join Date: Sep 2010
Posts: 836
Reputation: 81
Default Re: Dealership help,

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.
__________________
1.3 inch/360 - pretty high for precision
Tee is offline  
Old 09/08/2011, 10:15 AM   #9
Jack_Leslie
High-roller
 
Jack_Leslie's Avatar
 
Join Date: Feb 2011
Location: Australia
Posts: 1,197
Reputation: 98
Default Re: Dealership help,

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.
__________________
lol
Jack_Leslie is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Car Dealership? akif Help Archive 2 29/06/2011 05:17 PM
Dealership help THE_KNOWN Help Archive 4 25/01/2011 11:57 PM
Car Dealership [HELP...!] Cristiano[TW[ Help Archive 14 25/01/2011 09:11 PM
Car dealership [I will pay] yarrum3 Help Archive 0 19/01/2011 05:14 AM
Dealership :: IceKilla :: Help Archive 3 21/12/2009 02:35 PM


All times are GMT. The time now is 06:15 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.