Vehicle Auto Re-Create

Started by W3aPoN^, Jul 18, 2017, 11:21 AM

Previous topic - Next topic

W3aPoN^

hello fellas. Can you give me a Function which can re-create vehicles in database NOTE: For Only Custom Vehicles.
so i want a Function in which if a Player buy Vehicle 6400 the script auto re-create a new clone of 6400 Vehicle so players can buy 10+ copies of that Vehicle <3 Thanks in Advance.

Terror_Styles

Well Why Don't You Try Yourself? & If you find any error You can come here.
Simple & Easy!

Thanks me Later!

W3aPoN^

Sorry but i don't know what to with this

Terror_Styles

#3
This is just an example import it like this

function onScriptLoad()
{
Vehs <- ConnectSQL( "Vehs.db" );
CreateTables();
LoadVehicles();
}
function onScriptUnload()
{
DisconnectSQL( Vehs );
}
function CreateTables()
{
QuerySQL(Vehs, "CREATE TABLE IF NOT EXISTS Creation ( ID NUMERIC, Model NUMERIC, X NUMERIC, Y NUMERIC, Z NUMERIC, Col1 NUMERIC, Col2 NUMERIC, Angle NUMERIC)" );
QuerySQL(Vehs, "CREATE TABLE IF NOT EXISTS Sale ( ID NUMERIC, Cost NUMERIC, Owner TEXT, Shared TEXT )" );
}

function onPlayerEnterVehicle( player, veh, isPassenger )
{
local VehicleID2 = QuerySQL( Vehs, "SELECT * FROM Sale" );
if(VehicleID2)
{
local q = QuerySQL( Vehs, "SELECT * FROM Sale WHERE ID='"+veh.ID+"'" );
local
Cost=GetSQLColumnData( q, 1 ),
Owner=GetSQLColumnData( q, 2 ),
Share=GetSQLColumnData( q, 3 ),
MessagePlayer( "[#FFFFFF] Vehicle ID: "+veh.ID+". Vehicle Price: "+Cost+".", player );
MessagePlayer( "[#FF8000] Vehicle Owner: "+Owner+".  Car Sharer: "+Share+".", player );
}
}
}

function LoadVehicles()
{
local q = QuerySQL( Vehs, "SELECT * FROM Creation" ), i = 0;
while( GetSQLColumnData( q, 0 ) )
{
local
Model= GetSQLColumnData( q, 1 ),
X= GetSQLColumnData( q, 2 ),
Y= GetSQLColumnData( q, 3 ),
Z= GetSQLColumnData( q, 4 ),
Col1= GetSQLColumnData( q, 5 ),
Col2= GetSQLColumnData( q, 6 ),
Angle= GetSQLColumnData( q, 7 );
CreateVehicle( Model, Vector(X, Y, Z), Angle, Col1, Col2 );
GetSQLNextRow( q );
i++;
}
print("Vehicles Count ("+i+")");
return 0;
}


function onPlayerCommand( player, cmd, text )
{
else if ( cmd == "buycar" )
{
if ( !text ) MessagePlayer("Use /"+cmd+" <Veh/ID>.", player);
else if ( !IsNum( text ) ) MessagePlayer("ID Must be numbers.", player );
else {
local q = QuerySQL( Vehs, "SELECT * FROM Sale WHERE ID='"+text+"'" );
local Cash = GetSQLColumnData( q, 1 );
if ( player.Cash < Cash ) MessagePlayer("Insufficient Cash.", player );
else
{
QuerySQL( Vehs, "INSERT INTO Creation ( Id, Model, X, Y, Z, Col1, Col2, Angle ) VALUES ( '"+VehicleID+"', '"+ModelID+"', '"+player.Pos.x+"', '"+player.Pos.y+"', '"+player.Pos.z+"', '"+ColID1+"', '"+ColID2+"', '"+player.Angle+"' )" );
QuerySQL( Vehs, "INSERT INTO Sale ( ID, Cost, Owner, Shared ) VALUES ( '"+VehicleID+"', '"+Price+"', 'Unowned', 'None' )" );
CreateVehicle(6400,0,player.Pos, player.Angle,00,00);
QuerySQL( Vehs, "UPDATE Sale SET Owner='"+player.Name+"' WHERE ID='"+text+"'" );
MessagePlayer( "You have bought Vehicle Model: " + GetVehicleNameFromModel( FindVehicle( text.tointeger() ).Model ) + " Vehicle ID "+text+".", player );
player.Cash -= Cash;
}
}
}
}


This is just a simple example to Make this System Work!
I am not sure This is 100% okay, Don't try it lol ( Maybe It Works ) But Its an example


Updated!

W3aPoN^

Quote from: Terror_Styles on Jul 18, 2017, 03:33 PMThis is just an example import it like this

function onScriptLoad()
{
Vehs <- ConnectSQL( "Vehs.db" );
CreateTables();
LoadVehicles();
}
function onScriptUnload()
{
DisconnectSQL( Vehs );
}
function CreateTables()
{
QuerySQL(Vehs, "CREATE TABLE IF NOT EXISTS Creation ( ID NUMERIC, Model NUMERIC, X NUMERIC, Y NUMERIC, Z NUMERIC, Col1 NUMERIC, Col2 NUMERIC, Angle NUMERIC)" );
QuerySQL(Vehs, "CREATE TABLE IF NOT EXISTS Sale ( ID NUMERIC, Cost NUMERIC, Owner TEXT, Shared TEXT )" );
}

function onPlayerEnterVehicle( player, veh, isPassenger )
{
local VehicleID2 = QuerySQL( Vehs, "SELECT * FROM Sale" );
if(VehicleID2)
{
local q = QuerySQL( Vehs, "SELECT * FROM Sale WHERE ID='"+veh.ID+"'" );
local
Cost=GetSQLColumnData( q, 1 ),
Owner=GetSQLColumnData( q, 2 ),
Share=GetSQLColumnData( q, 3 ),
MessagePlayer( "[#FFFFFF] Vehicle ID: "+veh.ID+". Vehicle Price: "+Cost+".", player );
MessagePlayer( "[#FF8000] Vehicle Owner: "+Owner+".  Car Sharer: "+Share+".", player );
}
}
}

function LoadVehicles()
{
local q = QuerySQL( Vehs, "SELECT * FROM Creation" ), i = 0;
while( GetSQLColumnData( q, 0 ) )
{
local
Model= GetSQLColumnData( q, 1 ),
X= GetSQLColumnData( q, 2 ),
Y= GetSQLColumnData( q, 3 ),
Z= GetSQLColumnData( q, 4 ),
Col1= GetSQLColumnData( q, 5 ),
Col2= GetSQLColumnData( q, 6 ),
Angle= GetSQLColumnData( q, 7 );
CreateVehicle( Model, Vector(X, Y, Z), Angle, Col1, Col2 );
GetSQLNextRow( q );
i++;
}
print("Vehicles Count ("+i+")");
return 0;
}


function onPlayerCommand( player, cmd, text )
{
else if ( cmd == "buycar" )
{
if ( !text ) MessagePlayer("Use /"+cmd+" <Veh/ID>.", player);
else if ( !IsNum( text ) ) MessagePlayer("ID Must be numbers.", player );
else {
local q = QuerySQL( Vehicles, "SELECT * FROM Sale WHERE ID='"+text+"'" );
local Cash = GetSQLColumnData( q, 1 );
if ( player.Cash < Cash ) MessagePlayer("Insufficient Cash.", player );
else
{
QuerySQL( Vehs, "INSERT INTO Creation ( Id, Model, X, Y, Z, Col1, Col2, Angle ) VALUES ( '"+VehicleID+"', '"+ModelID+"', '"+player.Pos.x+"', '"+player.Pos.y+"', '"+player.Pos.z+"', '"+ColID1+"', '"+ColID2+"', '"+player.Angle+"' )" );
QuerySQL( Vehs, "INSERT INTO Sale ( ID, Cost, Owner, Shared ) VALUES ( '"+VehicleID+"', '"+Price+"', 'Unowned', 'None' )" );
CreateVehicle(6400,0,player.Pos, player.Angle,00,00);
QuerySQL( Vehs, "UPDATE Sale SET Owner='"+player.Name+"' WHERE ID='"+text+"'" );
MessagePlayer( "You have bought Vehicle Model: " + GetVehicleNameFromModel( FindVehicle( text.tointeger() ).Model ) + " Vehicle ID "+text+".", player );
player.Cash -= Cash;
}
}
}
}


This is just a simple example to Make this System Work!
I am not sure This is 100% okay, Don't try it lol ( Maybe It Works ) But Its an example

When i am Doing /buycar 1 error comes on Console Vehicles did not exist problem in Command
function onPlayerCommand( player, cmd, text )
{
else if ( cmd == "buycar" )
{
if ( !text ) MessagePlayer("Use /"+cmd+" <Veh/ID>.", player);
else if ( !IsNum( text ) ) MessagePlayer("ID Must be numbers.", player );
else {
local q = QuerySQL( Vehicles, "SELECT * FROM Sale WHERE ID='"+text+"'" );
local Cash = GetSQLColumnData( q, 1 );
if ( player.Cash < Cash ) MessagePlayer("Insufficient Cash.", player );
else
{
QuerySQL( Vehs, "INSERT INTO Creation ( Id, Model, X, Y, Z, Col1, Col2, Angle ) VALUES ( '"+VehicleID+"', '"+ModelID+"', '"+player.Pos.x+"', '"+player.Pos.y+"', '"+player.Pos.z+"', '"+ColID1+"', '"+ColID2+"', '"+player.Angle+"' )" );
QuerySQL( Vehs, "INSERT INTO Sale ( ID, Cost, Owner, Shared ) VALUES ( '"+VehicleID+"', '"+Price+"', 'Unowned', 'None' )" );
CreateVehicle(6400,0,player.Pos, player.Angle,00,00);
QuerySQL( Vehs, "UPDATE Sale SET Owner='"+player.Name+"' WHERE ID='"+text+"'" );
MessagePlayer( "You have bought Vehicle Model: " + GetVehicleNameFromModel( FindVehicle( text.tointeger() ).Model ) + " Vehicle ID "+text+".", player );
player.Cash -= Cash;
}
}
}
}
What to do With that? BTW Thanks
and also Thanks for you Reply

Terror_Styles


D4rkR420R

Quote from: =NK=RazaCharan** on Jul 19, 2017, 03:09 AMWhen i am Doing /buycar 1 error comes on Console Vehicles did not exist problem in Command
function onPlayerCommand( player, cmd, text )
{
else if ( cmd == "buycar" )
{
if ( !text ) MessagePlayer("Use /"+cmd+" <Veh/ID>.", player);
else if ( !IsNum( text ) ) MessagePlayer("ID Must be numbers.", player );
else {
local q = QuerySQL( Vehicles, "SELECT * FROM Sale WHERE ID='"+text+"'" );
local Cash = GetSQLColumnData( q, 1 );
if ( player.Cash < Cash ) MessagePlayer("Insufficient Cash.", player );
else
{
QuerySQL( Vehs, "INSERT INTO Creation ( Id, Model, X, Y, Z, Col1, Col2, Angle ) VALUES ( '"+VehicleID+"', '"+ModelID+"', '"+player.Pos.x+"', '"+player.Pos.y+"', '"+player.Pos.z+"', '"+ColID1+"', '"+ColID2+"', '"+player.Angle+"' )" );
QuerySQL( Vehs, "INSERT INTO Sale ( ID, Cost, Owner, Shared ) VALUES ( '"+VehicleID+"', '"+Price+"', 'Unowned', 'None' )" );
CreateVehicle(6400,0,player.Pos, player.Angle,00,00);
QuerySQL( Vehs, "UPDATE Sale SET Owner='"+player.Name+"' WHERE ID='"+text+"'" );
MessagePlayer( "You have bought Vehicle Model: " + GetVehicleNameFromModel( FindVehicle( text.tointeger() ).Model ) + " Vehicle ID "+text+".", player );
player.Cash -= Cash;
}
}
}
}
What to do With that? BTW Thanks
and also Thanks for you Reply

The purpose is because the database instance name is Vehs, not Vehicles.

local q = QuerySQL( Vehicles, "SELECT * FROM Sale WHERE ID='"+text+"'" );

As a conclusion, you have it wrong.

Terror_Styles

Bro You said Correct but the post was updated! Thanks for letting him know error

W3aPoN^

Thanks Buddies. Love you So Much But @Terror_Styles
function OnPlayerEnterVehicle has an Error Test it yourself
Console giving me an Error and When i am Removing The Whole
onPlayerEnterVehicle Function The Scripts Work. What to Do?

Terror_Styles

That's because of your vehicle system which is loaded. & It will be differ from mine.Stick to urs...

W3aPoN^

So how i can Set this if this problem didn't Solve then How players Get Vehicles IDs Vehicle Owners?

Terror_Styles

Bro You are loàding any vehicle system? If Yes then which one?

W3aPoN^

Only Yours i am Not Loading Any Other vehicle System

Terror_Styles

Implement this Vehicle System provided by KrloZ
http://forum.vc-mp.org/?topic=4575.0

& Add this in buycar command
QuerySQL( Vehs, "INSERT INTO Creation ( Id, Model, X, Y, Z, Col1, Col2, World, Angle ) VALUES ( '"+VehicleID+"', '"+ModelID+"', '"+player.Pos.x+"', '"+player.Pos.y+"', '"+player.Pos.z+"', '"+ColID1+"', '"+ColID2+"',"' + WorldID + '", '"+player.Angle+"' )" );
QuerySQL( Vehs, "INSERT INTO Sale ( ID, Cost, Owner, Shared, Shared2) VALUES ( '"+VehicleID+"', '"+Price+"', 'Unowned', 'None', 'None' )" );
CreateVehicle(6400,0,player.Pos, player.Angle,00,00);




W3aPoN^

#14
Thanks. Thanks. Thanks. Thanks. Thanks
Working 100% But i Got 2 Commands /buycar From you and another from Krlozz Vehicle System i Renamed your Command as /buycustomcar and I Got LoadVehicles() From You and Krlozz I Rename Your as LoadCustomVehicles() Thats all Thanks For Helping me ;) :) ;) BTW Buddy Look Your Code it Need to be Update one More Time
function onPlayerEnterVehicle( player, veh, isPassenger )
{
local VehicleID2 = QuerySQL( Vehs, "SELECT * FROM Sale" );
if(VehicleID2)
{
local q = QuerySQL( Vehs, "SELECT * FROM Sale WHERE ID='"+veh.ID+"'" );
local
Cost=GetSQLColumnData( q, 1 ),
Owner=GetSQLColumnData( q, 2 ),
Share=GetSQLColumnData( q, 3 ), <========== WRONG
MessagePlayer( "[#FFFFFF] Vehicle ID: "+veh.ID+". Vehicle Price: "+Cost+".", player );
MessagePlayer( "[#FF8000] Vehicle Owner: "+Owner+".  Car Sharer: "+Share+".", player );
}
}
}

Update with This

function onPlayerEnterVehicle( player, veh, isPassenger )
{
local VehicleID2 = QuerySQL( Vehs, "SELECT * FROM Sale" );
if(VehicleID2)
{
local q = QuerySQL( Vehs, "SELECT * FROM Sale WHERE ID='"+veh.ID+"'" );
local
Cost=GetSQLColumnData( q, 1 ),
Owner=GetSQLColumnData( q, 2 ),
Share=GetSQLColumnData( q, 3 ); <========== RIGHT
MessagePlayer( "[#FFFFFF] Vehicle ID: "+veh.ID+". Vehicle Price: "+Cost+".", player );
MessagePlayer( "[#FF8000] Vehicle Owner: "+Owner+".  Car Sharer: "+Share+".", player );
}
}
}

Thanks Again Buddy :D