-
Notifications
You must be signed in to change notification settings - Fork 4
Callout Template
Matthew edited this page Aug 4, 2022
·
6 revisions
Here's how a typical YobbinCallout is set up:
` //A Yobbin Callout namespace YobbinCallouts.Callouts { [CalloutInfo("A Yobbin Callout", CalloutProbability.High)] class AYobbinCallout : Callout { //Declarations of local variables go here private Vector3 MainSpawnPoint;
//These two variables are always required
private int MainScenario; //If there are multiple callout scenarios, which one, starting from zero.
private bool CalloutRunning; //If the callout is currently running or not.
//pre-callout logic
public override bool OnBeforeCalloutDisplayed()
{
Game.LogTrivial("==========YOBBINCALLOUTS: A Yobbin Callout Start=========="); //All callout starts are logged like this
System.Random r = new System.Random();
int Scenario = r.Next(0, 2); //Scenario chooser. In this case, there are two scenarios, 0 and 1.
MainScenario = Scenario;
Game.LogTrivial("YOBBINCALLOUTS: Scenario value is: " + MainScenario);
MainSpawnPoint = World.GetNextPositionOnStreet(player.Position.Around(600)); //get the Main Spawn point.
//or, CallHandler.locationchooser
ShowCalloutAreaBlipBeforeAccepting(MainSpawnPoint, 25f);
AddMinimumDistanceCheck(60f, MainSpawnPoint);
Functions.PlayScannerAudio("ATTENTION_ALL_UNITS_01 AUDIO");
CalloutMessage = "A Yobbin Callout";
CalloutPosition = MainSpawnPoint;
if (MainScenario == 0) CalloutAdvisory = "Description for scenario 0.";
else CalloutAdvisory = "Description for scenario 1";
return base.OnBeforeCalloutDisplayed();
}
public override bool OnCalloutAccepted()
{
try
{
Game.LogTrivial("YOBBINCALLOUTS: A Yobbin Callout Accepted by User");
if (Main.CalloutInterface)
{
CalloutInterfaceHandler.SendCalloutDetails(this, "CODE 03", ""); //For Opus' Callout Interface Plugin
}
else
{
Game.DisplayNotification("Respond ~r~Code 03"); //If they don't have the plugin installed
}
if (MainScenario == 0)
{
//Callout setup, instantiating stuff depending on the scenario
}
}
catch (Exception e) //standard error message for callout initializing
{
Game.LogTrivial("==========YOBBINCALLOUTS: ERROR CAUGHT ON CALLOUT INTIALIZATION==========");
Game.LogTrivial("IN: " + this);
string error = e.ToString();
Game.LogTrivial("ERROR: " + error);
Game.DisplayNotification("There was an ~r~Error~w~ Caught with ~b~YobbinCallouts. ~w~Please Check Your ~g~Log File.~w~ Sorry for the Inconvenience!");
Game.DisplayNotification("Error: ~r~" + error);
Game.LogTrivial("If You Believe this is a Bug, Please Report it on my Discord Server. Thanks!");
Game.LogTrivial("==========YOBBINCALLOUTS: ERROR CAUGHT ON CALLOUT INTIALIZATION==========");
}
if (!CalloutRunning) { Callout(); } //Call the Callout method itself
return base.OnCalloutAccepted();
}
public override void OnCalloutNotAccepted()
{
Game.LogTrivial("YOBBINCALLOUTS: Active Shooter Callout Not Accepted by User.");
//Functions.PlayScannerAudio("OTHER_UNIT_TAKING_CALL_02");
base.OnCalloutNotAccepted();
}
//For Callout logic
private void Callout()
{
CalloutRunning = true; //set the callout to be running
GameFiber.StartNew(delegate //start a new GameFiber
{
try
{
while (CalloutRunning) //similar to lspfr's Process() method
{
//all your callout logic goes here (or calling other methods)
break; //break out of the callout loop when done
}
GameFiber.Wait(2000);
Game.LogTrivial("YOBBINCALLOUTS: Callout Finished, Ending...");
EndCalloutHandler.EndCallout(); //call the End Callout Handler (you don't need to worry about this)
End();
}
catch (Exception e) //similar error catching to before
{
if (CalloutRunning) //if the callout is currently running
{
Game.LogTrivial("==========YOBBINCALLOUTS: ERROR CAUGHT==========");
Game.LogTrivial("IN: " + this);
string error = e.ToString();
Game.LogTrivial("ERROR: " + error);
Game.DisplayNotification("There was an ~r~Error~w~ Caught with ~b~YobbinCallouts. ~w~Please Check Your ~g~Log File.~w~ Sorry for the Inconvenience!");
Game.DisplayNotification("Error: ~r~" + error);
Game.LogTrivial("If You Believe this is a Bug, Please Report it on my Discord Server. Thanks!");
Game.LogTrivial("==========YOBBINCALLOUTS: ERROR CAUGHT==========");
}
else //sometimes, an error will be thrown if the callout is no longer running, especially if it was forced finished early
{
Game.LogTrivial("==========YOBBINCALLOUTS: ERROR CAUGHT - CALLOUT NO LONGER RUNNING==========");
string error = e.ToString();
Game.LogTrivial("ERROR: " + error);
Game.LogTrivial("No Need to Report This Error if it Did not Result in an LSPDFR Crash.");
Game.LogTrivial("==========YOBBINCALLOUTS: ERROR CAUGHT - CALLOUT NO LONGER RUNNING==========");
}
End();
}
});
}
public override void End() //cleanup
{
base.End();
if (CalloutRunning) //play and display a Code 4 message iff the callout is still running
{
Game.DisplayNotification("~g~Code 4~w~, return to patrol.");
Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE_4");
}
CalloutRunning = false; //once this is done, set the callout to no longer running
if (SuspectBlip.Exists()) { SuspectBlip.Delete(); } //delete anything else
Game.LogTrivial("YOBBINCALLOUTS: Active Shooter Callout Finished Cleaning Up."); //log it
}
public override void Process() //you don't need this but if you want to use it instead of my method, go ahead
{
base.Process();
}
}
} `