Jump to content

Help with creating dynamic callouts


LordRaven

Recommended Posts

I have been trying to create my callouts so that they have different things that can happen in them instead of the suspect always running or always shooting when you arrive. So far in the Process function

public override void Process()
{
  base.Process();
}

I create my Random var that I call to determine if a certain event happens

 

            Random fight = new Random();
            Random flee = new Random();
            Random surrender = new Random();
            Random talk = new Random();
            var Fight = fight.Next(1, 10);
            var Flee = flee.Next(10, 25);
            var Surrender = surrender.Next(25, 35);
            var Talk = talk.Next(35, 45);

than I call the fight.next to get a new var for the next if function

            fight.Next();
            if (Fight <= 11 && Game.LocalPlayer.Character.DistanceTo(Suspect.Position) < 10f)
{
//Do scripted event
}

If that returns back false I have and else if statement to handle the next set

            else
                flee.Next();        
            if (Flee <= 16 && !PursuitCreated && Game.LocalPlayer.Character.DistanceTo(Suspect) < 10f)
{
//Do scripted flee event
}

so on and so forth. The problem I am having is that I tend to get the same scripted events such as fight or flee. Sometimes the suspect will get stuck in a surrender, flee. I do end all this with a

else
return;

statement in case all of the return false so that it can start over until one returns true.

 

Now this is all in theory I need to know if this is some way to handle this or not. Been working on this for a few days now and I can get each section to run if I disable the others, but sometimes I notice I get stuck in my first if statement always returning true. I also notice that at times if the suspect fights the victim and the suspect gets killed the blip wont be removed until the next callout is forced. I end everything in

if (suspect.IsDead)
{End();}

or something similiar such as iscuffed. Am I using those statements correctly? I am willing to let someone look over my code and tell me if it makes sense to them, Would just like to figure this out and get more callouts made.

 

Thanks in advance.

Check out my youtube videos of LSPDFR!

https://www.youtube.com/user/RavenYeshina

 

 

Link to comment
Share on other sites

Spoiler
1 hour ago, LordRaven said:

I have been trying to create my callouts so that they have different things that can happen in them instead of the suspect always running or always shooting when you arrive. So far in the Process function



public override void Process()
{
  base.Process();
}

I create my Random var that I call to determine if a certain event happens

 



            Random fight = new Random();
            Random flee = new Random();
            Random surrender = new Random();
            Random talk = new Random();
            var Fight = fight.Next(1, 10);
            var Flee = flee.Next(10, 25);
            var Surrender = surrender.Next(25, 35);
            var Talk = talk.Next(35, 45);

than I call the fight.next to get a new var for the next if function



            fight.Next();
            if (Fight <= 11 && Game.LocalPlayer.Character.DistanceTo(Suspect.Position) < 10f)
{
//Do scripted event
}

If that returns back false I have and else if statement to handle the next set



            else
                flee.Next();        
            if (Flee <= 16 && !PursuitCreated && Game.LocalPlayer.Character.DistanceTo(Suspect) < 10f)
{
//Do scripted flee event
}

so on and so forth. The problem I am having is that I tend to get the same scripted events such as fight or flee. Sometimes the suspect will get stuck in a surrender, flee. I do end all this with a



else
return;

statement in case all of the return false so that it can start over until one returns true.

 

Now this is all in theory I need to know if this is some way to handle this or not. Been working on this for a few days now and I can get each section to run if I disable the others, but sometimes I notice I get stuck in my first if statement always returning true. I also notice that at times if the suspect fights the victim and the suspect gets killed the blip wont be removed until the next callout is forced. I end everything in



if (suspect.IsDead)
{End();}

or something similiar such as iscuffed. Am I using those statements correctly? I am willing to let someone look over my code and tell me if it makes sense to them, Would just like to figure this out and get more callouts made.

 

Thanks in advance.

 

I'd recommend creating a class that is used just for calling random number, like this (this may be wrong, I lost my common file so I don't remember exactly how I did it:

class RandomNumber
{
	public RandomNumber RandomNumber()
	{
		return new Random();
	}
}

Then you'll want to do something like this in your Process() loop:

(Edit: I just noticed an error; the class above should be labeled "Random" not "RandomNumber".  That will allow the code below to be correct)

Process()
{
  //Create your random number once to determine your outcome
  int ran = Random.RandomNumber.Next(1, 4)
  if (ran == 1)
  {
    CallFightCodeHere();
  }
  else if (ran == 2)
  {
    CallFleeCodeHere();
  }
  else if (ran == 3 || ran == 4)
  {
    //This will have a higher chance of occuring because it checks for 2 numbers
    CallOtherCodeHere();
  }
  else
  {
    DoSomethingElse;
  }
}

As for the blip not being removed, make sure you check to see that it's being deleted in your End() like:

if (myBlip.exists()) myBlip.Delete();


As for checking to see if your suspect is dead/arrested, I have a method I've created in a separate class (ExtensionMethods) and call during my process.  To use it you'll need to add your suspect(s) to a list you create and pass that to this method.  Here's an example:

 

//Add suspect to list when you create him
private Ped mySuspect;
private List<Ped> susList = new List<Ped>();
public bool OnCalloutAccepted()
{
  mySuspect = new Ped(myspawn);
  susList.Add(mySuspect);
}

public Process()
{
  base.Process;
  //Run some code (like above)
  
  // This will return true when every suspect in your susList (if they exist) is arrested or dead
  if (ExtensionMethods.PedCheck(susList))
    this.End()
}



class ExtensionsMethods
{
          public static bool PedCheck(this List<Ped> peds)
        {
            AddLog(peds.Count.ToString());
            if (peds.Count >= 1)
            {
                foreach (Ped ped in peds)
                {
                    if (ped)
                    {
                        if (Functions.IsPedArrested(ped))
                        {
                            continue;
                        }
                        else if (ped.IsDead)
                        {
                            continue;
                        }
                        else
                            return false;
                    }
                    else
                        return false;
                }
                return true;
            }
            else
                return false;
        }
}

This is a quick summary all from memory, so it may not be correct.  Dynamic callouts are hard to make, but they can make or break a callout!

Good luck!

Edited by Fiskey111
Added correction

 

 

Link to comment
Share on other sites

Also remember that Process gets called on every tick. So if you're going to have random chances of different things happen, you need to track which decision you made, and store that somewhere so you don't keep randomly choosing actions over and over again, hundreds of times a minute. An easy way to do this is to create an enum of possible states, then choose randomly from that enum in your OnCalloutAccepted method. Store the chosen enum value then refer to that as appropriate in Process.

[REL] Coastal Callouts: An action-packed mod with new vehicles, maps, capabilities, and callouts in and around the waters of Los Santos

[REL] Police Tape: Make your scenes more realistic while stopping peds and traffic

[REL] Better EMS: Realistic and dynamic EMS response

Join the Parks Benefactor Program to support my work and get early beta access!

Link to comment
Share on other sites

Thank you both for your input, it seems that using the enum is doing what I need. Now i am having problems with the displaying of subtitles. How do I get it to wait for the user to press a key, I have it set to

                    if (Game.IsKeyDownRightNow(System.Windows.Forms.Keys.Y))
                    {
                        Game.DisplaySubtitle("Suspect: Don't come any closer or they die!", 3000);
                        Game.DisplaySubtitle("Me:Put the gun down!", 3000);
                        GameFiber.Yield();
                    }

This does display the subtitles, but it shows them as soon as accepting the callout, and after that I want the suspect to surrender by placing his hands up. All he does right now is have a seizure as soon as I accept the callout.

Check out my youtube videos of LSPDFR!

https://www.youtube.com/user/RavenYeshina

 

 

Link to comment
Share on other sites

Spoiler
18 minutes ago, LordRaven said:

Thank you both for your input, it seems that using the enum is doing what I need. Now i am having problems with the displaying of subtitles. How do I get it to wait for the user to press a key, I have it set to



                    if (Game.IsKeyDownRightNow(System.Windows.Forms.Keys.Y))
                    {
                        Game.DisplaySubtitle("Suspect: Don't come any closer or they die!", 3000);
                        Game.DisplaySubtitle("Me:Put the gun down!", 3000);
                        GameFiber.Yield();
                    }

This does display the subtitles, but it shows them as soon as accepting the callout, and after that I want the suspect to surrender by placing his hands up. All he does right now is have a seizure as soon as I accept the callout.

 

My assumption is that as you press "Y" to accept the callout and the code advances to Process() it still is registering you pressing "Y".  I'd running a check to see if the player is on scene first before allowing that code snippet to run.

 

 

Link to comment
Share on other sites

Adding a speech check didn't work as I thought, here is the speech code

            else
            if (calloutState == CalloutState.Talk || calloutState == CalloutState.Talk2)
            {
                if (Game.LocalPlayer.Character.DistanceTo(Suspect.Position) < 10f)
                        {
                    Game.DisplayHelp("Press Y to talk.");
                    SpeechCheck = false;
                        if (SpeechCheck = false && Game.IsKeyDown(System.Windows.Forms.Keys.Y))
                        {
                        Game.DisplaySubtitle("Me:Put the gun down!", 3000);
                        Game.DisplaySubtitle("Suspect: Don't come any closer or they die!", 3000);
                        SpeechCheck = true;
                        }

                        Suspect.Tasks.PutHandsUp(-1, Game.LocalPlayer.Character);
                        Victim.Tasks.Flee(Suspect, 1000000, -1);

                        if (Suspect.IsDead)
                        { End(); }

                        if (Suspect.IsCuffed)
                        { End(); }
                    }                
            } 

This yields no text being written to screen

Check out my youtube videos of LSPDFR!

https://www.youtube.com/user/RavenYeshina

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...