stock GetFreeVehicleSlot()
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
new string[1000];
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", i);
if(fexist(string)) return i+1;
}
return -1;
}
command(setcarcolor, playerid, params[])
{
new col1, col2;
if(sscanf(params, "dd", col1, col2))
{
if(Player[playerid][AdminLevel] >= 4)
{
SendClientMessage(playerid, WHITE, "SYNTAX: /setcarcolor [color1] [color2]");
}
}
else
{
if(Player[playerid][AdminLevel] >= 4)
{
if(IsPlayerInAnyVehicle(playerid))
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(Vehicles[i][CarID] == GetPlayerVehicleID(playerid))
{
new string[128];
{
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", i);
}
if(fexist(string))
{
Vehicles[i][Col1] = col1;
Vehicles[i][Col2] = col2;
ChangeVehicleColor(i, col1, col2);
SaveExistingVehicle(i);
}
else
{
SendClientMessage(playerid, WHITE, "This is not a saved car!");
}
}
}
}
}
}
return 1;
}
stock GetFreeVehicleSlot()
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
new string[1000];
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", i);
if(fexist(string)) continue;
else if(!fexist(string)) return i;
}
return -1;
}
stock GetFreeVehicleSlot() //You will use GetFreeVehicleSlot() to get available IDs
{
for(new i = 0; i < MAX_VEHICLES; i++) //You start the loop correctly
{
new string[1000]; //You have an EXTREMELY oversized string which will take up alot of usage.
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", i); //You format the file to see if it exists
if(fexist(string)) return i+1; //This is where you are going wrong (and the string size), basically, if the file exists, you are saying the next available file is the file with a value of 1 more than this. So if file 1 exists, it will return file 2, but file 2 already exists...
}
return -1;
}
stock GetFreeVehicleSlot()
{
new string[40];
for(new i = 0; i < MAX_VEHICLES; i++)
{
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", i); //format the file
if(fexist(string)) continue; //If the file exists, go to the next file
return i; //If the file doesn't exist, then we have an available slot, and we return the number/value of 'i'
}
return -1; //return -1 or INVALID_VEHICLE_ID for no available files
}
Let's just have a quick look over your code.
pawn Код:
pawn Код:
|
command(setcarcolor, playerid, params[])
{
new col1, col2;
if(sscanf(params, "dd", col1, col2))
{
if(Player[playerid][AdminLevel] >= 4)
{
SendClientMessage(playerid, WHITE, "SYNTAX: /setcarcolor [color1] [color2]");
}
}
else
{
if(Player[playerid][AdminLevel] >= 4)
{
if(IsPlayerInAnyVehicle(playerid))
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
new string[128];
{
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", i);
}
if(fexist(string))
{
if(Vehicles[i][CarID] == GetPlayerVehicleID(playerid))
{
Vehicles[i][Col1] = col1;
Vehicles[i][Col2] = col2;
ChangeVehicleColor(i, col1, col2);
SaveExistingVehicle(i);
}
else
{
SCM(playerid, RED, "WTFFFFFFFFFFFFFF");
}
}
else
{
SendClientMessage(playerid, WHITE, "This is not a saved car!");
}
}
}
}
}
return 1;
}
About the first code, i think this will work:
pawn Код:
|
stock SaveExistingVehicle(carid)
{
new string[36];
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", carid);
if(fexist(string))
{
dini_IntSet(string, "FactionCar", 0);
dini_IntSet(string, "Model", Vehicles[carid][Model]);
dini_FloatSet(string, "XSpawn", Vehicles[carid][xspawn]);
dini_FloatSet(string, "YSpawn", Vehicles[carid][yspawn]);
dini_FloatSet(string, "ZSpawn", Vehicles[carid][zspawn]);
dini_FloatSet(string, "AngleSpawn", Vehicles[carid][anglespawn]);
dini_IntSet(string, "VirtualWorld", Vehicles[carid][VirtualWorld]);
dini_IntSet(string, "InteriorID", Vehicles[carid][InteriorID]);
dini_IntSet(string, "Color1", Vehicles[carid][Col1]);
dini_IntSet(string, "Color2", Vehicles[carid][Col2]);
dini_IntSet(string, "CarGroup", Vehicles[carid][CarGroup]);
dini_IntSet(string, "RentalCar", -1);
dini_Set(string, "vOwner", Vehicles[carid][vOwner]);
dini_Set(string, "Plate", Vehicles[carid][Plate]);
}
return 1;
}
for(new i = 0; i < MAX_VEHICLES; i++)
{
new string[40];
format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", i);
if(!fexist(string)) continue;
if(Vehicles[i][CarID] == GetPlayerVehicleID(playerid))
{
Vehicles[i][Col1] = col1;
Vehicles[i][Col2] = col2;
ChangeVehicleColor(i, col1, col2);
SaveExistingVehicle(i);
}
}