-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 38a9559
Showing
6 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NoCarJack | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using CitizenFX.Core; | ||
using CitizenFX.Core.Native; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NoCarJack | ||
{ | ||
public static class Extension | ||
{ | ||
static Random rnd = new Random(); | ||
|
||
/// <summary> | ||
/// Is vehicle empty, parked or in motion? | ||
/// </summary> | ||
/// <param name="veh"></param> | ||
/// <returns></returns> | ||
public static bool HasDriver(this Vehicle veh) | ||
{ | ||
bool hasDriver = false; | ||
if(veh.Exists() && veh.IsAlive) | ||
{ | ||
if(veh.Driver != null && veh.Driver.Exists() && veh.Driver.IsAlive) | ||
{ | ||
hasDriver = true; | ||
} | ||
} | ||
return hasDriver; | ||
} | ||
|
||
/// <summary> | ||
/// Defines whether the player can actually get inside the vehicle | ||
/// </summary> | ||
/// <returns></returns> | ||
public static bool IsLucky(this Ped ped, int value) | ||
{ | ||
int i = rnd.Next(0, 101); | ||
return i >= value; //luck factor | ||
} | ||
|
||
public static bool IsValid(this Vehicle veh) | ||
{ | ||
return veh != null && veh.Exists() && veh.IsAlive && veh.Speed < 5.0f; | ||
} | ||
|
||
public static bool IsConnected(this Player plyr) | ||
{ | ||
return Function.Call<bool>(Hash.NETWORK_IS_PLAYER_CONNECTED, plyr); | ||
} | ||
|
||
public static Player GetPlayerIndex(this Ped ped) | ||
{ | ||
return Function.Call<Player>(Hash._NETWORK_GET_PED_PLAYER, ped); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
using System; | ||
using System.Drawing; | ||
using CitizenFX; | ||
using CitizenFX.Core; | ||
using CitizenFX.Core.Native; | ||
using System.Collections.Generic; | ||
using System.Windows.Forms; | ||
using System.Threading.Tasks; | ||
using NoCarJack; | ||
|
||
namespace NoCarJack | ||
{ | ||
public class NoCarJack : BaseScript | ||
{ | ||
const string FILENAME = "NoCarJack.net.dll"; | ||
const string VERSION = "1.0.0"; | ||
const string AUTHOR = "winject"; | ||
const string CONFIG_PATH = "NoCarJack.ini"; | ||
|
||
bool SKIP = false; | ||
bool LOCK = false; | ||
Timer unlockTimer = new Timer(0); | ||
Timer skipTimer = new Timer(0); | ||
|
||
Vehicle lastVeh = null; | ||
Vehicle targetVeh = null; | ||
|
||
public NoCarJack() | ||
{ | ||
EventHandlers["nocarjack:skipThisFrame"] += new Action<int, int>(Skip); | ||
base.Tick += OnTick; | ||
} | ||
|
||
/// <summary> | ||
/// Disable the vehicle check temporarily for this player. | ||
/// Allows the player to get in any vehicle, must be triggered server-side! | ||
/// </summary> | ||
/// <param name="playerId">Targetted player ID retrieved with NETWORK_PLAYER_GET_USERID</param> | ||
/// <param name="time">Time before the granted access expires </param> | ||
private void Skip(int playerId, int time) | ||
{ | ||
int id = Game.Player.ServerId; | ||
if(playerId == id) | ||
{ | ||
SKIP = true; | ||
skipTimer.Limit = time; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Main loop | ||
/// </summary> | ||
/// <returns></returns> | ||
private async Task OnTick() | ||
{ | ||
if(SKIP && skipTimer.Expired) | ||
{ | ||
SKIP = false; | ||
} | ||
|
||
if(Game.PlayerPed.Exists() && Game.PlayerPed.IsAlive && Game.PlayerPed.CurrentVehicle != null) | ||
{ | ||
if(Game.PlayerPed.CurrentVehicle.Driver != null) | ||
{ | ||
if(Game.PlayerPed.CurrentVehicle.Driver.Handle == Game.PlayerPed.Handle) | ||
{ | ||
lastVeh = Game.PlayerPed.CurrentVehicle; | ||
} | ||
} | ||
} | ||
|
||
if (Game.PlayerPed.VehicleTryingToEnter != null && Game.PlayerPed.VehicleTryingToEnter.Exists() && !LOCK && !SKIP) | ||
{ | ||
//Check if vehicle is unlocked and free to be entered | ||
if (Function.Call<int>(Hash.GET_VEHICLE_DOOR_LOCK_STATUS, Game.PlayerPed.VehicleTryingToEnter) != 2 && Function.Call<int>(Hash.GET_VEHICLE_DOOR_LOCK_STATUS, Game.PlayerPed.VehicleTryingToEnter) != 10) | ||
{ | ||
targetVeh = Game.PlayerPed.VehicleTryingToEnter; | ||
|
||
if (!Game.PlayerPed.IsLucky(90)) | ||
{ | ||
if (targetVeh.HasDriver()) | ||
{ | ||
if (!IsPedInPlayerList(targetVeh.Driver)) //avoid disabling another's player vehicle | ||
{ | ||
Game.PlayerPed.Task.ClearAll(); | ||
targetVeh.LockStatus = VehicleLockStatus.CannotBeTriedToEnter; | ||
Function.Call(Hash.SET_VEHICLE_UNDRIVEABLE, targetVeh, true); | ||
targetVeh.IsEngineRunning = true; | ||
} | ||
else | ||
{ | ||
|
||
} | ||
} | ||
else | ||
{ | ||
if (!IsVehiclePlayerListLastVehicle(targetVeh)) | ||
{ | ||
if(lastVeh != null) | ||
{ | ||
if(lastVeh.Handle != targetVeh.Handle) | ||
{ | ||
Game.PlayerPed.Task.ClearAll(); | ||
targetVeh.LockStatus = VehicleLockStatus.CannotBeTriedToEnter; | ||
Function.Call(Hash.SET_VEHICLE_UNDRIVEABLE, targetVeh, true); | ||
} | ||
else | ||
{ | ||
|
||
} | ||
} | ||
else | ||
{ | ||
Game.PlayerPed.Task.ClearAll(); | ||
targetVeh.LockStatus = VehicleLockStatus.CannotBeTriedToEnter; | ||
Function.Call(Hash.SET_VEHICLE_UNDRIVEABLE, targetVeh, true); | ||
} | ||
} | ||
else | ||
{ | ||
|
||
} | ||
} | ||
} | ||
else | ||
{ | ||
|
||
} | ||
} | ||
unlockTimer.Limit = 500; | ||
LOCK = true; | ||
} | ||
|
||
if(unlockTimer.Expired && LOCK) | ||
{ | ||
if(Game.PlayerPed.VehicleTryingToEnter != null) | ||
{ | ||
if(targetVeh.Handle == Game.PlayerPed.VehicleTryingToEnter.Handle) | ||
{ | ||
unlockTimer.Limit = 1000; | ||
} | ||
else | ||
{ | ||
LOCK = !LOCK; | ||
} | ||
} | ||
else | ||
{ | ||
LOCK = !LOCK; | ||
} | ||
} | ||
await Task.FromResult(0); | ||
} | ||
|
||
/// <summary> | ||
/// Checks whether the specified ped belongs to a player's ped | ||
/// </summary> | ||
/// <param name="ped"></param> | ||
/// <returns></returns> | ||
private bool IsPedInPlayerList(Ped ped) | ||
{ | ||
PlayerList list = base.Players; | ||
foreach (Player p in list) | ||
{ | ||
if(p.Character == ped) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Checks whether the specified vehicle belongs to another player | ||
/// </summary> | ||
/// <param name="veh"></param> | ||
/// <returns></returns> | ||
private bool IsVehiclePlayerListLastVehicle(Vehicle veh) | ||
{ | ||
PlayerList list = base.Players; | ||
foreach (Player p in list) | ||
{ | ||
if (p.Handle != Game.PlayerPed.Handle) | ||
{ | ||
if (p.Character.LastVehicle != null) | ||
{ | ||
if (p.Character.LastVehicle.Handle == veh.Handle) | ||
{ | ||
//CitizenFX.Core.UI.Screen.ShowNotification("~r~PRIVATE VEHICLE"); | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
//CitizenFX.Core.UI.Screen.ShowNotification("~g~PUBLIC VEHICLE"); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{E07B8A73-40DB-49F4-9EFD-D3B248AD9820}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>NoCarJack.net</RootNamespace> | ||
<AssemblyName>NoCarJack.net</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>false</DebugSymbols> | ||
<DebugType>none</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\..\cfx-server\resources\nocarjack\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="CitizenFX.Core"> | ||
<HintPath>..\..\..\AppData\Local\FiveM\FiveM.app\citizen\clr2\lib\mono\4.5\CitizenFX.Core.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Extension.cs" /> | ||
<Compile Include="Main.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Timer.cs" /> | ||
<Compile Include="Config.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// Les informations générales relatives à un assembly dépendent de | ||
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations | ||
// associées à un assembly. | ||
[assembly: AssemblyTitle("")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("")] | ||
[assembly: AssemblyCopyright("")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly | ||
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de | ||
// COM, affectez la valeur true à l'attribut ComVisible sur ce type. | ||
[assembly: ComVisible(false)] | ||
|
||
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM | ||
[assembly: Guid("e07b8a73-40db-49f4-9efd-d3b248ad9820")] | ||
|
||
// Les informations de version pour un assembly se composent des quatre valeurs suivantes : | ||
// | ||
// Version principale | ||
// Version secondaire | ||
// Numéro de build | ||
// Révision | ||
// | ||
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut | ||
// en utilisant '*', comme indiqué ci-dessous : | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.