Basic car lock system (tested&working)

Started by Sonmez, May 04, 2020, 07:58 PM

Previous topic - Next topic

Sonmez

function onScriptLoad()
{
    Vehicles<- ConnectSQL( "Vehicles.db" );
    QuerySQL( Vehicles, "CREATE TABLE IF NOT EXISTS Cars ( Vehicle NUMERIC DEFAULT 0 , Locked NUMERIC DEFAULT 0)" );
}

function onPlayerEnteringVehicle(player,vehicle, door)
{
    local p = QuerySQL(Vehicles, "SELECT * FROM Cars WHERE Vehicle = '" +vehicle.ID + "'");
    if (p)
    {
        if (GetSQLColumnData(p,1).tointeger() == 1) //it means locked
        {
            return false;
        }
        else
        {
            return 1;
        }
    }
else
{
return true;
}
}

function onPlayerCommand(player,cmd,text)
{
    if(cmd == "lock")
    {
        if (!player.Vehicle){MessagePlayer("You aren't in any vehicle", player); return false;}
        local p = QuerySQL(Vehicles, "SELECT * FROM Cars WHERE Vehicle = '" +player.Vehicle.ID + "'");
        if (p)
        {
            QuerySQL( Vehicles, "UPDATE Cars SET Locked='"+1+"' WHERE Vehicle LIKE '" + player.Vehicle.ID + "'" );
        }
        else
        {
            QuerySQL( Vehicles, "INSERT INTO Cars ( Vehicle, Locked) VALUES ( '" + player.Vehicle.ID + "', '" +1 + "')" );
        }
    }
    if(cmd == "unlock")
    {
        if (!player.Vehicle){MessagePlayer("You aren't in any vehicle", player); return false;}
        local p = QuerySQL(Vehicles, "SELECT * FROM Cars WHERE Vehicle = '" +player.Vehicle.ID + "'");
        if (p)
        {
            QuerySQL( Vehicles, "UPDATE Cars SET Locked='"+0+"' WHERE Vehicle LIKE '" + player.Vehicle.ID + "'" );
        }
        else
        {
            QuerySQL( Missions, "INSERT INTO Vehicles ( Vehicle, Locked) VALUES ( '" + player.Vehicle.ID + "', '" +0 + "')" );
        }
    }
}

function onPlayerExitVehicle(player, vehicle)
{
        local p = QuerySQL(Vehicles, "SELECT * FROM Cars WHERE Vehicle = '" +vehicle.ID + "'");
        if (p)
        {
            QuerySQL( Vehicles, "UPDATE Cars SET Locked='"+0+"' WHERE Vehicle LIKE '" + vehicle.ID + "'" );
        }
}

function onPlayerPart(player)
{
if (player.Vehicle)
{
    local p = QuerySQL(Vehicles, "SELECT * FROM Cars WHERE Vehicle = '" +player.Vehicle.ID + "'");
    if (p)
    {
        QuerySQL( Vehicles, "UPDATE Cars SET Locked='"+0+"' WHERE Vehicle LIKE '" + player.Vehicle.ID + "'" );
    }
}
}
if (!perfect) createAgain();

umar4911

https://forum.vc-mp.org/?topic=898.0

QuoteVerify that the script is working properly.
Take your script, extract it, and start fresh with the latest Squirrel server available. If you are using a database, erase it and start from scratch. Make absolutely sure that all functions and commands are working as they should.

If your script uses a database, make sure that you either add a bare-bones Database file with all unnecessary entries removed, or that you include a file with the CREATE TABLE/INSERT statements that need to be run.

The title......
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

Sonmez

Quote from: umar4911 on May 04, 2020, 09:00 PMhttps://forum.vc-mp.org/?topic=898.0

QuoteVerify that the script is working properly.
Take your script, extract it, and start fresh with the latest Squirrel server available. If you are using a database, erase it and start from scratch. Make absolutely sure that all functions and commands are working as they should.

If your script uses a database, make sure that you either add a bare-bones Database file with all unnecessary entries removed, or that you include a file with the CREATE TABLE/INSERT statements that need to be run.

The title......

Tested now
if (!perfect) createAgain();