Basic Tunning System w/GUI

Started by KrOoB_, Jul 18, 2020, 03:23 AM

Previous topic - Next topic

KrOoB_

While making this script i use KrLozz Vehicle System so they are compatible 100% (0 error).
and thanks NewK for help
You can use your own vehicle script it'll compatible with yours no problem :D ( if you get error please notice me)

INFO
First things first script create a table in db because it needs to store somewhere :D
then getting handling infos from car after this it writing to database.
Finally, player enter vehicle and trigger the function, function starts load the vehicles info's from database and done :THUMSUP: :D

I made it at night so there maybe error( i saw nothing tried 2 times ) please notice me good luck <3

WARNINGS

I'm not a designer don't judge me about pic and hud i'm learning still :D

The tunning packs are randomly set i just write numbers so car can be too crazy or just freeze the car :D


İf you are using krlozz's script or another and you have already vehicle database just add this code your server and start just one time it'll create a table and add vehicles you have in your db
[noae][noae][noae][noae][noae][noae]function onScriptLoad()
{
LoadTunning();
}

function LoadTunning()
{
local q = QuerySQL( Vehicles, "SELECT * FROM Creation" ), i = 0;
while( GetSQLColumnData( q, 0 ) )
{
local Model= GetSQLColumnData( q, 1 );
QuerySQL( Vehicles, "INSERT INTO Tunning ( ID, Acceleration, MaxSpeed, NumberGears, Flags ) VALUES ( '" + GetSQLColumnData( q, 0 ) + "','" + GetHandlingRule( GetSQLColumnData( q, 1 ), 14) + "','" + GetHandlingRule(GetSQLColumnData( q, 1 ), 13) + "', '" + GetHandlingRule(GetSQLColumnData( q, 1 ), 12) + "', '" + GetHandlingRule(GetSQLColumnData( q, 1 ), 28) + "' )" );
GetSQLNextRow( q );
i++;
}
print("Writen ("+i+")");
return 0;
}
[/noae][/noae][/noae][/noae][/noae][/noae]

I'm not a designer don't judge me about pic and hud i'm learning still :D



https://www.youtube.com/watch?v=HKOaJ02hXPA


Server Side

[noae][noae][noae][noae][noae][noae]function onScriptLoad()
{
I_KEY <- BindKey(true, 0x49, 0, 0);
      ENTER <- BindKey(true, 0x0D, 0, 0);
    teleport <- array(GetMaxPlayers(),0);
  Customer <- CreateCheckpoint(null, 0, true, Vector(-846.449, -902.177, 11.1034), RGB(0, 0, 200), 3.0);
  Marker_Customer <- CreateMarker(0, Vector( -846.449, -902.177, 11.1034 ), 2, RGB(41, 182, 0), 20 );


//KrLoz script's db
Vehicles <- ConnectSQL( "scripts/Vehicles.db" );

QuerySQL(Vehicles, "CREATE TABLE IF NOT EXISTS Creation ( id NUMERIC, model NUMERIC, x NUMERIC, y NUMERIC, z NUMERIC, col1 NUMERIC, col2 NUMERIC, world NUMERIC, angle NUMERIC)" );
QuerySQL(Vehicles, "CREATE TABLE IF NOT EXISTS Sale ( ID NUMERIC, Cost NUMERIC, Owner TEXT, Shared TEXT, Shared2 TEXT )" );
LoadVehicles();

 QuerySQL(Vehicles, "create table if not exists Tunning ( ID NUMERIC, Acceleration FLOAT, MaxSpeed FLOAT, NumberGears NUMERIC, Flags Numeric ) ");
 tuni <- array(GetMaxPlayers(), null);

}

function onScriptUnload()
{
}
function LoadVehicles()
{
local q = QuerySQL( Vehicles, "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 ),
World= GetSQLColumnData( q, 7 ),
Angle= GetSQLColumnData( q, 8 );
CreateVehicle( Model, World, Vector(X, Y, Z), Angle, Col1, Col2 );
GetSQLNextRow( q );
i++;
}
print("Vehicles Count ("+i+")");
return 0;
}

// ========================================== V E H I C L E   E V E N T S =============================================

function onPlayerEnterVehicle( player, vehicle, door )
{
local veh = player.Vehicle;

local q = QuerySQL(Vehicles, "SELECT * FROM Tunning WHERE ID = '" + vehicle.ID + "'");
 if (q)
 {
 veh.SetHandlingData(14, GetSQLColumnData(q, 1));
 veh.SetHandlingData(13, GetSQLColumnData(q, 2));
 veh.SetHandlingData(12, GetSQLColumnData(q, 3));
 veh.SetHandlingData(28, GetSQLColumnData(q, 4));
 }else
 {
local veh = vehicle.ID;
QuerySQL( Vehicles, "INSERT INTO Tunning ( ID, Acceleration, MaxSpeed, NumberGears, Flags ) VALUES ( '" + veh + "','" + GetHandlingRule( vehicle.Model, 14) + "','" + GetHandlingRule(vehicle.Model, 13) + "', '" + GetHandlingRule(vehicle.Model, 12) + "', '" + GetHandlingRule(vehicle.Model, 28) + "' )" );
 }
}

function IsVehForSale( id )
{
local q = QuerySQL( Vehicles, "SELECT * FROM Sale WHERE ID='"+id+"'" );
local own = GetSQLColumnData( q, 2 );
if ( own == "Unowned" ) return 1;
else return 0;
}
function IsOwnerOrSharer( veh, player )
{
local q = QuerySQL( Vehicles, "SELECT * FROM Sale WHERE ID='"+veh.ID+"'" );
local owner = GetSQLColumnData( q, 2 );
local sha = GetSQLColumnData( q, 3 );
local sha2 = GetSQLColumnData( q, 4 );
if ( ( owner == player.Name ) || ( sha == player.Name ) || ( sha2 == player.Name ) ) return 1;
else return 0;
}
function IsVehicleOwner( veh, player )
{
local q = QuerySQL( Vehicles, "SELECT * FROM Sale WHERE ID='"+veh.ID+"'" );
local owner = GetSQLColumnData( q, 2 );
if ( owner == player.Name ) return 1;
else return 0;
}

//================================= O T H E R F U N C T I O N S ==========================================================

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();
}

function GetPlayer( plr )
{
if ( plr )
{
if ( IsNum( plr ) )
{
plr = FindPlayer( plr.tointeger() );
if ( plr ) return plr;
else return false;
}
else
{
plr = FindPlayer( plr );
if ( plr ) return plr;
else return false;
}
}
else return false;
}
// =========================================== P I C K U P   E V E N T S ==============================================

// =========================================== P L A Y E R   E V E N T S ==============================================


function onPlayerCommand( player, cmd, text )
{
if ( cmd =="pos")
{
    Message( ""+ player.Pos.x + ", " + player.Pos.y + ", " + player.Pos.z);

}
else if ( cmd == "cag")
{
local veh = FindVehicle(1);
veh.Pos = Vector( player.Pos.x + 1, player.Pos.y+1, player.Pos.z  );

}
else if(cmd == "bring") {
if(!text) MessagePlayer( "Error - Correct syntax - /bring <Name/ID>' !",player );
else {
local plr = FindPlayer(text);
if(!plr) MessagePlayer( "Error - Unknown player !",player);
else {
plr.Pos = player.Pos;
MessagePlayer( "[ /" + cmd + " ] " + plr.Name + " was sent to " + player.Name, player );
}
}
}
   
/*
else if(cmd == "exec")
{
if( !text ) MessagePlayer( "Error - Syntax: /exec <Squirrel code>", player);
else
{
try
{
local script = compilestring( text );
script();
}
catch(e) MessagePlayer( "Error: " + e, player);
}
}
    */
   
return 1;
}

function onClientScriptData( player )
{
local int = Stream.ReadInt(),
string = Stream.ReadString();
Message(""+ string);
if(string == "r1")
{
if( player.Vehicle)
{
local veh = player.Vehicle;
local q = QuerySQL(Vehicles, "SELECT * FROM Tunning WHERE ID = '" + veh.ID + "'");
if (q)
{
PlaySound(player.World, 50012, player.Pos);
veh.SetHandlingData(13, 1.0);
QuerySQL( Vehicles,"UPDATE Tunning SET Acceleration='"+ 10.0 +"' WHERE ID='"+player.Vehicle.ID+"'"); // 0.0 value is the new value of car's acceleration you need to change it with your values
QuerySQL( Vehicles,"UPDATE Tunning SET MaxSpeed='"+ 10.0 +"' WHERE ID='"+player.Vehicle.ID+"'");// 0.0 value is the new value of car's maxspeed you need to change it with your values
MessagePlayer("Vehicle successfully upgraded",player);
}
}else MessagePlayer("You need to be in a vehicle to do this", player)
  }
if(string == "motor2")
{
if( player.Vehicle)
{
local veh = player.Vehicle;
local q = QuerySQL(Vehicles, "SELECT * FROM Tunning WHERE ID = '" + veh.ID + "'");
if (q)
{
veh.SetHandlingData(13, 0.0);
PlaySound(player.World, 50011, player.Pos);
QuerySQL( Vehicles,"UPDATE Tunning SET MaxSpeed='"+ 0.0 +"' WHERE ID='"+player.Vehicle.ID+"'");// 0.0 value is the new value of car's maxspeed you need to change it with your values
MessagePlayer("Vehicle successfully upgraded",player);
}
}else MessagePlayer("You need to be in a vehicle to do this", player)
  }
if(string == "motor3")
{
if( player.Vehicle)
{
local veh = player.Vehicle;
local q = QuerySQL(Vehicles, "SELECT * FROM Tunning WHERE ID = '" + veh.ID + "'");
if (q)
{
veh.SetHandlingData(13, 0.0);
PlaySound(player.World, 50011, player.Pos);
QuerySQL( Vehicles,"UPDATE Tunning SET MaxSpeed='"+ 0.0 +"' WHERE ID='"+player.Vehicle.ID+"'"); // 0.0 value is the new value of car's maxspeed you need to change it with your values
MessagePlayer("Vehicle successfully upgraded",player);
}
}else MessagePlayer("You need to be in a vehicle to do this", player)
  }
if(string == "speed1")
{
if( player.Vehicle)
{
local veh = player.Vehicle;
local q = QuerySQL(Vehicles, "SELECT * FROM Tunning WHERE ID = '" + veh.ID + "'");
if (q)
{
veh.SetHandlingData(14, 0.0);
PlaySound(player.World, 50011, player.Pos);
QuerySQL( Vehicles,"UPDATE Tunning SET Acceleration='"+ 0.0 +"' WHERE ID='"+player.Vehicle.ID+"'"); // 0.0 value is the new value of car's acceleration you need to change it with your values
MessagePlayer("Vehicle successfully upgraded",player);
}
}else MessagePlayer("You need to be in a vehicle to do this", player)
  }
if(string == "speed2")
{
if( player.Vehicle)
{
local veh = player.Vehicle;
local q = QuerySQL(Vehicles, "SELECT * FROM Tunning WHERE ID = '" + veh.ID + "'");
if (q)
{
veh.SetHandlingData(14, 0.0);
PlaySound(player.World, 50011, player.Pos);
QuerySQL( Vehicles,"UPDATE Tunning SET Acceleration='"+ 0.0 +"' WHERE ID='"+player.Vehicle.ID+"'"); // 0.0 value is the new value of car's acceleration you need to change it with your values
MessagePlayer("Vehicle successfully upgraded",player);
}
}else MessagePlayer("You need to be in a vehicle to do this", player)
  }
if(string == "speed3")
{
if( player.Vehicle)
{
local veh = player.Vehicle;
local q = QuerySQL(Vehicles, "SELECT * FROM Tunning WHERE ID = '" + veh.ID + "'");
if (q)
{
veh.SetHandlingData(14, 0.0);
PlaySound(player.World, 50011, player.Pos);
QuerySQL( Vehicles,"UPDATE Tunning SET Acceleration='"+ 0.0 +"' WHERE ID='"+player.Vehicle.ID+"'"); // 0.0 value is the new value of car's acceleration you need to change it with your values
MessagePlayer("Vehicle successfully upgraded",player);
}
}else MessagePlayer("You need to be in a vehicle to do this", player)
  }
// After this, is yours you can add anything you want. for car Handling list http://wiki.thijn.ovh/index.php?title=Changing_Vehicle_Handling
}


// ====================================== C H E C K P O I N T   E V E N T S ==========================================

function onCheckpointEntered( player, checkpoint )
{
teleport[player.ID]=checkpoint.ID;
if ( teleport[player.ID] == 0)
{
Announce("Press I", player, 0);
}
}

function onCheckpointExited( player, checkpoint )
{
}

// =========================================== B I N D   E V E N T S =================================================

function onKeyUp( player, key )
{
  if (key == I_KEY)
    {
switch(teleport[player.ID])
{
case 0:
if( player.Vehicle)
{
local data = Stream();
data.StartWrite(  );
data.WriteInt(42);
Stream.SendStream(player)
}
break;
}
}
}

// ================================== E N D   OF   O F F I C I A L   E V E N T S ======================================


function SendDataToClient( player, ... )
{
    if( vargv[0] )
    {
        local     byte = vargv[0],
                len = vargv.len();
               
        if( 1 > len ) devprint( "ToClent <" + byte + "> No params specified." );
        else
        {
            Stream.StartWrite();
            Stream.WriteByte( byte );

            for( local i = 1; i < len; i++ )
            {
                switch( typeof( vargv[i] ) )
                {
                    case "integer": Stream.WriteInt( vargv[i] ); break;
                    case "string": Stream.WriteString( vargv[i] ); break;
                    case "float": Stream.WriteFloat( vargv[i] ); break;
                }
            }
           
            if( player == null ) Stream.SendStream( null );
            else if( typeof( player ) == "instance" ) Stream.SendStream( player );
            else devprint( "ToClient <" + byte + "> Player is not online." );
        }
    }
    else devprint( "ToClient: Even the byte wasn't specified..." );
}
[/noae][/noae][/noae][/noae][/noae][/noae]

Client Side

you need to download it Client Side and sound in this

I just spilled water on my desk f-ck,
see u guys <3

 :edit: Vehicles.db -  Example DB

KrOoB_


Sebastian

I thought Im the only one thinking about tunning :o