Quote:
Originally Posted by BenzoAMG
Let's just have a quick look over your code.
pawn Код:
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; }
Now let's begin to correct it:
pawn Код:
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 }
Hope I've helped you understand it at least a little bit.
|
Fixed thank you very much, now my second problem, about that setcarcolor