I haven't tested it. Please test it and reply me! :D
function CVehicle::GetRadiansAngle()
{
local angle = ::asin(this.Rotation.z) * -2;
return this.Rotation.w < 0 ? 3.14159 - angle : 6.28319 - angle;
}
function CreateTable()
{
QuerySQL(VehDB, "CREATE TABLE IF NOT EXISTS Vehicles ( ID INTEGER, Model INTEGER, World INTEGER, Color1 INTEGER, Color2 INTEGER, PosX REAL, PosY REAL, PosZ REAL, Angle REAL )" );
}
function LoadVehicle()
{
local q = QuerySQL(VehDB, "SELECT * FROM Vehicles");
if (q)
{
local count = 1;
do
{
local model = GetSQLColumnData(q, 1);
local world = GetSQLColumnData(q, 2);
local col1 = GetSQLColumnData(q, 3);
local col2 = GetSQLColumnData(q, 4);
local x = GetSQLColumnData(q, 5);
local y = GetSQLColumnData(q, 6);
local z = GetSQLColumnData(q, 7);
local angle = GetSQLColumnData(q, 8);
local ID = CreateVehicle(model, world, x, y, z, angle, col1 , col2);
count++;
}
while (GetSQLNextRow(q));
FreeSQLQuery(q);
if (count > 0)
for (local i = 1; i <= count; i++)
QuerySQL(VehDB, "UPDATE Vehicles SET ID=" + i + " WHERE rowid=" + i);
}
}
function UpdateVehicle(veh, Pos, Angle, Color1, Color2, Model)
{
if (!Pos) Pos = veh.Pos;
if (!Angle) Angle = veh.GetRadiansAngle();
if (!Color1 || !Color2)
{
Color1 = veh.Colour1;
Color2 = veh.Colour2;
}
if (!Model) Model = veh.Model;
QuerySQL(VehDB, "UPDATE Vehicles SET Color1="+Color1+", Color2="+Color2+", PosX="+Pos.x+", PosY="+Pos.y+", PosZ="+Pos.z+", Angle="+Angle+", Model="+Model+" WHERE ID="+veh.ID);
}
function AddVehicle(Model, Colour1, Colour2, Pos, Angle)
{
local veh = CreateVehicle(model, player.Pos, Angle, Colour1, Colour1);
QuerySQL(VehDB, "INSERT INTO Vehicles ( ID, Model, World, Color1, Color2, PosX, PosY, PosZ, Angle ) VALUES ( "+veh.ID+", "+Model+", 1, "+Colour1+", "+Colour2+", "+Pos.x+", "+Pos.y+", "+Pos.z+", "+Angle+" )");
return veh;
}
function DeleteVehicle(ID)
{
QuerySQL(VehDB, "DELETE FROM Vehicles WHERE ID="+ID);
}
function SaveServerVehicles()
{
for (local i = 1; i <= GetVehicleCount(); i++)
{
local veh = FindVehicle(i);
if (veh)
AddVehicle(veh.Model, veh.Colour1, veh.Colour2, veh.Pos, veh.GetRadiansAngle());
}
}
Sorry Good Work
Quote from: BrYaN_FuRy on Jul 31, 2015, 04:08 PMWhere is Commands Btw?
I don't what you say... ???
donde esta el comando?
WHat you mean?
Just fix the little bugs, and you're done.
Its working for me, but sometimes the SaveServerFunction doesn't saves to DB
I only say that where is the command to create the vehicle
There is already an improved snippet posted here (http://forum.vc-mp.org/?topic=1177.0)
Thank You