Car Jack Script

Started by Kewun, Aug 26, 2016, 06:54 AM

Previous topic - Next topic

Kewun

function onPlayerJackCar(player)
{
local plr = GetClosestPlayer(player, 2)
        if ( !plr ) return false;
local distance = player.Pos.Distance(plr.Pos)
if ( distance < 2 ) {
{
                if ( !plr.Vehicle ) return false;
if ( plr.Vehicle ) {
plr.Eject()
plr.Pos = player.Pos
plr.SetAnim(151)
player.Vehicle = GetClosestVehicle(player,50)
}
}
    }
}
function GetClosestPlayer( source, max_distance = 100 ) {
    local int_MaxPlayers = GetMaxPlayers(), tbl_CloestPlayer = { Instance = null, Distance = max_distance };
        for( local i = 0; i < int_MaxPlayers; ++i ) {
            local player = FindPlayer( i );
            if( player && player.ID != source.ID ) {
                local distance = source.Pos.Distance( player.Pos );
                if( distance < tbl_CloestPlayer.Distance ) {
                    tbl_CloestPlayer.Instance = player;
                    tbl_CloestPlayer.Distance = distance;
                }
            }
        }
    return tbl_CloestPlayer.Instance;
}
function GetClosestVehicle( source, max_distance = 100 ) {
    local int_MaxVehicles = 70000, tbl_CloestVehicle = { Instance = null, Distance = max_distance };
        for( local i = 0; i < int_MaxVehicles; ++i ) {
            local vehicle = FindVehicle( i );
            if( vehicle && vehicle.ID != source.ID ) {
                local distance = source.Pos.Distance( vehicle.Pos );
                if( distance < tbl_CloestVehicle.Distance ) {
                    tbl_CloestVehicle.Instance = vehicle;
                    tbl_CloestVehicle.Distance = distance;
                }
            }
        }
    return tbl_CloestVehicle.Instance;
}
function onScriptLoad()
{
jackcar <- BindKey(true,0x47,0,0)
}
function onKeyDown(player,key)
{
  if ( key == jackcar )
  {
     onPlayerJackCar(player)
   }
}

tested and working

Press G to jack car

credits: Doom_Kill3r for GetClosestPlayer function and GetClosestVehicle