Skip to content

Callout Methods and Events

Daniel K edited this page Jun 28, 2020 · 1 revision

Required methods and events for a callout

The following methods and events must be in your callout class, otherwise it won't work.

All other methods/events can be used, but these are necessary. Check out the callout examples if you are not sure how to use them.

Methods

Available API methods.

OnAccept

Use this to spawn peds and set properties.

public virtual async Task OnAccept() { }

You must override this method.

public override async Task OnAccept()
{
   this.InitBlip(); // InitBlip must be called to spawn the default blip
   // Spawn peds here
}

InitInfo

Initializes the callout.
Must be called from the constructor of your callout.

Params:

  • location
    Type: Vector3
    Description: The world location of the callout.

InitInfo initializes your callout with default values.

protected void InitInfo(Vector3 location)
{
    this.AssignedPlayers = new List<Ped>();
    this.AssignedPlayers.Add(Game.PlayerPed);
    this.CalloutDescription = "<Unnamed Callout Description>";
    this.ShortName = "<Unnamed Callout>";
    this.ResponseCode = -1;
    this.Location = location;
    this.Identifier = Guid.NewGuid().ToString();
}

And you have to call it like:

public MyCallout()
{
    // in the constructor
    base.InitInfo(new Vector3(0,0,0)); // callout location
    // and other details of the call
    this.ShortName = "CalloutName";
    this.CalloutDescription = "Default Description";
    this.ResponseCode = 3;
    this.StartDistance = 20f;
}

SpawnPed

Spawns a networked ped, so others can interact with it as well and not just the callout receiver.
Ped and Vehicle spawning should always happen in the Init() method.

Params:

  • pedHash
    Type: PedHash
    Description: PedHash.
  • location
    Type: Vector3
    Description: The location where the ped spawns.
  • heading
    Type: float
    Description: The direction where the ped is heading (0-360 deg).
Ped ped; // Global Ped
public async override Task OnAccept()
{
  ped = await SpawnPed(PedHash.ChinGoonCutscene, this.Location,12);
}

GetRandomPed

Returns a random PedHash, excluding animals.

Usage:

...
PedHash randomPed = GetRandomPed(); 
...

SpawnVehicle

Spawns a networked vehicle, so others can interact with it as well and not just the callout receiver.
Ped and Vehicle spawning should always happen in the Init() method.

Params:

  • vehicleHash
    Type: VehicleHash
    Description: VehicleHash.
  • location
    Type: Vector3
    Description: The location where the vehicle spawns.
  • heading
    Type: float
    Description: The direction where the vehicle is heading (0-360 deg).
Vehicle veh; // Global Vehicle
public async override Task Init()
{
  veh = await SpawnVehicle(VehicleHash, this.Location,12);
}

Events

Events are triggered when specific, pre-defined events occur in the game. These can be useful to attach your own logic to interact with the world when these events happen.
An event may happen multiple times.

OnAccept

OnAccept will be called when the player accepts the call.
You must call base.OnAccept(args) to initialize the callout with default properties.
You don't need to pass any parameter if you don't want to change the default marker.

Params:

  • (optional) circleRadius
    Type: float
    Default value: 75f Description: The radius of the circle on the map.
  • (optional) blipColor
    Type: BlipColor
    Default value: BlipColor.Yellow
    Description: The color of the Blip.
  • (optional) sprite
    Type: BlipSprite
    Default value: BlipSprite.BigCircle
    Description: Blip sprite.
  • (optional) alpha
    Type: int
    Default value: 100
    Description: The opacity of the circle (100% by default).
 protected void OnAccept(float circleRadius = 75f, BlipColor color = BlipColor.Yellow, BlipSprite sprite = BlipSprite.BigCircle, int alpha = 100)

OnStart

Triggered when the player gets in range of the callout.
Note: You must call the base OnStart event in your overridden OnStart event, as it changes a few data which is necessary to have a properly working callout.

Params:

  • closest
    Type: Ped
    Description: The closest player's ped will be passed as a parameter. (Only players from AssignedPlayers are checked)
public virtual void OnStart(Ped closest)
{
  this.Started = true;
  if (closest.NetworkId != Game.PlayerPed.NetworkId)
  {
    this.AssignedPlayers.Add(closest);               
  }
}

You must override this in your class.

public override void OnStart(Ped closest)
{
 base.OnStart(closes)
 // Do not spawn peds here
 // You could remove the marker from the map once the player gets close enough
 // your event logic goes here...
}

OnBackupCalled

Triggered when the player requests backup. The backup code will be passed as a parameter.
You can create specific events to happen here, such as make the ped flee, etc.

Params:

  • code
    Type: int
    Description: Backup code (1,2,3 or 99)
public virtual void OnBackupCalled(int code) { } // 1,2,3,99

You must override this method if you want to use it.

public override void OnBackupCalled(int code)
{
// event logic
}

OnBackupReceived

Triggered when someone accepts the backup. It may happen multiple times, depending on how many players accept it.
Params:

  • player
    Type: Player
    Description: The player who accepted the backup request.
public virtual void OnBackupReceived(Player player) { }

You must override this method if you want to use it.

public override void OnBackupReceived(Player player) 
{ 
// event logic
}

OnPlayerRevokedBackup

Triggered when someone who accepted the backup revokes it or cancels the call.
Params:

  • player
    Type: Player
    Description: The player who revoked the backup.
public virtual void OnPlayerRevokedBackup(Player player) { } 

You must override this method if you want to use it.

public override void OnPlayerRevokedBackup(Player player) 
{ 
// event logic
} 

OnCancelBefore

Triggered after the callout is completed (or cancelled), but before removing the entities from the map (by the object deleter)

public virtual void OnCancelBefore() {}

You must override this method if you want to use it.

public override void OnCancelBefore() 
{
// event logic
}

OnCancelAfter

Triggered after the callout is completed (or cancelled), but after removing the entities from the map (by the object deleter)

public virtual void OnCancelAfter() { }

You must override this method if you want to use it.

public override void OnCancelAfter() 
{ 
// event logic
}

For a more detailed Callout lifecycle documentation, click here