commands /park help pls

Started by Adrenaline, Mar 10, 2017, 03:58 PM

Previous topic - Next topic

Adrenaline

Why not save the location of vehicles used with the / park command when restoring the server?

function onPlayerCommand( player, cmd, text )
{
{
if ( cmd == "park" )
{
local veh = player.Vehicle;
if ( veh )
{
veh.SpawnPos = Vector( veh.Pos.x, veh.Pos.y, veh.Pos.z );
veh.SpawnAngle = veh.Angle;
MessagePlayer( "Parked Vehicle!", player );
}

EK.IceFlake

You need to store it in a database and read it on the next start.

Adrenaline

Quote from: EK.IceFlake on Mar 10, 2017, 04:03 PMYou need to store it in a database and read it on the next start.
How do I get it?

kennedyarz

#3
Then create a database to store the vehicles. Then delete the vehicles that appear in server.config and create new vehicles. Example:

funtion OnScriptLoad()
{
Server <- ConnectSQL( "Server.db" );
QuerySQL( Server, "CREATE TABLE IF NOT EXISTS Vehicles ( ID NUMERIC, Model NUMERIC, PX FLOAT, PY FLOAT, PZ FLOAT, Angle FLOAT, Cor1 NUMERIC, Cor2 NUMERIC, Owner TEXT, Locked NUMERIC, OwnerName TEXT )" );
LoadCars();
}

function OnPlayerCommand( player, cmd )
{
   else if( cmd == "addveh" )
    {
    if ( !text ) MessagePlayer ( "/addveh Name Model" , player );
    else if ( (GetVehicleModelFromName(text).tointeger() < 130) ) MessagePlayer ( "/addveh <130/236>" , player );
    else if ( (GetVehicleModelFromName(text).tointeger() > 236) ) MessagePlayer ( "/addveh <130/236>" , player );
    else if ( (GetVehicleModelFromName(text).tointeger() == 180) ) MessagePlayer ("Model not available" , player );
    else if ( (GetVehicleModelFromName(text).tointeger() == 181) ) MessagePlayer ( "Model not available" , player );
    else
    {
    local i=GetVehicleCount();
    i++;
    local col1=rand() %100;
    local col2=rand() %100;
    local X=player.Pos.x,Y=player.Pos.y,Z=player.Pos.z;
    CreateVehicle( GetVehicleModelFromName(text).tointeger(), 1, Vector( X.tofloat(), Y.tofloat(), Z.tofloat() ), player.Angle, rand() %100, rand() %100 );
    player.Pos.z = player.Pos.z+4;
    QuerySQL( Server, "INSERT INTO Vehicles (  ID , Model , PX , PY , PZ , Angle , Cor1 , Cor2, Owner, Locked, OwnerName   ) VALUES ('"+i+"','"+GetVehicleModelFromName(text).tointeger()+"','"+X+"','"+Y+"','"+Z+"','"+player.Angle+"','"+col1+"','"+col2+"', 'No', '0', 'For Sale' )" );
    }
    }
}

function LoadCars()
{
local i = 0, ID, Model, X, Y, Z, Angle, col1, col2;
local q = QuerySQL(Server, "SELECT * FROM Vehicles" );
while ( GetSQLColumnData( q, 0 ) != null )
{
Model = GetSQLColumnData( q, 1);
X = GetSQLColumnData( q, 2 );
Y = GetSQLColumnData( q, 3 );
Z = GetSQLColumnData( q, 4 );
Angle = GetSQLColumnData( q, 5 );
col1 = GetSQLColumnData( q, 6);
col2 = GetSQLColumnData( q, 7 );
CreateVehicle( Model, 1, Vector( X.tofloat(), Y.tofloat(), Z.tofloat() ), Angle, col1, col2 );
GetSQLNextRow( q );
i++;
}
FreeSQLQuery( q );
print( "Vehicles Loaded: "+ i);
}

Note: not tested

Adrenaline

Quote from: kennedyarz on Mar 10, 2017, 09:22 PMThen create a database to store the vehicles. Then delete the vehicles that appear in server.config and create new vehicles. Example:

funtion OnScriptLoad()
{
Server <- ConnectSQL( "Server.db" );
QuerySQL( Server, "CREATE TABLE IF NOT EXISTS Vehicles ( ID NUMERIC, Model NUMERIC, PX FLOAT, PY FLOAT, PZ FLOAT, Angle FLOAT, Cor1 NUMERIC, Cor2 NUMERIC, Owner TEXT, Locked NUMERIC, OwnerName TEXT )" );
LoadCars();
}

function OnPlayerCommand( player, cmd )
{
   else if( cmd == "addveh" )
    {
    if ( !text ) MessagePlayer ( "/addveh Name Model" , player );
    else if ( (GetVehicleModelFromName(text).tointeger() < 130) ) MessagePlayer ( "/addveh <130/236>" , player );
    else if ( (GetVehicleModelFromName(text).tointeger() > 236) ) MessagePlayer ( "/addveh <130/236>" , player );
    else if ( (GetVehicleModelFromName(text).tointeger() == 180) ) MessagePlayer ("Model not available" , player );
    else if ( (GetVehicleModelFromName(text).tointeger() == 181) ) MessagePlayer ( "Model not available" , player );
    else
    {
    local i=GetVehicleCount();
    i++;
    local col1=rand() %100;
    local col2=rand() %100;
    local X=player.Pos.x,Y=player.Pos.y,Z=player.Pos.z;
    CreateVehicle( GetVehicleModelFromName(text).tointeger(), 1, Vector( X.tofloat(), Y.tofloat(), Z.tofloat() ), player.Angle, rand() %100, rand() %100 );
    player.Pos.z = player.Pos.z+4;
    QuerySQL( Server, "INSERT INTO Vehicles (  ID , Model , PX , PY , PZ , Angle , Cor1 , Cor2, Owner, Locked, OwnerName   ) VALUES ('"+i+"','"+GetVehicleModelFromName(text).tointeger()+"','"+X+"','"+Y+"','"+Z+"','"+player.Angle+"','"+col1+"','"+col2+"', 'No', '0', 'For Sale' )" );
    }
    }
}

function LoadCars()
{
local i = 0, ID, Model, X, Y, Z, Angle, col1, col2;
local q = QuerySQL(Server, "SELECT * FROM Vehicles" );
while ( GetSQLColumnData( q, 0 ) != null )
{
Model = GetSQLColumnData( q, 1);
X = GetSQLColumnData( q, 2 );
Y = GetSQLColumnData( q, 3 );
Z = GetSQLColumnData( q, 4 );
Angle = GetSQLColumnData( q, 5 );
col1 = GetSQLColumnData( q, 6);
col2 = GetSQLColumnData( q, 7 );
CreateVehicle( Model, 1, Vector( X.tofloat(), Y.tofloat(), Z.tofloat() ), Angle, col1, col2 );
GetSQLNextRow( q );
i++;
}
FreeSQLQuery( q );
print( "Vehicles Loaded: "+ i);
}

Note: not tested
error :/

Luis_Labarca

 :)Take this my friend is 100% tested and works 100% ;) :D

function onScriptLoad()
{
Vehicles<- ConnectSQL( "Vehicles.db" );
QuerySQL( Vehicles, "CREATE TABLE IF NOT EXISTS Vehicle ( Model NUMERIC, PosX FLOAT, PosY FLOAT, PosZ FLOAT, AngleX FLOAT, AngleY FLOAT, AngleZ FLOAT, Col1 NUMERIC, Col2 NUMERIC, WorldID NUMERIC)" );
LoadVehicle()
}

function LoadVehicle()
{
local i = 0, ID, Model, X, Y, Z, AngleX, AngleY, AngleZ, Col1, Col2, WorldID;
local q = QuerySQL(Vehicles, "SELECT * FROM Vehicle" );
while ( GetSQLColumnData( q, 0 ) != null )
{
Model = GetSQLColumnData( q, 0);
X = GetSQLColumnData( q, 1 );
Y = GetSQLColumnData( q, 2 );
Z = GetSQLColumnData( q, 3 );
AngleX = GetSQLColumnData( q, 4 );
AngleY = GetSQLColumnData( q, 5 );
AngleZ = GetSQLColumnData( q, 6 );
Col1 = GetSQLColumnData( q, 7);
Col2 = GetSQLColumnData( q, 8 );
WorldID = GetSQLColumnData( q, 9 );
local V=CreateVehicle( Model, WorldID, Vector( X , Y , Z  ), 0 , Col1, Col2 );
V.SpawnPos = Vector( X , Y , Z );
V.SpawnAngle=Vector( AngleX , AngleY , AngleZ );
V.EulerAngle.x=AngleX;
V.EulerAngle.y=AngleY;
V.EulerAngle.z=AngleZ;
GetSQLNextRow( q );
i++;
}
FreeSQLQuery( q );
print( "Vehicle "+ i);
}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "park" )
{
if (player.Vehicle )
{
player.Vehicle.SpawnPos = Vector( player.Vehicle.Pos.x, player.Vehicle.Pos.y, player.Vehicle.Pos.z );
player.Vehicle.SpawnAngle=Vector(player.Vehicle.EulerAngle.x, player.Vehicle.EulerAngle.y, player.Vehicle.EulerAngle.z);
QuerySQL(Vehicles, "UPDATE Vehicle SET PosX='"+player.Vehicle.Pos.x+"',PosY='"+player.Vehicle.Pos.y+"',PosZ='"+player.Vehicle.Pos.z+"', AngleX='"+player.Vehicle.EulerAngle.x+"', AngleY='"+player.Vehicle.EulerAngle.y+"', AngleZ='"+player.Vehicle.EulerAngle.z+"' WHERE rowid LIKE '" + player.Vehicle.ID + "'");
MessagePlayer( "Parked Vehicle!", player );
}
}
if( cmd == "addv" )
{
if( !text )MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( NumTok( text, " " ) < 4 )MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( player.Vehicle ) MessagePlayer("You must be outside of the vehicle",player);
else{
local TextSplit = split( text, " " ),ModelID=TextSplit[ 0 ],ColID1=TextSplit[ 1 ],ColID2=TextSplit[ 2 ],WorldID=TextSplit[ 3 ];
if ( !IsNum(ModelID)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(ColID1)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(ColID2)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(WorldID)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ((ModelID.tointeger() < 130) ) MessagePlayer ( "The models ID must be greater than 130" , player );
else if ((ModelID.tointeger() == 180))MessagePlayer ("This model id is not a vehicle" , player );
else if ((ModelID.tointeger() == 181))MessagePlayer ("This model id is not a vehicle" , player );
else{
local VehicleID=GetVehicleCount();
VehicleID+=1;
QuerySQL( Vehicles, "INSERT INTO Vehicle ( Model , PosX , PosY , PosZ , AngleX , AngleY , AngleZ , Col1 , Col2 , WorldID  ) VALUES ('" + ModelID + "','" + player.Pos.x + "','" + player.Pos.y + "','" + player.Pos.z + "','0','0','0','" + ColID1 + "','" + ColID2 + "','" + WorldID + "' )" );
CreateVehicle(ModelID.tointeger(),WorldID.tointeger(),player.Pos, player.Angle,ColID1.tointeger(),ColID2.tointeger());
MessagePlayer ("You have added the vehicle." , player );
MessagePlayer ("ID["+VehicleID+"] Model["+ModelID+"] X["+player.Pos.x+"] Y["+player.Pos.y+"] Z["+player.Pos.z+"] Col1["+ColID1+"] Col2["+ColID2+"] World["+WorldID+"] Angle["+player.Angle+"]" , player );
}
}
}
}

function NumTok(string, separator)
{
 local tokenized = split(string, separator);
 return tokenized.len();
}
My server RP
IP: 51.222.28.159:8194

ℛḝξ☂

Store vehicles you need to load into database, and load vehicles from database.
Then you can change its spawn position from this command and in database, so that it's position will be what you changed everytime it is loaded or respawned.
I may be a slow walker but I am always walking.

Adrenaline

Quote from: Luis_Labarca on Mar 11, 2017, 03:27 AM:)Take this my friend is 100% tested and works 100% ;) :D

function onScriptLoad()
{
Vehicles<- ConnectSQL( "Vehicles.db" );
QuerySQL( Vehicles, "CREATE TABLE IF NOT EXISTS Vehicle ( Model NUMERIC, PosX FLOAT, PosY FLOAT, PosZ FLOAT, AngleX FLOAT, AngleY FLOAT, AngleZ FLOAT, Col1 NUMERIC, Col2 NUMERIC, WorldID NUMERIC)" );
LoadVehicle()
}

function LoadVehicle()
{
local i = 0, ID, Model, X, Y, Z, AngleX, AngleY, AngleZ, Col1, Col2, WorldID;
local q = QuerySQL(Vehicles, "SELECT * FROM Vehicle" );
while ( GetSQLColumnData( q, 0 ) != null )
{
Model = GetSQLColumnData( q, 0);
X = GetSQLColumnData( q, 1 );
Y = GetSQLColumnData( q, 2 );
Z = GetSQLColumnData( q, 3 );
AngleX = GetSQLColumnData( q, 4 );
AngleY = GetSQLColumnData( q, 5 );
AngleZ = GetSQLColumnData( q, 6 );
Col1 = GetSQLColumnData( q, 7);
Col2 = GetSQLColumnData( q, 8 );
WorldID = GetSQLColumnData( q, 9 );
local V=CreateVehicle( Model, WorldID, Vector( X , Y , Z  ), 0 , Col1, Col2 );
V.SpawnPos = Vector( X , Y , Z );
V.SpawnAngle=Vector( AngleX , AngleY , AngleZ );
V.EulerAngle.x=AngleX;
V.EulerAngle.y=AngleY;
V.EulerAngle.z=AngleZ;
GetSQLNextRow( q );
i++;
}
FreeSQLQuery( q );
print( "Vehicle "+ i);
}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "park" )
{
if (player.Vehicle )
{
player.Vehicle.SpawnPos = Vector( player.Vehicle.Pos.x, player.Vehicle.Pos.y, player.Vehicle.Pos.z );
player.Vehicle.SpawnAngle=Vector(player.Vehicle.EulerAngle.x, player.Vehicle.EulerAngle.y, player.Vehicle.EulerAngle.z);
QuerySQL(Vehicles, "UPDATE Vehicle SET PosX='"+player.Vehicle.Pos.x+"',PosY='"+player.Vehicle.Pos.y+"',PosZ='"+player.Vehicle.Pos.z+"', AngleX='"+player.Vehicle.EulerAngle.x+"', AngleY='"+player.Vehicle.EulerAngle.y+"', AngleZ='"+player.Vehicle.EulerAngle.z+"' WHERE rowid LIKE '" + player.Vehicle.ID + "'");
MessagePlayer( "Parked Vehicle!", player );
}
}
if( cmd == "addv" )
{
if( !text )MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( NumTok( text, " " ) < 4 )MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( player.Vehicle ) MessagePlayer("You must be outside of the vehicle",player);
else{
local TextSplit = split( text, " " ),ModelID=TextSplit[ 0 ],ColID1=TextSplit[ 1 ],ColID2=TextSplit[ 2 ],WorldID=TextSplit[ 3 ];
if ( !IsNum(ModelID)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(ColID1)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(ColID2)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(WorldID)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ((ModelID.tointeger() < 130) ) MessagePlayer ( "The models ID must be greater than 130" , player );
else if ((ModelID.tointeger() == 180))MessagePlayer ("This model id is not a vehicle" , player );
else if ((ModelID.tointeger() == 181))MessagePlayer ("This model id is not a vehicle" , player );
else{
local VehicleID=GetVehicleCount();
VehicleID+=1;
QuerySQL( Vehicles, "INSERT INTO Vehicle ( Model , PosX , PosY , PosZ , AngleX , AngleY , AngleZ , Col1 , Col2 , WorldID  ) VALUES ('" + ModelID + "','" + player.Pos.x + "','" + player.Pos.y + "','" + player.Pos.z + "','0','0','0','" + ColID1 + "','" + ColID2 + "','" + WorldID + "' )" );
CreateVehicle(ModelID.tointeger(),WorldID.tointeger(),player.Pos, player.Angle,ColID1.tointeger(),ColID2.tointeger());
MessagePlayer ("You have added the vehicle." , player );
MessagePlayer ("ID["+VehicleID+"] Model["+ModelID+"] X["+player.Pos.x+"] Y["+player.Pos.y+"] Z["+player.Pos.z+"] Col1["+ColID1+"] Col2["+ColID2+"] World["+WorldID+"] Angle["+player.Angle+"]" , player );
}
}
}
}

function NumTok(string, separator)
{
 local tokenized = split(string, separator);
 return tokenized.len();
}
:B

kennedyarz


Luis_Labarca

Quote from: AdrenAline on Mar 11, 2017, 08:09 PM
Quote from: Luis_Labarca on Mar 11, 2017, 03:27 AM:)Take this my friend is 100% tested and works 100% ;) :D

function onScriptLoad()
{
Vehicles<- ConnectSQL( "Vehicles.db" );
QuerySQL( Vehicles, "CREATE TABLE IF NOT EXISTS Vehicle ( Model NUMERIC, PosX FLOAT, PosY FLOAT, PosZ FLOAT, AngleX FLOAT, AngleY FLOAT, AngleZ FLOAT, Col1 NUMERIC, Col2 NUMERIC, WorldID NUMERIC)" );
LoadVehicle()
}

function LoadVehicle()
{
local i = 0, ID, Model, X, Y, Z, AngleX, AngleY, AngleZ, Col1, Col2, WorldID;
local q = QuerySQL(Vehicles, "SELECT * FROM Vehicle" );
while ( GetSQLColumnData( q, 0 ) != null )
{
Model = GetSQLColumnData( q, 0);
X = GetSQLColumnData( q, 1 );
Y = GetSQLColumnData( q, 2 );
Z = GetSQLColumnData( q, 3 );
AngleX = GetSQLColumnData( q, 4 );
AngleY = GetSQLColumnData( q, 5 );
AngleZ = GetSQLColumnData( q, 6 );
Col1 = GetSQLColumnData( q, 7);
Col2 = GetSQLColumnData( q, 8 );
WorldID = GetSQLColumnData( q, 9 );
local V=CreateVehicle( Model, WorldID, Vector( X , Y , Z  ), 0 , Col1, Col2 );
V.SpawnPos = Vector( X , Y , Z );
V.SpawnAngle=Vector( AngleX , AngleY , AngleZ );
V.EulerAngle.x=AngleX;
V.EulerAngle.y=AngleY;
V.EulerAngle.z=AngleZ;
GetSQLNextRow( q );
i++;
}
FreeSQLQuery( q );
print( "Vehicle "+ i);
}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "park" )
{
if (player.Vehicle )
{
player.Vehicle.SpawnPos = Vector( player.Vehicle.Pos.x, player.Vehicle.Pos.y, player.Vehicle.Pos.z );
player.Vehicle.SpawnAngle=Vector(player.Vehicle.EulerAngle.x, player.Vehicle.EulerAngle.y, player.Vehicle.EulerAngle.z);
QuerySQL(Vehicles, "UPDATE Vehicle SET PosX='"+player.Vehicle.Pos.x+"',PosY='"+player.Vehicle.Pos.y+"',PosZ='"+player.Vehicle.Pos.z+"', AngleX='"+player.Vehicle.EulerAngle.x+"', AngleY='"+player.Vehicle.EulerAngle.y+"', AngleZ='"+player.Vehicle.EulerAngle.z+"' WHERE rowid LIKE '" + player.Vehicle.ID + "'");
MessagePlayer( "Parked Vehicle!", player );
}
}
if( cmd == "addv" )
{
if( !text )MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( NumTok( text, " " ) < 4 )MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( player.Vehicle ) MessagePlayer("You must be outside of the vehicle",player);
else{
local TextSplit = split( text, " " ),ModelID=TextSplit[ 0 ],ColID1=TextSplit[ 1 ],ColID2=TextSplit[ 2 ],WorldID=TextSplit[ 3 ];
if ( !IsNum(ModelID)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(ColID1)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(ColID2)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(WorldID)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ((ModelID.tointeger() < 130) ) MessagePlayer ( "The models ID must be greater than 130" , player );
else if ((ModelID.tointeger() == 180))MessagePlayer ("This model id is not a vehicle" , player );
else if ((ModelID.tointeger() == 181))MessagePlayer ("This model id is not a vehicle" , player );
else{
local VehicleID=GetVehicleCount();
VehicleID+=1;
QuerySQL( Vehicles, "INSERT INTO Vehicle ( Model , PosX , PosY , PosZ , AngleX , AngleY , AngleZ , Col1 , Col2 , WorldID  ) VALUES ('" + ModelID + "','" + player.Pos.x + "','" + player.Pos.y + "','" + player.Pos.z + "','0','0','0','" + ColID1 + "','" + ColID2 + "','" + WorldID + "' )" );
CreateVehicle(ModelID.tointeger(),WorldID.tointeger(),player.Pos, player.Angle,ColID1.tointeger(),ColID2.tointeger());
MessagePlayer ("You have added the vehicle." , player );
MessagePlayer ("ID["+VehicleID+"] Model["+ModelID+"] X["+player.Pos.x+"] Y["+player.Pos.y+"] Z["+player.Pos.z+"] Col1["+ColID1+"] Col2["+ColID2+"] World["+WorldID+"] Angle["+player.Angle+"]" , player );
}
}
}
}

function NumTok(string, separator)
{
 local tokenized = split(string, separator);
 return tokenized.len();
}
:B

Lol, I do not get any error
That is that you did something wrong re-copy the code

function onScriptLoad()
{
Vehicles<- ConnectSQL( "Vehicles.db" );
QuerySQL( Vehicles, "CREATE TABLE IF NOT EXISTS Vehicle ( Model NUMERIC, PosX FLOAT, PosY FLOAT, PosZ FLOAT, AngleX FLOAT, AngleY FLOAT, AngleZ FLOAT, Col1 NUMERIC, Col2 NUMERIC, WorldID NUMERIC)" );
LoadVehicle()
}

function LoadVehicle()
{
local i = 0, ID, Model, X, Y, Z, AngleX, AngleY, AngleZ, Col1, Col2, WorldID;
local q = QuerySQL(Vehicles, "SELECT * FROM Vehicle" );
while ( GetSQLColumnData( q, 0 ) != null )
{
Model = GetSQLColumnData( q, 0);
X = GetSQLColumnData( q, 1 );
Y = GetSQLColumnData( q, 2 );
Z = GetSQLColumnData( q, 3 );
AngleX = GetSQLColumnData( q, 4 );
AngleY = GetSQLColumnData( q, 5 );
AngleZ = GetSQLColumnData( q, 6 );
Col1 = GetSQLColumnData( q, 7);
Col2 = GetSQLColumnData( q, 8 );
WorldID = GetSQLColumnData( q, 9 );
local V=CreateVehicle( Model, WorldID, Vector( X , Y , Z  ), 0 , Col1, Col2 );
V.SpawnPos = Vector( X , Y , Z );
V.SpawnAngle=Vector( AngleX , AngleY , AngleZ );
V.EulerAngle.x=AngleX;
V.EulerAngle.y=AngleY;
V.EulerAngle.z=AngleZ;
GetSQLNextRow( q );
i++;
}
FreeSQLQuery( q );
print( "Vehicle "+ i);
}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "park" )
{
if (player.Vehicle )
{
player.Vehicle.SpawnPos = Vector( player.Vehicle.Pos.x, player.Vehicle.Pos.y, player.Vehicle.Pos.z );
player.Vehicle.SpawnAngle=Vector(player.Vehicle.EulerAngle.x, player.Vehicle.EulerAngle.y, player.Vehicle.EulerAngle.z);
QuerySQL(Vehicles, "UPDATE Vehicle SET PosX='"+player.Vehicle.Pos.x+"',PosY='"+player.Vehicle.Pos.y+"',PosZ='"+player.Vehicle.Pos.z+"', AngleX='"+player.Vehicle.EulerAngle.x+"', AngleY='"+player.Vehicle.EulerAngle.y+"', AngleZ='"+player.Vehicle.EulerAngle.z+"' WHERE rowid LIKE '" + player.Vehicle.ID + "'");
MessagePlayer( "Parked Vehicle!", player );
}
}
if( cmd == "addv" )
{
if( !text )MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( NumTok( text, " " ) < 4 )MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( player.Vehicle ) MessagePlayer("You must be outside of the vehicle",player);
else{
local TextSplit = split( text, " " ),ModelID=TextSplit[ 0 ],ColID1=TextSplit[ 1 ],ColID2=TextSplit[ 2 ],WorldID=TextSplit[ 3 ];
if ( !IsNum(ModelID)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(ColID1)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(ColID2)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ( !IsNum(WorldID)) MessagePlayer("Usage: /"+cmd+" [ModelID] [Col1ID] [Col2ID] [WorldID]",player);
else if ((ModelID.tointeger() < 130) ) MessagePlayer ( "The models ID must be greater than 130" , player );
else if ((ModelID.tointeger() == 180))MessagePlayer ("This model id is not a vehicle" , player );
else if ((ModelID.tointeger() == 181))MessagePlayer ("This model id is not a vehicle" , player );
else{
local VehicleID=GetVehicleCount();
VehicleID+=1;
QuerySQL( Vehicles, "INSERT INTO Vehicle ( Model , PosX , PosY , PosZ , AngleX , AngleY , AngleZ , Col1 , Col2 , WorldID  ) VALUES ('" + ModelID + "','" + player.Pos.x + "','" + player.Pos.y + "','" + player.Pos.z + "','0','0','0','" + ColID1 + "','" + ColID2 + "','" + WorldID + "' )" );
CreateVehicle(ModelID.tointeger(),WorldID.tointeger(),player.Pos, player.Angle,ColID1.tointeger(),ColID2.tointeger());
MessagePlayer ("You have added the vehicle." , player );
MessagePlayer ("ID["+VehicleID+"] Model["+ModelID+"] X["+player.Pos.x+"] Y["+player.Pos.y+"] Z["+player.Pos.z+"] Col1["+ColID1+"] Col2["+ColID2+"] World["+WorldID+"] Angle["+player.Angle+"]" , player );
}
}
}
}

function NumTok(string, separator)
{
 local tokenized = split(string, separator);
 return tokenized.len();
}
My server RP
IP: 51.222.28.159:8194

KAKAN

Luis and kenne, see the error's details once again. q = null.
So, in your loadvehicle function, add a check for q...
This:-
local q = QuerySQL(Vehicles, "SELECT * FROM Vehicle" );
while ( GetSQLColumnData( q, 0 ) != null )
should be:
local q = QuerySQL(Vehicles, "SELECT * FROM Vehicle" );
if( q == null ) return print("No vehicles to load");
while ( GetSQLColumnData( q, 0 ) != null )
oh no

kennedyarz


Luis_Labarca

Quote from: KAKAN on Mar 12, 2017, 05:49 AMLuis and kenne, see the error's details once again. q = null.
So, in your loadvehicle function, add a check for q...
This:-
local q = QuerySQL(Vehicles, "SELECT * FROM Vehicle" );
while ( GetSQLColumnData( q, 0 ) != null )
should be:
local q = QuerySQL(Vehicles, "SELECT * FROM Vehicle" );
if( q == null ) return print("No vehicles to load");
while ( GetSQLColumnData( q, 0 ) != null )

Ah ok but I miss it to me it works fine without putting
if( q == null ) return print("No vehicles to load");

And adrenaline you get that error thanks for solving the error @KAKAN
My server RP
IP: 51.222.28.159:8194

Luis_Labarca

@KAKAN

@AdrenAline I passed your server to have it fixed and I came to change the plugin sqlite-win32 by sqlite04rel32 and the error no longer exists
I think the plugin sqlite04rel32 does not need if( q == null ) return print("No vehicles to load");

So I used to work fine and not because I used the plugin sqlite04rel32 :D
My server RP
IP: 51.222.28.159:8194

Adrenaline

Quote from: Luis_Labarca on Mar 12, 2017, 04:18 PM@KAKAN

@AdrenAline I passed your server to have it fixed and I came to change the plugin sqlite-win32 by sqlite04rel32 and the error no longer exists
I think the plugin sqlite04rel32 does not need if( q == null ) return print("No vehicles to load");

So I used to work fine and not because I used the plugin sqlite04rel32 :D
yes :)