Vice City: Multiplayer

VC:MP Discussion => Support => Topic started by: kennedyarz on Sep 06, 2017, 02:24 AM

Title: Vehicles ID's
Post by: kennedyarz on Sep 06, 2017, 02:24 AM
I have a doubt. good and is a problem that is happening in my script and I do not know or better said. I do not remember how to solve it. I happen to have a database with this structure.
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FCsLDF2u.png&hash=f682a165b6670b6f5c87ed5aa39a412af53593cb)

Suppose you create 100 Vehicles. then delete the first 30. But these vehicles as seen have an ID in the database. then I would start counting from 31 onwards. but with this function "+ Vehicle.ID +" will not start reading from 31 if not from the first, then when the player gets into a car it reads in the "+ Vehicle.ID +" but as we know it is different from the ID that exits in the database, so when the player enters the vehicle the Owner appears "NULL". how to avoid this ???
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FFITQb7T.png&hash=8396f83fcedbab499520f55c1a7b1116c3cb321b)
Title: Re: Vehicles ID's
Post by: KAKAN on Sep 06, 2017, 02:47 AM
update the IDs. Simple.
Title: Re: Vehicles ID's
Post by: kennedyarz on Sep 06, 2017, 02:56 AM
Quote from: KAKAN on Sep 06, 2017, 02:47 AMupdate the IDs. Simple.

already knew. but how should be the function? to update ids?
Title: Re: Vehicles ID's
Post by: DizzasTeR on Sep 06, 2017, 11:19 AM
Either don't have a PRIMERY ID like you have now, or just re-alter the table so they get re-counted from 1. This ofcourse affects every ID on server which means you have to destroy all the vehicles and re-create them with the new reference IDs of the database for proper updating.
Title: Re: Vehicles ID's
Post by: kennedyarz on Sep 06, 2017, 11:38 AM
Quote from: Doom_Kill3R on Sep 06, 2017, 11:19 AMEither don't have a PRIMERY ID like you have now, or just re-alter the table so they get re-counted from 1. This ofcourse affects every ID on server which means you have to destroy all the vehicles and re-create them with the new reference IDs of the database for proper updating.

all right. but do you know the method to count from vehicle 1 and change your id in the database? is that I will always be removing vehicles from the server, which means that I must compile IDs as it is a great job to delete the database and create it again every time a vehicle is deleted. any idea how to do it?
Title: Re: Vehicles ID's
Post by: kennedyarz on Sep 06, 2017, 12:21 PM
Does this work well? or cause some error? and what mistakes?
   function ResetIDs()
    {
        local q = QuerySQL(db,"SELECT ID FROM Vehicles");
        for(local i = 1; i < 2500; i++)
        {
            local veh = FindVehicle( i );
            if (veh)
{
                QuerySQL(db"UPDATE Vehicles SET ID='"+veh.ID+"' WHERE ID='"+GetSQLColumnData(q,0)+"'");
                GetSQLNextRow( q );
print("Vehicles Loaded - "+i);
            }
        }
    }

retarded
Title: Re: Vehicles ID's
Post by: Anik on Sep 06, 2017, 03:19 PM
Execute this on "Execute SQL" on the DB Browser.
UPDATE Vehicles SET ID = rowid
Title: Re: Vehicles ID's
Post by: kennedyarz on Sep 06, 2017, 06:57 PM
Quote from: Anik on Sep 06, 2017, 03:19 PMExecute this on "Execute SQL" on the DB Browser.
UPDATE Vehicles SET ID = rowid

the command does not work well, says that it runs without problems but does not change its ID's to the same value as rowid, probe with other commands and worked, but with that not.
Title: Re: Vehicles ID's
Post by: ! on Sep 18, 2017, 05:19 AM
Use this function and then restart your server
function ResetIDs()
    {
    local q = QuerySQL(db,"SELECT ID FROM Vehicles"), i = 1;
    while( GetSQLColumnData( q, 0 ) != null )
       {
       QuerySQL(db"UPDATE Vehicles SET ID='"+i+"' WHERE ID='"+GetSQLColumnData(q,0)+"'");
       i++;
       GetSQLNextRow( q );
       }
    FreeQuery( q );
    print("Vehicles Loaded - "+i);
    }

 :edit:
P.S: After using above function don't use this
UPDATE Vehicles SET ID = rowid
Cause it will change the ids to the one used upon INSERT
Title: Re: Vehicles ID's
Post by: Sandisk on Jun 10, 2023, 12:43 AM
Quote from: ! on Sep 18, 2017, 05:19 AMUse this function and then restart your server
function ResetIDs()
    {
    local q = QuerySQL(db,"SELECT ID FROM Vehicles"), i = 1;
    while( GetSQLColumnData( q, 0 ) != null )
      {
      QuerySQL(db"UPDATE Vehicles SET ID='"+i+"' WHERE ID='"+GetSQLColumnData(q,0)+"'");
      i++;
      GetSQLNextRow( q );
      }
    FreeQuery( q );
    print("Vehicles Loaded - "+i);
    }

 :edit:
P.S: After using above function don't use this
UPDATE Vehicles SET ID = rowid
Cause it will change the ids to the one used upon INSERT

myproblem: when i create a vehicle in the server it spawns with 243 id when i restart the server it changes into 68 id
so the id 68 is not in the database so i got errors

this function doesn't work and doesn't change the ids in the database

console : "[SCRIPT] Vehicles Count (69)
           [SCRIPT] Vehicles Loaded - 1"