Skip to content

API v1.0.2

Daniel K edited this page Jul 16, 2020 · 2 revisions

FivePD API Update 1.0.2

IsPlayerPerformingTrafficStop (async)

Returns whether the player is performing a traffic stop.

Returns: <bool>

Example:

if(await Utilities.IsPlayerPerformingTrafficStop()) // must be awaited
{
   // Player is performing a traffic stop
   ...
}

GetVehicleFromTrafficStop (async)

Returns the vehicle from the traffic stop. (If the player is not performing a traffic stop, the return value will be null)

Returns <Vehicle>

Example:

...
Vehicle vehicle = await Utilities.GetVehicleFromTrafficStop(); // Must be awaited
if(vehicle != null)
{
  // do stuffs
}
...

RequestBackup

Now you can request player backups aswell.
Backup (enum) can be:

  • Code1
  • Code2
  • Code3
  • Code99

Example:

// Code 1:
Utilities.RequestBackup(Utilities.Backups.Code1);
// Code 2:
Utilities.RequestBackup(Utilities.Backups.Code2);
// Code 3:
Utilities.RequestBackup(Utilities.Backups.Code3);
// Code 99:
Utilities.RequestBackup(Utilities.Backups.Code99);

CancelBackup

Cancels the backup request.

Example:

Utilities.CancelBackup();

ShowNetworkedNotification

Now you can set the notification background color aswell (last,optional parameter).

OnServiceCancelled (event)

Triggered when the player cancels a requested service.
The cancelled service will be passed as a parameter (Utilities.Services)

Example:

Events.OnServiceCancelled += OnServiceCancelled;
...
public async Task OnServiceCancelled(Utilities.Services service)
{
  ...
}

TriggerEvents

An alternative way to utilize FivePD methods is using events. Most of these events work the same as the methods, except you don't need to reference the API ( so you can use these outside of the FivePD folder, in individual scripts ).
More events will be added in future updates.

Event names:

  • FivePD::API::IsPlayerPerformingTrafficStop
    Required: <CallbackDelegate<bool>>
    If no vehicle could be found, the returned network id will be 0 <int>.
  • FivePD::API::GetVehicleFromTrafficStop
    Required: <CallbackDelegate<bool>>
  • FivePD::API::RequestService
    Required: enum value must be passed from the Utilities.Services (eg. 0,1,...) <int>
  • FivePD::API::CancelService
    Required: enum value must be passed from the Utilities.Services (eg. 0,1,...) <int>
  • FivePD::API::RequestBackup
    Required: enum value must be passed from the Utilities.Backups (eg. 0,1,3,99) <int>
  • FivePD::API::CancelBackup

Examples:

TriggerEvent("FivePD::API::IsPlayerPerformingTrafficStop",new Action<bool>((bool isInTrafficStop)=>{
   if(isInTrafficStop)
   {
      // the player is in a traffic stop
   }
});
TriggerEvent("FivePD::API::GetVehicleFromTrafficStop",new Action<int>((int vehicleNetID)=>{
   if(vehicleNetID == 0)
   {
       Debug.WriteLine("No vehicle could be found!");
       return;
   }
});
TriggerEvent("FivePD::API::RequestService",0); // To request an ambulance
TriggerEvent("FivePD::API::CancelService",0); // To cancel the amublance
TriggerEvent("FivePD::API::RequestBackup",1); // To request Code1 backup
TriggerEvent("FivePD::API::CancelBackup"); // To cancel the recently requested backup