PDA

View Full Version : Vehicle UID, need help


HondaCBR
31/12/2011, 11:42 PM
I download a well working car system, the problem is that it doens't have a buy car command, it had 3 cars in scriptfiles/Auta 0.cfg 1.cfg 2.cfg and when you do things like spawn the car you have to provide the UID (eg. /car spawn 0)

So I made a /buysultan command to start of with. The only thing IDK how to do was to make a new ID, lets say there are 4 cars in the scriptfiles (0.cfg,1.cfg,2.cfg,3.cfg) How can does settings get stored in a file called 4.cfg?

And as I pointed out in the script, please check if name saving is right.


if(strcmp(cmd, "/buysultan", true) == 0)
{
new CarFile[35];

format(CarFile,sizeof(CarFile),"Auta/%d.ini",Car[playerid][UID]);

new Float:vInfo[5];
vInfo[0] = 1270.6603;
vInfo[1] = -1397.4448;
vInfo[2] = 12.5259;
vInfo[3] = 3.5967;
vInfo[4] = 1000;
new Damage[4];
Damage[0] = 0;
Damage[1] = 0;
Damage[2] = 0;
Damage[3] = 0;
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,48);

dini_IntSet(CarFile,"Spawned",1);
dini_IntSet(CarFile,"Locked",0);
dini_IntSet(CarFile,"ModelID",560);
dini_Set(CarFile,"Owner",name);//Im not sure which dini to use for playername, tell me if this is right.
dini_FloatSet(CarFile,"X",vInfo[0]);
dini_FloatSet(CarFile,"Y",vInfo[1]);
dini_FloatSet(CarFile,"Z",vInfo[2]);
dini_FloatSet(CarFile,"A",vInfo[3]);
dini_FloatSet(CarFile,"Health",vInfo[4]);
dini_IntSet(CarFile,"Panels",Damage[0]);
dini_IntSet(CarFile,"Doors",Damage[1]);
dini_IntSet(CarFile,"Lights",Damage[2]);
dini_IntSet(CarFile,"Tires",Damage[3]);
dini_IntSet(CarFile,"Color1",3);
dini_IntSet(CarFile,"Color2",3);
dini_IntSet(CarFile,"PAINTJOB",-1);
dini_IntSet(CarFile,"SPOILER",-1);
dini_IntSet(CarFile,"HOOD",-1);
dini_IntSet(CarFile,"ROOF",-1);
dini_IntSet(CarFile,"SIDESKIRT",-1);
dini_IntSet(CarFile,"LAMPS",-1);
dini_IntSet(CarFile,"NITRO",-1);
dini_IntSet(CarFile,"EXHAUST",-1);
dini_IntSet(CarFile,"WHEELS",-1);
dini_IntSet(CarFile,"STEREO",-1);
dini_IntSet(CarFile,"HYDRAULICS",-1);
dini_IntSet(CarFile,"FRONT_BUMPER",-1);
dini_IntSet(CarFile,"REAR_BUMPER",-1);
dini_IntSet(CarFile,"VENT_RIGHT",-1);
dini_IntSet(CarFile,"VENT_LEFT",-1);

Car[playerid][VehicleGameID] = CreateVehicle(dini_Int(CarFile,"ModelID"),dini_Float(CarFile,"X"),dini_Float(CarFile,"Y"),dini_Float(CarFile,"Z"),dini_Float(CarFile,"A"),dini_Int(CarFile,"Color1"),dini_Int(CarFile,"Color2"),-1);
}

Jefff
01/01/2012, 12:43 AM
new str[24];
for(new d=0; d < MAX_CARS; d++)
{
format(str,sizeof(str),"/Cars/%d.cfg",d);
if(!fexist(str)) // first empty slot
{
// create a file
break;
}
}

HondaCBR
01/01/2012, 07:34 AM
IT does work but, i had a 0.ini file, then I bought a sultan and it created 47.ini, Also I bought like 10 of them and only one of them saved to file the 47.ini one, no more files were created.

if(strcmp(cmd, "/buysultan", true) == 0)
{
new CarFile[35];
new str[24];
for(new d=0; d < MAX_VEHICLES; d++)//is it alrgiht if I use MAX_VEHICLES? I dont have MAX_CARS defined.
{
format(str,sizeof(str),"/Auta/%d.cfg",d);
if(!fexist(str)) // first empty slot
{
format(CarFile,sizeof(CarFile),"/Auta/%d.ini",str);
dini_Create(CarFile);
break;
}
}
new Float:vInfo[5];
vInfo[0] = 1270.6603;
vInfo[1] = -1397.4448;
vInfo[2] = 12.5259;
vInfo[3] = 3.5967;
vInfo[4] = 1000;
new Damage[4];
Damage[0] = 0;
Damage[1] = 0;
Damage[2] = 0;
Damage[3] = 0;
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,48);

dini_IntSet(CarFile,"Spawned",1);
dini_IntSet(CarFile,"Locked",0);
dini_IntSet(CarFile,"ModelID",560);
dini_Set(CarFile,"Owner",name);//Im not sure which dini to use for playername, tell me if this is right.
dini_FloatSet(CarFile,"X",vInfo[0]);
dini_FloatSet(CarFile,"Y",vInfo[1]);
dini_FloatSet(CarFile,"Z",vInfo[2]);
dini_FloatSet(CarFile,"A",vInfo[3]);
dini_FloatSet(CarFile,"Health",vInfo[4]);
dini_IntSet(CarFile,"Panels",Damage[0]);
dini_IntSet(CarFile,"Doors",Damage[1]);
dini_IntSet(CarFile,"Lights",Damage[2]);
dini_IntSet(CarFile,"Tires",Damage[3]);
dini_IntSet(CarFile,"Color1",3);
dini_IntSet(CarFile,"Color2",3);
dini_IntSet(CarFile,"PAINTJOB",-1);
dini_IntSet(CarFile,"SPOILER",-1);
dini_IntSet(CarFile,"HOOD",-1);
dini_IntSet(CarFile,"ROOF",-1);
dini_IntSet(CarFile,"SIDESKIRT",-1);
dini_IntSet(CarFile,"LAMPS",-1);
dini_IntSet(CarFile,"NITRO",-1);
dini_IntSet(CarFile,"EXHAUST",-1);
dini_IntSet(CarFile,"WHEELS",-1);
dini_IntSet(CarFile,"STEREO",-1);
dini_IntSet(CarFile,"HYDRAULICS",-1);
dini_IntSet(CarFile,"FRONT_BUMPER",-1);
dini_IntSet(CarFile,"REAR_BUMPER",-1);
dini_IntSet(CarFile,"VENT_RIGHT",-1);
dini_IntSet(CarFile,"VENT_LEFT",-1);

Car[playerid][VehicleGameID] = CreateVehicle(dini_Int(CarFile,"ModelID"),dini_Float(CarFile,"X"),dini_Float(CarFile,"Y"),dini_Float(CarFile,"Z"),dini_Float(CarFile,"A"),dini_Int(CarFile,"Color1"),dini_Int(CarFile,"Color2"),-1);
}

HondaCBR
01/01/2012, 11:03 AM
Anyone knows why this happens?

HondaCBR
01/01/2012, 12:46 PM
... As no one wanted to help for a while now, During that time I manged to do the command myself, So Ill post the fixed version just in case anyone will search for this who wants one.


if(strcmp(cmd, "/buy2", true) == 0)
{
new CarFile[35];

new id = GenerateID();
format(CarFile,sizeof (CarFile),"/Auta/%d.ini",id);
dini_Create(CarFile);

new Float:vInfo[5];
vInfo[0] = 1270.6603;
vInfo[1] = -1397.4448;
vInfo[2] = 12.5259;
vInfo[3] = 3.5967;
vInfo[4] = 1000;
new Damage[4];
Damage[0] = 0;
Damage[1] = 0;
Damage[2] = 0;
Damage[3] = 0;
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,48);

dini_IntSet(CarFile,"Spawned",1);
dini_IntSet(CarFile,"Locked",0);
dini_IntSet(CarFile,"ModelID",560);
dini_Set(CarFile,"Owner",name);//Im not sure which dini to use for playername, tell me if this is right.
dini_FloatSet(CarFile,"X",vInfo[0]);
dini_FloatSet(CarFile,"Y",vInfo[1]);
dini_FloatSet(CarFile,"Z",vInfo[2]);
dini_FloatSet(CarFile,"A",vInfo[3]);
dini_FloatSet(CarFile,"Health",vInfo[4]);
dini_IntSet(CarFile,"Panels",Damage[0]);
dini_IntSet(CarFile,"Doors",Damage[1]);
dini_IntSet(CarFile,"Lights",Damage[2]);
dini_IntSet(CarFile,"Tires",Damage[3]);
dini_IntSet(CarFile,"Color1",3);
dini_IntSet(CarFile,"Color2",3);
dini_IntSet(CarFile,"PAINTJOB",-1);
dini_IntSet(CarFile,"SPOILER",-1);
dini_IntSet(CarFile,"HOOD",-1);
dini_IntSet(CarFile,"ROOF",-1);
dini_IntSet(CarFile,"SIDESKIRT",-1);
dini_IntSet(CarFile,"LAMPS",-1);
dini_IntSet(CarFile,"NITRO",-1);
dini_IntSet(CarFile,"EXHAUST",-1);
dini_IntSet(CarFile,"WHEELS",-1);
dini_IntSet(CarFile,"STEREO",-1);
dini_IntSet(CarFile,"HYDRAULICS",-1);
dini_IntSet(CarFile,"FRONT_BUMPER",-1);
dini_IntSet(CarFile,"REAR_BUMPER",-1);
dini_IntSet(CarFile,"VENT_RIGHT",-1);
dini_IntSet(CarFile,"VENT_LEFT",-1);

Car[playerid][VehicleGameID] = CreateVehicle(dini_Int(CarFile,"ModelID"),dini_Float(CarFile,"X"),dini_Float(CarFile,"Y"),dini_Float(CarFile,"Z"),dini_Float(CarFile,"A"),dini_Int(CarFile,"Color1"),dini_Int(CarFile,"Color2"),-1);
}


stock GenerateID()
{
for(new i = 0; i < M_VEHICLES; i++)
{
new file[64];format(file,sizeof file,"/Auta/%d.ini",i);
if(!fexist(file)) return i;
}
return -1;
}