Vehicle Creating Script v0.1 By Beztone & MatheuS(aka Takanaue)
Just Put The Following Data In You Script in Correct Places
Actually this system is just like an map editor :)
To spawn a vehicle use /addcar
/addcar <ModelID> <COLOR1> <COLOR2>
To erase current vehicle press
Delete key
To save current vehicle in db press
P key after parking the vehicle to your desired position
Note: Vehicle wont be edited/erased once you save it in db. Vehicle ModelIDs will be found Here (http://wiki.vc-mp.org/wiki/Vehicles) and colorIDs will be found Here (http://wiki.vc-mp.org/wiki/Car_Colors)
class PlayerStats
{
IdBeingEdit = null;
IsBeingEdited =false;
}
function onScriptLoad()
{
status <- array(GetMaxPlayers(), null);
del <- BindKey(true,0x2E,0,0);
p <- BindKey(true,0x50,0,0);
vdb <- ConnectSQL("vehicles.sqlite");
if (vdb) print("Vehicles Database loaded Successfully");
::QuerySQL( vdb, "CREATE TABLE IF NOT EXISTS Vehicles ( Model INT, World INT, PX FLOAT, PY FLOAT, PZ FLOAT, Angle FLOAT, col1 INT, col2 INT)" );
LoadCars();
}
function onPlayerJoin( player )
{
status[player.ID] = PlayerStats();
}
function onPlayerCommand( player, cmd, text )
{
if ( cmd == "addcar" )
{
if (player.Name == "YOURNICK") //this would be just like as admin system
{
if ( !text ) MessagePlayer( ">> Use /" + cmd + " <Model> <Col1> <Col2>", player );
else if ( status[player.ID].IsBeingEdited==true ) MessagePlayer( "Recent vehicle Not Saved Yet", player );
else
{
local
model = GetTok(text," ",1),
color1 = GetTok(text," ",2),
color2 = GetTok(text," ",3);
if ( !model || !color1 || !color2 ) MessagePlayer( ">> Use /" + cmd + " <Model> <Col1> <Col2>", player );
else
{
status[player.ID].IsBeingEdited=true;
player.Vehicle = CreateVehicle( model.tointeger(), player.World, Vector( player.Pos.x.tofloat(), player.Pos.y.tofloat(), player.Pos.z.tofloat() ), player.Angle.tofloat(), color1.tointeger(), color2.tointeger() );
Message( "[#FF0000]Vehicle Created, Park The Vehicle To You Pos and [#FFFFFF]Press P to Save It In Database" );
status[player.ID].IdBeingEdit = player.Vehicle.ID;
}
}
}
}
return 1;
}
function LoadCars()
{
local q = QuerySQL( vdb, "SELECT * FROM Vehicles" ), i = 0;
while( GetSQLColumnData( q, 0 ) )
{
local
Model = GetSQLColumnData( q, 0 ),
World = GetSQLColumnData( q, 1 ),
PX= GetSQLColumnData( q, 2 ),
PY = GetSQLColumnData( q, 3 ),
PZ = GetSQLColumnData( q, 4 ),
Angle = GetSQLColumnData( q, 5 ),
col1 = GetSQLColumnData( q, 6 ),
col2 = GetSQLColumnData( q, 7 );
CreateVehicle( Model.tointeger(), World.tointeger(), Vector( PX.tofloat(), PY.tofloat(), PZ.tofloat() ), Angle.tofloat(), col1, col2 );
GetSQLNextRow( q );
i++;
}
print( "Cars loaded - " + i );
}
function onPlayerEnterVehicle( player, vehicle, door )
{
Message("Vehicle ID: "+vehicle.ID+" Model ID: "+vehicle.Model)
}
function onKeyDown( player, key )
{
if(key==del)
{
if(status[player.ID].IsBeingEdited==false) Message(player.Name+": [#FFFFFF]First turn on editing");
else if(!player.Vehicle) Message(player.Name+": [#FFFFFF]Must Be In Vehicle To Remove");
else if(!player.Vehicle.ID == status[player.ID].IdBeingEdit) Message(player.Name+": [#FFFFFF]This Vehicle Is Not In Editing Process");
else
{
FindVehicle(player.Vehicle.ID).Delete();
status[player.ID].IsBeingEdited=false;
status[player.ID].IdBeingEdit = null;
Message( "[#FF0000]Admin [#FFFFFF]" + player.Name + " [#FF0000]Erased Vehicle from [#FFFFFF]" + GetDistrictName( player.Pos.x, player.Pos.y ) + "." );
}
}
else if(key==p)
{
if(status[player.ID].IsBeingEdited==false) Message(player.Name+": [#FFFFFF]First turn on editing");
else if(!player.Vehicle) Message(player.Name+": [#FFFFFF]Must Be In Vehicle To Save Vehicle");
else if(!player.Vehicle.ID == status[player.ID].IdBeingEdit) Message(player.Name+": [#FFFFFF]This Vehicle Is Not In Editing Process");
else {
QuerySQL( vdb, "INSERT INTO Vehicles ( Model, World, PX, PY, PZ, Angle, col1, col2 ) VALUES ( '" + player.Vehicle.Model + "', '" + player.Vehicle.World + "', '" + player.Vehicle.Pos.x + "', '" + player.Vehicle.Pos.y + "', '" + player.Vehicle.Pos.z + "', '" + player.Vehicle.EulerAngle.z + "', '" + player.Vehicle.Colour1 + "', '" + player.Vehicle.Colour2 + "')" );
Message(player.Name+": [#FFFFFF]Vehicle Saved In Database");
status[player.ID].IsBeingEdited=false;
status[player.ID].IdBeingEdit = null;
}
}
}
function GetTok(string, separator, n, ...)
{
local m = vargv.len() > 0 ? vargv[0] : n,
tokenized = split(string, separator),
text = "";
if (n > tokenized.len() || n < 1) return null;
for (; n <= m; n++)
{
text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
}
return text;
}
function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}
The System Is Tested By me So If You Found Any BUG The Comment BellowUpdated: classes was missed
Edited on 07/01/2016: forgot to mention Keys and command
Nice ;D
Nice!
"DizzasTeR" This is my nick, everyone knows me on it, Really?!
Edit: Change it...
You can put in postin?
Why don't u change the
function onKeyDown( player, key ) to case?
For ex
function onKeyDown( player, key )
{
{
switch(key)
{
case del:
<Edited snippet>
break;
case p:
<Edited snippet>
break;
}
}
}
Because i'm in love with if,elsif system
lol, then also convert it, it'll help me in other way
Or else I'll post the function onkeydown with case
It doesnt make lag and it will be easy for newbies to learn
Just for your information
@KAKAN, Using case everywhere is not necessary, specially for something like this since he is just checking two conditions.
Use case if you have to go through alot of condition checks.
each has its own way of developing.
Okay
@Doom_Killer Thanks for telling me
hey where do i add this
In your script.
If NO THEN GO KILL YOURSELF
Quote from: KAKAN on Aug 25, 2015, 05:34 PMIn your script.
If NO THEN GO KILL YOURSELF
Please keep it nice...
Quote from: Spidey on Aug 25, 2015, 05:29 PMhey where do i add this
Please stop scripting if this is a genuine question.
In your script
Quote from: FinchDon on Aug 26, 2015, 01:28 PMSpidey Hey Bro I can tell where to add You need to go to first Window folder in Local Disc C and Then Delete everything then add this on notepad and save it in your script ;)
Please be nice, and what u wrote, i can't understand
Quote from: FinchDon on Aug 26, 2015, 01:28 PMSpidey Hey Bro I can tell where to add You need to go to first Window folder in Local Disc C and Then Delete everything then add this on notepad and save it in your script ;)
Why do you act like that? You've been far more stupid then Spidey. So you know how unhelpful you are right now. Stop fucking around or get the fuck out.
I know Well
@KAKAN @Thijn Who Can Speak Up with the noob who don't know even one thing we tried to help him a lot but he don't have brain so what can we do? -_-
Quote from: FinchDon on Aug 26, 2015, 05:12 PMI know Well @KAKAN @Thijn Who Can Speak Up with the noob who don't know even one thing we tried to help him a lot but he don't have brain so what can we do? -_-
You don't lower yourself and act like a retard yourself. You were far more retarded then this guy, so it's best if you not judge people like that at all.
* BUMP *
Sorry bumping this topic, but I saw it and I can not leave it.
The original script is not saving the correct angle, to fix this bug you should only add a function and change a line.
Function:
function GetRadiansAngle(Rotation)
{
local angle;
angle = ::asin( Rotation.z ) * -2;
return Rotation.w < 0 ? 3.14159 - angle : 6.28319 - angle;
}
Modify line:
QuerySQL( vdb, "INSERT INTO Vehicles ( Model, World, PX, PY, PZ, Angle, col1, col2 ) VALUES ( '" + player.Vehicle.Model + "', '" + player.Vehicle.World + "', '" + player.Vehicle.Pos.x + "', '" + player.Vehicle.Pos.y + "', '" + player.Vehicle.Pos.z + "', '" + player.Vehicle.EulerAngle.z + "', '" + player.Vehicle.Colour1 + "', '" + player.Vehicle.Colour2 + "')" );
To:
QuerySQL( vdb, "INSERT INTO Vehicles ( Model, World, PX, PY, PZ, Angle, col1, col2 ) VALUES ( '" + player.Vehicle.Model + "', '" + player.Vehicle.World + "', '" + player.Vehicle.Pos.x + "', '" + player.Vehicle.Pos.y + "', '" + player.Vehicle.Pos.z + "', '" + GetRadiansAngle(player.Vehicle.Angle) + "', '" + player.Vehicle.Colour1 + "', '" + player.Vehicle.Colour2 + "')" );
where is the link to the download ???
you have to copy paste the code
How to modify a car that is aleardy saved?
it says index ID doesnt exist.
Quote from: Shovon^ on Jan 02, 2017, 06:20 AMit says index ID doesnt exist.
Yeaa You are right this script giving error "The Brain Does Not Exists"
Quote from: happymint2 on Jan 02, 2017, 12:14 PMQuote from: Shovon^ on Jan 02, 2017, 06:20 AMit says index ID doesnt exist.
Yeaa You are right this script giving error "The Brain Does Not Exists"
ya ya u also just have the brain for insulting others