Vehicle IDs cross
#1

Sometimes, the ID certain vehicles cross, and they end up taking eachothers properties. I made it to create all vehicles, dispite if they exist, and then delete those vehicles if they're not supposed to exist. Which works when the server starts.

pawn Код:
if(vInfo[vid][Model] == 0 && vid != 0)
    {
        vid = CreateVehicle(400, 1529.6, -1691.2, 13.3, 0, 0, 0, -1);
        SetVehicleVirtualWorld(vid, 9929);
        return 1;
    }
After they are all loaded:

pawn Код:
public DelCars()
{
    for(new i; i<MAX_VEHICLES; i++)
    {
        if(GetVehicleVirtualWorld(i) == 9929) DestroyVehicle(i);
    }
    return 1;
}
Now, i'm sure there is a better way to handle that, besides creating and removing. But anyhow, it seems that the odd time, ids will swap. For example, there was a vehicle with model 490, that ended up as a freeway.

I think it might happen on vehicle park.

pawn Код:
CMD:vpark(playerid, params[])
{
    if(GetPlayerState(playerid) == 2)
     {
        new vid = GetPlayerVehicleID(playerid);
        if(strmatch(vInfo[vid][Owner], pInfo[playerid][Name]))
         {
            new Float:X, Float:Y, Float:Z, Float:A;
            GetVehiclePos(vid, X, Y, Z);
            GetVehicleZAngle(vid, A);
            if(X == 1529.6 && Y == -1691.2 && Z == 13.3) return ErrorMessage(playerid, "You cannot park your vehicle here.");
            vInfo[vid][SpawnX] = X;
            vInfo[vid][SpawnY] = Y;
            vInfo[vid][SpawnZ] = Z;
            vInfo[vid][SpawnA] = A;
            vInfo[vid][SpawnVW] = GetPlayerVirtualWorld(playerid);
            vInfo[vid][SpawnInt] = GetPlayerInterior(playerid);

            DestroyVehicle(vid);

            vid = CreateVehicle(vInfo[vid][Model], vInfo[vid][SpawnX], vInfo[vid][SpawnY], vInfo[vid][SpawnZ], vInfo[vid][SpawnA], vInfo[vid][Col1], vInfo[vid][Col2], -1);
            LinkVehicleToInterior(vid, vInfo[vid][SpawnInt]);
            SetVehicleVirtualWorld(vid, vInfo[vid][SpawnVW]);

            SetVehicleParamsEx(vid, 0, 0, 0, 1, 0, 0, 0);

            SaveVehicle(vid);
           
            return 1;
           }
    }
    return 1;
}
Reason being is, if vehicle ID 3 was deleted, then if you park vehicle id 5, it will take id 3, and therefore save to id 3. Is there a way to force a vehicle to have the proper id?
Reply
#2

Store the ID in a variable and save the vehicle info for that specific variable.
Reply
#3

For a park command, create enough backup variables inside your function to hold all data about your current vehicle, like position, rotation, color, tunings, ...

Let's assume your vehicle had vehicleid 5.

Then destroy the vehicle and cleanup your data (set it to 0) in the array where the vehicle was stored (index 5 of your vinfo array).

Then re-create a new one at the new position where you want to park it using CreateVehicle.
You will be given a new vehicleid, let's assume it's 3 now.

Then store the temporary data from your backup variables into index 3 of your vinfo array.



You could also keep the data at index 5, destroy the vehicle, re-create it using data from index 5, then copy the data from index 5 to index 3 and finally clear all data at index 5.
Reply
#4

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
For a park command, create enough backup variables inside your function to hold all data about your current vehicle, like position, rotation, color, tunings, ...

Let's assume your vehicle had vehicleid 5.

Then destroy the vehicle and cleanup your data (set it to 0) in the array where the vehicle was stored (index 5 of your vinfo array).

Then re-create a new one at the new position where you want to park it using CreateVehicle.
You will be given a new vehicleid, let's assume it's 3 now.

Then store the temporary data from your backup variables into index 3 of your vinfo array.



You could also keep the data at index 5, destroy the vehicle, re-create it using data from index 5, then copy the data from index 5 to index 3 and finally clear all data at index 5.
Well, I wanted it to always be at 5, to attach objects to vehicles and things. I've figured it out, instead of destroying and re creating the car on park, it updates the spawn position, then, towing the vehicle repairs and teleports. Seems to work just fine, and solve the problem
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)