Skip to content

API v0.6.4

Daniel K edited this page Jun 28, 2020 · 2 revisions

FivePD API Update 0.6.4

You must use this API version for the latest ( 1.0.5 ) FivePD version
Old callouts are still compatible, but you might need to make a few changes.

Download it here

(If I missed something, feel free to open an issue)

New Features

GUID
GetPedData
SetPedData
GetPlayerData (New Callsign property)
GetPlayerDataEvent (New)
CheckRequirements

This method is going to change in the next API version:

base.EndCallout();

GUID

(If you are using Visual Studio or JetBrains Rider, you might already have a GUID, so you can skip this step. However, if you are using Command-line build with csc.exe, you must specify a GUID)

Every callout must specify a GUID (Globally Unique Identifier) to prevent FixedLocation callouts from being spawned multiple times (so to prevent ped stacking).
To generate a GUID, you can use an Online GUID Generator. To add it:

[GuidAttribute("a6f854c1-371a-4b2b-93c5-d99989552898")]
[CalloutProperties("Test", "FivePD", "1.0", Probability.Medium)]
public class Test : CalloutAPI.Callout
{
	...
}

By not specifying a GUID, a warning message will show up: "No GUID".

async GetPedData(int NetworkID)

You cannot use this method in the constructor.

  • NetworkID <int>
    • Description: Network id of the ped (ped.NetworkID)
  • Returns: <dynamic>

Returns the following data of the given ped (with NetworkId)

  • Firstname <string>
  • Lastname <string>
  • Warrant <string>
  • License <string>
  • DOB <string> (mm/dd/yyyy format)
  • AlcoholLevel <double>
  • DrugsUsed <bool []>
  • Gender <string>
  • Age <int>
  • Address <string>
  • Items List<dynamic>
  • Violations List<dynamic>

To get the data, you must spawn the ped, then

Ped ped;
...

dynamic data = await this.GetPedData(ped.NetworkId);

(Example) Usage:

// eg. in Init()
public async override Task Init()
{
	dynamic data = await this.GetPedData(suspect.NetworkId); // you must await it
            
        string firstname = data.Firstname;
}

To get the firstname of the ped:

string firstname = data.Firstname;

To get the lastname of the ped:

string lastname = data.Lastname;

To get the warrant:

string warrant = data.Warrant;

To get the license:

string license = data.License;

To get the date of birth"

string dob = data.DOB;

To get the ped's blood alcohol content:

double alcoholLevel = data.AlcoholLevel;

To get the drugs:

bool[] drugs = data.DrugsUsed;
// drugs[0] -> Meth (if it is true)
// drugs[1] -> Cocaine (if it is true)
// drugs[2] -> Marijuana (if it is true)

To get the gender of the ped:

string gender = data.Gender;

To get the age of the ped:

int age = data.Age;

To get the address of the ped:

string address = data.Address;

To get the items:

  • item is an object and has the following properties:
  • Name and IsIllegal
List<dynamic> items = data.Items;

To get an item

string name = items[0].Name;
bool isIllegal = items[0].IsIllegal

To get the violations:

  • violation is an object and has the following properties:
  • Offence and Charge
List<dynamic> violations = data.Violations;

To get a violation

string offence = violations[0].Offence;
string charge = violations[0].Charge;
// A way to get the items
foreach (var elem in items)
{
	string itemName = elem.Name;
	bool isIllegal = elem.IsIllegal;
}
// A way to get the violations
foreach (var elem in items)
{
	string offence = elem.Offence;
	string charge = elem.Charge;
}

SetPedData(int NetworkID,ExpandoObject PedData)

You cannot use this method in the constructor.

  • NetworkID <int>
    • Description: NetworkId of the ped
  • PedData <ExpandoObject>
    • Description: Ped data

You can set the data of your spawned ped. You don't need to set every detail of your ped, these are just optional. Even if you only set the firstname of the ped, other information will be random.

Optional

  • firstname <string>
  • lastname <string>
  • alcoholLevel <double>
  • drugsUsed <bool []> ([0] -> Meth, [1] -> Cocaine, [2] -> Marijuana) (set each to true or false)
  • items List<object>

First, you need to create a new ExpandoObject:

dynamic pedData = new ExpandoObject();

Firstname,lastname

pedData.firstname = "Example";
pedData.lastname = "Name";

To set the alchol level of the ped:

pedData.alcoholLevel = 0.0;

To set the used drugs:

pedData.drugsUsed = new bool[] {false,false,true}; // [0] -> Meth, [1] -> Cocaine, [2] -> Marijuana

To set the items:

List<object> items = new List<object>();

object phone = new {
	Name = "Phone",
	IsIllegal = false
};

items.Add(phone)
pedData.items = items;

this.SetPedData(ped.NetworkId,pedData);

GetPlayerData()

  • Returns: <dynamic>

You cannot use this method in the constructor.
Returns data of the Player who received the callout

Usage:

dynamic playerData = this.GetPlayerData();

You can obtain the following information about the player:

  • Department <string>
  • DepartmentID <int>
  • DisplayName <string>
  • Rank <string>
  • XP <int>
  • Callsign <string>

To get the name of the player:

string displayName = playerData.DisplayName;

To get the id of the department that the player is in:

int departmentID = playerData.DepartmentID;

To get the department:

string department = playerData.Department;

To get the rank:

string rank = playerData.Rank;

To get the XP:

int xp = playerData.XP;

To get the Callsign:

int xp = playerData.Callsign;

GetPlayerData Event

You can now access the PlayerData object even outside of this API. To receive it, you must pass a Callback, and it returns the playerData dynamic object, which contains the same details as the dynamic that GetPlayerData() returns.

BaseScript.TriggerEvent("FivePD::Addons::GetPlayerData", new Action<object>((playerData) =>
{
   dynamic _playerData = playerData;
}));

CheckRequirements

You can define requirements for your callouts.
If it returns true, your callout will be started, otherwise an other callout will be rolled.
See Issue #10

Example

public override async Task<bool> CheckRequirements()
{
    if (World.CurrentDayTime.Hours < 20)
	return false; // Your callout won't start if the time is less than 20
    return true; // start your callout
}

More things to come in the next API version!