Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/KDani-99/FivePD-API
Browse files Browse the repository at this point in the history
  • Loading branch information
KDani-99 committed Dec 14, 2020
2 parents 26cb07e + d95bf6c commit eda0acd
Show file tree
Hide file tree
Showing 12 changed files with 401 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions Examples/Callouts/One project with multiple callouts/Callouts.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Callouts", "Callouts\Callouts.csproj", "{458057BC-1BFA-41D7-AC60-5075A88582AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{458057BC-1BFA-41D7-AC60-5075A88582AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{458057BC-1BFA-41D7-AC60-5075A88582AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{458057BC-1BFA-41D7-AC60-5075A88582AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{458057BC-1BFA-41D7-AC60-5075A88582AA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using CitizenFX.Core;
using FivePD.API;
using FivePD.API.Utils;

namespace Callouts
{
[CalloutProperties("Active shooters", "FivePD", "1.0")]
public class ActiveShooters : FivePD.API.Callout
{
private Ped ped, ped2;
private bool hasStarted;

public ActiveShooters()
{
InitInfo(World.GetNextPositionOnStreet(Game.PlayerPed.GetOffsetPosition(Utils.GetRandomPosition(300,800))));
ShortName = "Active shooters";
CalloutDescription = "";
ResponseCode = 3;
StartDistance = 150f;
}

public override async Task OnAccept()
{
InitBlip();

ped = await SpawnPed(RandomUtils.GetRandomPed(), Location);
ped.KeepTask();
ped.Armor = 3000;
ped2 = await SpawnPed(RandomUtils.GetRandomPed(), Location);
ped2.KeepTask();
ped2.Armor = 3000;

var weapons = new[]
{
WeaponHash.Pistol,
WeaponHash.MicroSMG,
WeaponHash.SawnOffShotgun,
WeaponHash.AssaultRifle,
WeaponHash.SawnOffShotgun,
WeaponHash.HeavySniper
};
ped.Weapons.Give(weapons[Utils.rnd.Next(weapons.Length)], int.MaxValue, true, true);
ped2.Weapons.Give(weapons[Utils.rnd.Next(weapons.Length)], int.MaxValue, true, true);

Tick += Action;
}

public override void OnStart(Ped closest)
{
base.OnStart(closest);
hasStarted = true;
ped.Task.ShootAt(closest);
ped2.Task.ShootAt(closest);
}

public override void OnCancelBefore()
{
Tick -= Action;
base.OnCancelBefore();
}

private async Task Action()
{
if (hasStarted)
{
if(ped.Exists() && ped.IsAlive) await DoTheAction(ped, AssignedPlayers);
if(ped2.Exists() && ped2.IsAlive) await DoTheAction(ped2, AssignedPlayers);
}
else
{
if(ped.Exists() && ped.IsAlive) await DoTheAction(ped, null);
if(ped2.Exists() && ped2.IsAlive) await DoTheAction(ped2, null);
}
await BaseScript.Delay(Utils.rnd.Next(1000, 4500));
}

private async Task DoTheAction(Ped ped, List<Ped> pedsToShoot)
{
Ped pedToShoot = pedsToShoot == null ? Utilities.GetClosestPed(ped) : ped.GetClosestPedFromPedList(pedsToShoot);
if (pedToShoot == null || pedToShoot.IsDead) return;

int chance = Utils.rnd.Next(10);
if(chance >= 0 && chance <= 5)
{
ped.Task.ShootAt(pedToShoot);
}
else
{
Vector3 pos = ped.GetOffsetPosition(Utils.GetRandomPosition(5, 25));
ped.Task.RunTo(pos);
while (World.GetDistance(pos, ped.Position) >= 3f)
{
await BaseScript.Delay(10);
}
ped.Task.ShootAt(pedToShoot);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.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>{458057BC-1BFA-41D7-AC60-5075A88582AA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Callouts</RootNamespace>
<AssemblyName>Callouts.net</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\CitizenFX.Core.1.3.0\lib\net45\CitizenFX.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FivePD.net, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\FivePD.net.1.2.0\lib\net452\FivePD.net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActiveShooters.cs" />
<Compile Include="Mugging.cs" />
<Compile Include="SlowVehicle.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnconsciousPerson.cs" />
<Compile Include="Utils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Threading.Tasks;
using CitizenFX.Core;
using FivePD.API;
using FivePD.API.Utils;

namespace Callouts
{
[CalloutProperties("Mugging", "FivePD", "1.0")]
public class Mugging : FivePD.API.Callout
{
private Ped suspect, victim;

public Mugging()
{
InitInfo(World.GetNextPositionOnStreet(Game.PlayerPed.GetOffsetPosition(Utils.GetRandomPosition())));
ShortName = "Mugging";
CalloutDescription = "";
ResponseCode = 3;
StartDistance = 120f;
}

public override async Task OnAccept()
{
InitBlip();

suspect = await SpawnPed(RandomUtils.GetRandomPed(), Location);
victim = await SpawnPed(RandomUtils.GetRandomPed(), Location);
suspect.KeepTask();
victim.KeepTask();

suspect.Weapons.Give(WeaponHash.Knife, 1, true, true);
}

public override void OnStart(Ped closest)
{
base.OnStart(closest);
Tick += Action;
suspect.Task.FightAgainst(victim, -1);
}

public override void OnCancelBefore()
{
Tick -= Action;
base.OnCancelBefore();
}

private async Task Action()
{
Ped closest = (!victim.Exists() || victim.IsDead) ? suspect.GetClosestPedFromPedList(AssignedPlayers) : victim;
if (closest == null || closest.IsDead) return;
suspect.Task.ClearAll();
if (World.GetDistance(closest.Position, suspect.Position) <= 20f)
{
suspect.Task.FightAgainst(closest);
}
await BaseScript.Delay(2000);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Callouts")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Callouts")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("458057BC-1BFA-41D7-AC60-5075A88582AA")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Threading.Tasks;
using CitizenFX.Core;
using FivePD.API;
using FivePD.API.Utils;
using static CitizenFX.Core.Native.API;

namespace Callouts
{
[CalloutProperties("Slow vehicle", "FivePD", "1.0")]
public class SlowVehicle : FivePD.API.Callout
{
private Ped driver;
private Vehicle vehicle;

public SlowVehicle()
{
InitInfo(World.GetNextPositionOnStreet(Game.PlayerPed.GetOffsetPosition(Utils.GetRandomPosition())));
ShortName = "Slow vehicle";
CalloutDescription = "";
ResponseCode = 2;
StartDistance = 120f;
}

public override async Task OnAccept()
{
InitBlip();

driver = await SpawnPed(RandomUtils.GetRandomPed(), Location);
vehicle = await SpawnVehicle(RandomUtils.GetRandomVehicle(), Location);

driver.KeepTask();
TaskVehicleDriveWander(driver.Handle, vehicle.Handle, 5f, 143);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Threading.Tasks;
using CitizenFX.Core;
using FivePD.API;
using FivePD.API.Utils;

namespace Callouts
{
[CalloutProperties("Unconscious person", "FivePD", "1.0")]
public class UnconsciousPerson : FivePD.API.Callout
{
private Ped ped;

public UnconsciousPerson()
{
InitInfo(World.GetNextPositionOnStreet(Game.PlayerPed.GetOffsetPosition(Utils.GetRandomPosition())));
ShortName = "Unconscious person";
CalloutDescription = "";
ResponseCode = 3;
StartDistance = 200f;
}

public override async Task OnAccept()
{
InitBlip();

ped = await SpawnPed(RandomUtils.GetRandomPed(), Location);

ped.KeepTask();
ped.Kill();
}
}
}
Loading

0 comments on commit eda0acd

Please sign in to comment.