Getting ID of Vehicle from file -
cloudysky - 21.04.2015
Hi again, another hurdle is in the way with my vehicle script haha this time its retrieving the FileID number of a car.
For example I want to be able to use the command /fileid with it responding 'This File ID is 1" (For the first car saved) etc So i know what cars to remove! I use DINI, i know its outdated.
Thanks in advance.
Re: Getting ID of Vehicle from file -
Sithis - 21.04.2015
Do you have your code and an exampe ini file for a vehicle?
Re: Getting ID of Vehicle from file -
cloudysky - 21.04.2015
EDIT:
This is what I now have, the problem is that it comes up all the cars in the server not just that individual car id. So for example if there is 4 cars on the server, i get in and it goes:
Car 1
Car 2
Car 3
Car 4
Instead of just Car 2.
This is the code
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new Vehiclefile[256];
for(new i = 1; i < MAX_VEHICLES; i++)
{
format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", i);
if(fexist(Vehiclefile) )
{
Vehicles[i][FILEID] = dini_Int(Vehiclefile, "FILEID");
new string[128];
format(string, sizeof(string), "Car %d", Vehicles[i][FILEID]);
SendClientMessage(playerid, COLOUR_PURPLE, string);
}
}
return 1;
}
Re: Getting ID of Vehicle from file -
[KHK]Khalid - 21.04.2015
Okay, I understand what you're trying to do there, but this isn't the way to go. It should be easier if you assign the file-id of each vehicle to
Vehicles[i][FILEID] while CREATING & LOADING it from files (i.e LoadVehicles, show me that function in your script if you can).
Re: Getting ID of Vehicle from file -
Sithis - 21.04.2015
Yes, Khalid is right. I also suggest assigning the appropriate fileid to Vehicles[i][FILEID] during the
loading of every vehicle.
During OnPlayerEnterVehicle, you can then simply lookup the fileid by selecting the proper vehicleid, and you're done.
Re: Getting ID of Vehicle from file -
cloudysky - 21.04.2015
Thanks for the response, I've been at work so a bit late replying..
Re: Getting ID of Vehicle from file -
[KHK]Khalid - 22.04.2015
Fine! I see that you're already assigning the file-id to its variable, then your OnPlayerEnterVehicle code could just be like this:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new Vehiclefile[256];
format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", vehicleid);
if(fexist(Vehiclefile))
{
Vehicles[i][FILEID] = dini_Int(Vehiclefile, "FILEID");
new string[128];
format(string, sizeof(string), "Car %d", Vehicles[i][FILEID]);
SendClientMessage(playerid, COLOUR_PURPLE, string);
}
return 1;
}
Though, I have some notes on your code:
1. Isn't 256 too much for your strings? Have you done your measurement or you're just dropping numbers? Stop wasting memory! Also why more strings when could be less, for example:
Instead of this:
pawn Код:
new Vehiclefile[256];
format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", vehicleid);
if(fexist(Vehiclefile))
{
Vehicles[i][FILEID] = dini_Int(Vehiclefile, "FILEID");
new string[128];
format(string, sizeof(string), "Car %d", Vehicles[i][FILEID]);
SendClientMessage(playerid, COLOUR_PURPLE, string);
}
You could do this, you can format strings twice and more if you want (unless you're gonna need to use them later):
pawn Код:
new string[appropriate size here for both uses];
format(string, sizeof(string), "vehicles/Vehicle_%d.ini", vehicleid);
if(fexist(string))
{
Vehicles[i][FILEID] = dini_Int(string, "FILEID");
format(string, sizeof(string), "Car %d", Vehicles[i][FILEID]);
SendClientMessage(playerid, COLOUR_PURPLE, string);
}
2. I have a feeling that you will probably face other problems in the future by the look of this:
pawn Код:
SpawnedVehicles++;
new id = SpawnedVehicles;
new Vehiclefile[256];
format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", id);
I think you're mixing up vehicle FileIDs and in-game vehicleids, however I could be wrong, it's your system anyway and you should know better.