Question regarding vehicle system
#1

Well hello there, I am facing an issue with the vehicle system I am having. Let me get straight into it.

I am looping, then loading the data based on the loop id. Let's say we have 3 cars.

Car File 1 - Loaded.
Car File 2- Loaded.
Car File 3 - Loaded.

It works perfect if the numbers are one after one but what I am facing is, if car file 2 was deleted. Since it's samp so it takes the empty vehicle id. It takes 2. But the loop id is 3. therefore in the vehicle ID 2 variables will not be set.
Example:
Car File 1 - Loaded.
Car File 2 - NOT FOUND (continue)
Car File 3 - Loaded. But the vehicle ingame ID is 2 not 3.


If something is not clear please tell me and I'm hoping someone is familiar with this issue.


Thanks.
Reply
#2

That system is not perfect, and it's one of issues you'll face. You can monkey-patch this by creating some hidden vehicles to fill the id gaps, and then remove them so you can reclaim vehicle id for new cars. Better solution is to not rely on constantess of the vehicle id. Keep additional value - unique index - of a vehicle, and operate on that value instead. Only drawback would be that you couldn't use value of GetPlayerVehicleID directly, but you'd have to store meta data like
pawn Код:
new VehicleIndexes[MAX_VEHICLES] = { 0, ... };
//Load vehicle with unique index 8
new newcarid = CreateVehicle(...);
VehicleIndexes[newcarid] = Value of your unique index.
Reply
#3

pawn Код:
new car[3];
new bool:check[3];
for(new i; i < 3; ++i)
{
     for(new x; x < 3; ++x)
     {
           new file[26];
           format(file, sizeof file, "carfile%i", x);
            if(fexist(file))
           {
                 if(!check[x])
                 {
                       car[i] = CreateVehicle(...);
                       check[x] = true;
                       continue;
                  }
            }
     }
}
This will skip the id of the non existing file and turn to the existing one. I am helping you on phone though.
Reply
#4

Quote:
Originally Posted by ginger
Посмотреть сообщение
pawn Код:
new car[3];
new bool:check[3];
for(new i; i < 3; ++i)
{
     for(new x; x < 3; ++x)
     {
           new file[26];
           format(file, sizeof file, "carfile%i", x);
            if(fexist(file))
           {
                 if(!check[x])
                 {
                       car[i] = CreateVehicle(...);
                       check[x] = true;
                       continue;
                  }
            }
     }
}
This will skip the id of the non existing file and turn to the existing one. I am helping you on phone though.
That's not the issue I am having I can skip them non-existing vehicles but if there are 3 vehicle or more and the number two vehicle was removed then they were re-loaded. When a vehicle creates ingame id will be 2. But the variables will be loaded in 3 not 2.
Reply
#5

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
That's not the issue I am having I can skip them non-existing vehicles but if there are 3 vehicle or more and the number two vehicle was removed then they were re-loaded. When a vehicle creates ingame id will be 2. But the variables will be loaded in 3 not 2.
According to the code,
car1 file exist, car1 created with variable car[1]
car 2 file dont exist, car 2 is null
Car3 exists and car 3 created with variable car[2] so car[3] will be null

EDITED RESULT:
pawn Код:
loop 1, car 1, var 1
loop 2, car -, var -
loop 3, car 2, var 2
So it follows the order and vehicle ids will be identical.

If mean something else, try to explain and express more and meaningful.
Reply
#6

pawn Код:
for(new i; i = 1; i < 3; i++)
{
new id = CreateVehicle(..);
printf("ingame id %i loop id %i",id,i);
if(id != i)
{
printf("loop id %i does not match game id %i",i,id);
}
}
Now think of it like that.

Car 1 creates (successfully no issues)
Car 2 not found. (ignores)
Car 3 creates but SA-MP wisely it will find a non-existing vehicle ID and overwrites it, get me? So the ingame id will be 2, therefore variables will be loaded in 3 and id 2 variables will be null even though the car id is 2.

So it will print:
pawn Код:
ingame id 1 loop id 1
ingame id 0 loop id 2
ingame id 2 loop id 3.
Reply
#7

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
pawn Код:
for(new i; i = 1; i < 3; i++)
{
new id = CreateVehicle(..);
printf("ingame id %i loop id %i",id,i);
if(id != i)
{
printf("loop id %i does not match game id %i",i,id);
}
}
Now think of it like that.

Car 1 creates (successfully no issues)
Car 2 not found. (ignores)
Car 3 creates but SA-MP wisely it will find a non-existing vehicle ID and overwrites it, get me? So the ingame id will be 2, therefore variables will be loaded in 3 and id 2 variables will be null even though the car id is 2.

So it will print:
pawn Код:
ingame id 1 loop id 1
ingame id 0 loop id 2
ingame id 2 loop id 3.
Thats what ginger gave you!
Reply
#8

------
Reply
#9

I don't think there is a way to set vehicle ID's.
What you could do though is to create a vehicle even if the file isn't there and delete them when the loop has finished. I don't recommend doing that though, as it will cause an even worse fuss with ID's when you create cars in game then.

Another option is to run a loop when loading the cars. A loop that renames all the files in order.

PHP код:
CreateVehicle(........);
new 
String[100];
format(Stringsizeof(String), "Car %d"vehicleid);
Rename(oldname[], newname[]); 
As for the renaming, you have to take a look around the forum for how to do it.
Reply
#10

I know how to rename files, thanks for your response I'll try doing that and reply with the results.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)