Utilities
Namespace: FivePD.API#
File: Source/Utilities.cs#
These utility functions can be used in both callouts and plugins.
Enums#
Services#
- Ambulance
0 - AirAmbulance
1 - FireDept
2 - Coroner
3 - AnimalControl
4 - TowTruck
5 - Mechanic
6 - PrisonTransport
7
Methods#
GetPassengersFromTrafficStop#
Returns an array of passenger peds from the pulled over vehicle.
caution
The driver ped will not be added into the array.
Returns: Ped[]
Params: -
Example#
var passengers = Utilities.GetPassengersFromTrafficStop();GetDriverFromTrafficStop#
Returns the driver ped from of pulled over vehicle.
Returns: Ped
Params: -
Example#
var driver = Utilities.GetDriverFromTrafficStop();SetPlayerData#
Changing the player's data will be saved in the database.
Returns: -
Params:
- playerData
- Type: PlayerData
- The data that you want to set
- setPlayerDataFlags
- Type: SetPlayerDataFlags
- The data that you want to set with the playerData object
Example#
var playerData = new PlayerData();playerData.DepartmentID = -1;
// This will kick the player from the department (only changes the department id)Utilities.SetPlayerData(playerData, SetPlayerDataFlags.DepartmentID);EnableMod#
Enables the mod for the local player. Can be useful to make FivePD to work along with other resources.
Can be called dynamically. (can be toggled)
Returns: -
Params: -
Example#
EnableMod();DisableMod#
Disables the mod for the local player. Can be useful to make FivePD to work along with other resources.
Can be called dynamically. (can be toggled)
Returns: -
Params: -
Example#
DisableMod();GetRandomPosInPlayerDepartmentArea#
Returns a random position within the range of the player's department.
Returns: Vector3
Params: -
Example#
var position = GetRandomPosInPlayerDepartmentArea();GetClosestPed#
Returns the closest ped to the given ped's location.
Returns: Ped
Params:
- ped
- Type: Ped
- Ped
Example#
TO get the closest ped to the player
Ped closest = GetClosestPed(Game.PlayerPed);IsPlayerOnDuty#
Returns whether the local player is on duty.
Returns: bool
Params: -
Example#
bool isOnDuty = IsPlayerOnDuty();SetPlayerDuty#
Sets the local player's duty status.
Returns: -
Params:
- onDuty
- Type: bool
trueavailable,falseotherwise
Example#
SetPlayerDuty(true); // to set the player on dutySyncBlip#
Syncs a blip globally (every player on the server will be able to see the synced blip).
Returns: -
Params:
- blip
- Type: Blip
- The blip that you want to sync
Example#
Blip blip = World.CreateBlip(...); // spawn blip with your settingsSyncBlip(blip);SyncBlipWithRadius#
Syncs a blip globally with radius .
Returns: -
Params:
- blip
- Type: Blip
- The blip that you want to sync
- radius
- Type: float
- The blip's radius
Example#
Blip blip = World.CreateBlip(...); // spawn blip with your settingsSyncBlipWithRadius(blip,125f); // sync the blip with 125f radiusSyncBlipDelete#
Deletes a (previously) synced blip (from every connected client).
Returns: -
Params:
- blip
- Type: Blip
- The blip that you want to delete (and was previously synced)
Example#
Blip blip = World.CreateBlip(...); // spawn blip with your settingsSyncBlip(blip);...// later in your codeSyncBlipDelete(blip); // the blip will be deleted from every clientRequestBackup#
Requests backup for the local player (if the player is in a department).
Returns: -
Params:
- backup
- Type: Backups
- The code of the backup request (
1,2,3,99)
Example#
RequestBackup(Backups.Code1); // To request Code1 backupCancelBackup#
Cancels the current backup request.
Returns: -
Params: -
Example#
CancelBackup(); // The current backup will be cancelledForceCallout#
caution
If there are multiple callouts with the same name, the first in the collection will be selected.
Forces a FivePD callout by its GUID or name.
If the callout could not be found, an error message will be displayed in the console.
Returns: -
Params:
- identifier
- Type: string
- The name or GUID of the callout
Example#
ForceCallout("a6f854c1-371a-4b2b-93c5-d99989552898"); // Forces a callout with the given GUID...ForceCallout("Mugging"); // Forces the "Mugging" calloutGetCurrentCallout#
Returns the current (ongoing) callout.
Returns: Callout
Params: -
Example#
FivePD.API.Callout callout = GetCurrentCallout();GetCallouts#
Returns a list of every enabled callout.
Returns: List<Callout>
Params: -
Example#
var callouts = GetCallouts();ExcludeVehicleFromTrafficStop#
The vehicle won't stop when the player initiates a traffic stop on the given vehicle.
Returns: -
Params:
- networkId
- Type: int
- The network id of the vehicle
Example#
ExcludeVehicleFromTrafficStop(vehicle.NetworkId);IsPlayerPerformingTrafficStop#
Returns whether the local player is performing a traffic stop.
Returns: bool
Params: -
Example#
bool isPlayerInTrafficStop = IsPlayerPerformingTrafficStop();GetVehicleFromTrafficStop#
caution
Returns null if the player is not in a traffic stop or the vehicle could not be found.
Returns the vehicle from the current traffic stop.
Returns: Vehicle
Params: -
Example#
Vehicle vehicle = GetVehicleFromTrafficStop();RequestService#
Requests a FivePD service to a given position.
You can request the following services:
AmbulanceAirAmbulanceFireDeptCoronerAnimalControlTowTruckMechanicPrisonTransport
Returns: -
Params:
- service
- Type: Service
- The type of the requested service
- position
- Type: Vector3
- The position where you want to request the service
Example#
RequestService(Services.Ambulance,new Vector3(0,0,0));CancelService#
Cancels the previously requested service.
Returns: -
Params:
- service
- Type: Service
- The type of the requested service
Example#
CancelService(Services.Ambulance); // Cancels the previously requested AmbulanceGetVehicleData#
info
This method is also available as a Vehicle extension.
See EntityExtensions class.
Returns a VehicleData object.
Returns: VehicleData
Params:
- networkId
- Type: int
- The network id of the vehicle
Example#
Vehicle vehicle;...VehicleData data = await GetVehicleData(vehicle.NetworkId);
string licensePlate = data.LicensePlate;
string flag = data.Flag;
int ownerNetworkID = data.OwnerNetworkID;
string ownerFirstname = data.OwnerFirstname;
string ownerLastname = data.OwnerLastname;
bool insurance = data.Insurance; // true = valid, false = invalid
bool registration = data.Registration; // true = valid, false = invalid
string color = data.VehicleColor;
string vehicleName = data.Name;
int vehicleID = data.ID;
List<Item> items = data.Items;
foreach (var elem in items){ string itemName = elem.Name; bool isIllegal = elem.IsIllegal;}SetVehicleData#
info
This method is also available as a Vehicle extension.
See EntityExtensions class.
Returns: -
Params:
- networkId
- Type: int
- The network id of the vehicle
- vehicleData
- Type: VehicleData
- The data that you want to set
Example#
VehicleData vehicleData = new VehicleData();// To set insurance statusvehicleData.Insurance = false;// To set registration statusvehicleData.Registration = false;// To set itemsvar items = new List<Item>();
Item phone = new Item { Name = "Phone", IsIllegal = false};
items.Add(phone);vehicleData.Items = items; // to set items
// And then you must call the SetVehicleData method
SetVehicleData(vehicle.NetworkId,vehicleData);GetPlayerData#
Returns FivePD information from the local player.
Returns: PlayerData
Params: -
Example#
PlayerData playerData = GetPlayerData();// To get the name of the playerstring displayName = playerData.DisplayName;// To get the ID of the player's departmentint departmentID = playerData.DepartmentID;// To get the name of the player's departmentstring department = playerData.Department;// To get the player's rankstring rank = playerData.Rank;// To get the player's callsignstring callsign = playerData.Callsign;GetPedData#
info
This method is also available as a Ped extension.
See EntityExtensions class.
Returns FivePD information about the given ped.
Returns: Task<PedData>
Params:
- networkId
- Type: int
- The network id of the ped
Example#
PedData data = await GetPedData(ped.NetworkId); // GetPedData returns a task// To get the name of the pedstring firstname = data.FirstName;string lastname = data.LastName;// To get the warrant (null or empty if none)string warrant = data.Warrant;// To get the licensevar license = data.License;// To get the date of birthstring dob = data.DOB;// To get the ped's blood alcohol leveldouble alcoholLevel = data.BloodAlcoholLevel;// To get the used drugsbool[] drugs = data.DrugsUsed;// drugs[0] -> Meth (if true)// drugs[1] -> Cocaine (if true)// drugs[2] -> Marijuana (if true)// To get the gender of the pedGender gender = data.Gender;// To get the age of the pedint age = data.Age;// To get the home address of the pedstring address = data.Address;// To get the items that the player possessesList<Item> items = data.Items;// To get an item from the liststring name = items[0].Name;bool isIllegal = items[0].IsIllegal;// To get the player's violationsList<Violation> violations = data.Violations;// To get a violation from the liststring offence = violations[0].Offence;string charge = violations[0].Charge;// A way to get the itemsforeach (var elem in items){ string itemName = elem.Name; bool isIllegal = elem.IsIllegal;}// A way to get the violationsforeach (var elem in items){ string offence = elem.Offence; string charge = elem.Charge;}SetPedData#
info
This method is also available as a Ped extension.
See EntityExtensions class.
Sets information about the ped.
Returns: -
Params:
- networkId
- Type: int
- The network id of the ped
- pedData
- Type: PedData
- Object with information about the ped
Example#
First, you need to create a new PedData instance
Ped ped;...PedData data = new PedData();To set the name of the ped
// using the same data object that we've just createddata.FirstName = "...";data.LastName = "...";
Utilities.SetPedData(ped.NetworkId,data);To set used drugs
// using the same data object that we've just createdPedData.Drugs [] usedDrugs = new PedData.Drugs[2]; // if we want only 2 typesusedDrugs[0] = PedData.Drugs.Meth;usedDrugs[1] = PedData.Drugs.Cocaine;
Utilities.SetPedData(ped.NetworkId,data);To set the drivers license (same with other types of licenses, eg hunting)
// using the same data object that we've just createdPedData.License newLicense = new PedData.License();newLicense.Expiration = "10/03/2020";newLicense.Status = PedData.License.State.Expired;
Utilities.SetPedData(ped.NetworkId,data);To set item(s)
// using the same data object that we've just createdItem item = new Item();item.Name = "Phone";item.IsIllegal = false;
data.Items = new List<Item>();
data.Items.Add(item);
Utilities.SetPedData(ped.NetworkId,data);