Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: MacTavish on Jul 30, 2015, 10:47 AM

Title: [Snippet]Vehicle Creating In Database
Post by: MacTavish on Jul 30, 2015, 10:47 AM
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 Bellow

Updated: classes was missed

Edited on 07/01/2016: forgot to mention Keys and command
Title: Re: [Snippet]Vehicle Creating In Database
Post by: MatheuS on Jul 30, 2015, 11:48 AM
Nice ;D
Title: Re: [Snippet]Vehicle Creating In Database
Post by: KAKAN on Jul 30, 2015, 01:07 PM
Nice!
Title: Re: [Snippet]Vehicle Creating In Database
Post by: DizzasTeR on Jul 30, 2015, 01:32 PM
"DizzasTeR" This is my nick, everyone knows me on it, Really?!

Edit: Change it...
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Joao^ on Jul 30, 2015, 02:13 PM
You can put in postin?
Title: Re: [Snippet]Vehicle Creating In Database
Post by: KAKAN on Jul 30, 2015, 05:20 PM
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;
}
}
}
Title: Re: [Snippet]Vehicle Creating In Database
Post by: MacTavish on Jul 30, 2015, 05:26 PM
Because i'm in love with if,elsif system
Title: Re: [Snippet]Vehicle Creating In Database
Post by: KAKAN on Jul 30, 2015, 05:27 PM
lol, then also convert it, it'll help me in other way
Or else I'll post the function onkeydown with case
Title: Re: [Snippet]Vehicle Creating In Database
Post by: MacTavish on Jul 30, 2015, 05:30 PM
It doesnt make lag and it will be easy for newbies to learn
Title: Re: [Snippet]Vehicle Creating In Database
Post by: DizzasTeR on Jul 30, 2015, 06:36 PM
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.
Title: Re: [Snippet]Vehicle Creating In Database
Post by: MatheuS on Jul 30, 2015, 09:25 PM
each has its own way of developing.
Title: Re: [Snippet]Vehicle Creating In Database
Post by: KAKAN on Jul 31, 2015, 09:44 AM
Okay @Doom_Killer Thanks for telling me
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Spidey on Aug 25, 2015, 05:29 PM
hey where do i add this
Title: Re: [Snippet]Vehicle Creating In Database
Post by: KAKAN on Aug 25, 2015, 05:34 PM
In your script.
If NO THEN GO KILL YOURSELF
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Thijn on Aug 25, 2015, 07:07 PM
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.
Title: Re: [Snippet]Vehicle Creating In Database
Post by: FinchDon on Aug 26, 2015, 01:28 PM
In your script
Title: Re: [Snippet]Vehicle Creating In Database
Post by: KAKAN on Aug 26, 2015, 04:07 PM
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
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Thijn on Aug 26, 2015, 04:40 PM
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.
Title: Re: [Snippet]Vehicle Creating In Database
Post by: FinchDon on Aug 26, 2015, 05:12 PM
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? -_-
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Thijn on Aug 27, 2015, 06:25 PM
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.
Title: Re: [Snippet]Vehicle Creating In Database
Post by: MatheuS on Jul 20, 2016, 02:39 PM
* 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 + "')" );
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Shovon^ on Aug 25, 2016, 06:35 AM
where is the link to the download ???
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Kewun on Aug 25, 2016, 07:18 AM
you have to copy paste the code
Title: Re: [Snippet]Vehicle Creating In Database
Post by: NicusorN5 on Nov 08, 2016, 07:09 PM
How to modify a car that is aleardy saved?
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Shovon^ on Jan 02, 2017, 06:20 AM
it says index ID doesnt exist.

Title: Re: [Snippet]Vehicle Creating In Database
Post by: Cool on Jan 02, 2017, 12:14 PM
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"
Title: Re: [Snippet]Vehicle Creating In Database
Post by: Shovon^ on Jan 02, 2017, 12:56 PM
Quote from: happymint2 on Jan 02, 2017, 12:14 PM
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"

ya ya u also just have the brain for insulting others