Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Nihongo^ on Apr 05, 2023, 08:08 PM

Title: /car Vehicle id null
Post by: Nihongo^ on Apr 05, 2023, 08:08 PM
Script read the data from the database

I removed tank and hunter from the database ( ID 132 and 136 ) after that whenever someone type /car it gives this error ( its gives error on some vehicles )

when i used my old database ( which contain tank and hunter ) the function works fine and give the details of every cars

Kindly suggest me what i do now ? i don't want to put back tank and hunter

p.s when i type admin command /spawncar 132 its spawn tank if i remove tank from the database it spawn pizza bike (which gives error)

Quotefunction VehicleInfo( player, veh )
{
  local Query = QuerySQL(vdb, "SELECT * FROM Vehicles WHERE VehID = '"+veh+"' " ),
    VehMod = GetSQLColumnData( Query, 0 ),
    VehOwner = GetSQLColumnData( Query, 4 ),
    VehCost = GetSQLColumnData( Query, 5 ),
    VehShared = GetSQLColumnData( Query, 6 ),
  VehID = GetSQLColumnData( Query, 7 ),
  HP = player.Vehicle.Health / 10;

    SendMessage( "Vehicle: "+GetVehicleNameFromModel( VehMod )+", ID: "+VehID+", Health: "+HP+" Price: "+VehCost+", Owner: "+VehOwner+", Shared With: "+VehShared+".", player );

FreeSQLQuery( Query );
}
(https://i.postimg.cc/HxQ30wcg/image.png)
Title: Re: /car Vehicle id null
Post by: habi on Apr 05, 2023, 10:14 PM
Show your onPlayerCommand function for cmd == "car".
Title: Re: /car Vehicle id null
Post by: Nihongo^ on Apr 06, 2023, 06:10 AM
Quote from: habi on Apr 05, 2023, 10:14 PMShow your onPlayerCommand function for cmd == "car".

  else if ( ( cmd == "car" ) || ( cmd == "veh" ) )
{
  if ( !player.IsSpawned ) ErrorMessage("[#FF0000][Server] - [#FFFFFF]You need to be spawned to use this command.", player );
  else if ( !player.Vehicle ) ErrorMessage( "[#FF0000][Server] - [#FFFFFF]You need to be in a vehicle to use this command", player );
  else
  {
    local veh = player.Vehicle.ID;
    VehicleInfo( player, veh );
   
  }
}
Title: Re: /car Vehicle id null
Post by: habi on Apr 06, 2023, 09:24 AM
Solution 1 (without modifying database)
In your onPlayerCommand, make the following change for cmd=="car"
VehicleInfo( player, veh>131? ++veh>135? ++veh:veh:veh);Explanation:
If id > 131
   if ++id > 135
      return ++id
   else
      return id (this id is 1 greater)
else
   return id (original id)

Solution 2 (Database modification)
Execute the two sql commands (make backup of db before). Then 'VehID' column of the table will be continuous. You are getting error because at 132 and 136,  there is no row.
//This will decrease vehicle Id from 133 to last by 1
UPDATE Vehicles SET VehID = VehID - 1 WHERE VehID > 132 ;

//This will do the same for VehId from 137
UPDATE Vehicles SET VehID = VehID - 1 WHERE VehID > 136 ;

Execute the above commands as strings passed to QuerySQL function or use sqlite database viewer.