Jump to content

Combat Peds problem [Callout]


gdanbo

Recommended Posts

I have a problem while trying to make a callout where one ped and one cop shoot at each other, but they don't do it as I want them to. They will shoot at each other but only if they come really close one to another or when I push them with a car. Also they won't walk, but just move really slow without walking. Here are parts of my code in which I think is the problem:

 public override bool OnCalloutAccepted()
        {
            Game.DisplaySubtitle("Get to the ~r~scene~w~.", 7500);
            suspectBlip = mySuspect.AttachBlip();
            suspectBlip.Color = Color.DarkRed;
            suspectBlip.RouteColor = Color.DarkRed;
            suspectBlip.IsRouteEnabled = true;
            Game.DisplayNotification("3dtextures", "mpgroundlogo_cops", "DISPATCH", " ", "Respond CODE 3");
            GameFiber.Sleep(3000);
            Functions.PlayScannerAudio("PROCEED_WITH_CAUTION_01");

            mySuspect.RelationshipGroup = "ATTACKER";
            Game.LocalPlayer.Character.RelationshipGroup = "COP";
            myOfficer.RelationshipGroup = "COP";
            Game.SetRelationshipBetweenRelationshipGroups("ATTACKER", "COP", Relationship.Hate);
            Game.SetRelationshipBetweenRelationshipGroups("COP", "ATTACKER", Relationship.Hate);
            mySuspect.StaysInGroups = true;
            myOfficer.StaysInGroups = true;

            return base.OnCalloutAccepted();
        }

and 

public override void Process()
        {
            base.Process();
            {
                if (Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 80f)
                {
                    suspectBlip.IsRouteEnabled = false;
                    mySuspect.Tasks.FightAgainstClosestHatedTarget(1000f);
                    myOfficer.Tasks.FightAgainstClosestHatedTarget(1000f);
                    mySuspect.CanAttackFriendlies = true;
                    mySuspect.CanBeTargetted = true;
                }
            }
            if (mySuspect.IsCuffed || mySuspect.IsDead)
            {
                this.End();
            }
        }

 

Also, when I try it with mySuspectTasks.FightAgainst(myOfficer); it seems to work, but I want the suspect to shoot at me, the officer and the backup. Please help me

Edited by Boba
Link to comment
Share on other sites

Hey,

 

You can use:

public Task FireWeaponAt(
	Entity target,
	int duration,
	FiringPattern firingPattern
)

And if you want the ped to get closer you can use:

public Task GoToWhileAiming(
	Entity entity,
	Entity entityToAimAt,
	float distanceThreshold,
	float speed,
	bool fireWeapon,
	FiringPattern firingPattern
)

This will make sure that the ped keeps shoothing (or not depending on what you tell him to do)

 

 

Could you try this?

 

Tell me how it went.

 

Greeting juan.

Thank you

Link to comment
Share on other sites

Hi, thanks for helping me out, I'm trying it right now.

Hey, I've just tried it, the suspect's now acting normally and shooting at me, but the problem is he is only shooting at me and not at the officer too. What should I do?

 

Also, for some odd reason, when I try using this: Functions.RequestBackup(Game.LocalPlayer.Character.Position, LSPD_First_Response.EBackupResponseType.Code3, LSPD_First_Response.EBackupUnitType.LocalUnit); unlimited units keep spawning until my game crashes

Edited by gdanbo
Link to comment
Share on other sites

So, depending an what you want you have multiple options:

 

Option 1: Make your suspect fire at a ped, then check if your ped has died if that returns true; make him shoot at you.

 

Option 2: Make your suspect fire at a ped, then when it has died make your suspect fire randomly at all hated peds (or all peds, your choice).

public static Ped[] GetAllPeds();

Use a foreach, and then use an if statments to set a max distance to your ped, check if your ped hate each other, check if any ped is shooting.

 

On the second thing, make sure it is not on a loop, for instance process() is on a loop so if you were to put that code in there without making sure it is only runned once, it wil just keep doing that every iteration. If that is not the case could you provide some code?

 

Greetings juan

Thank you

Link to comment
Share on other sites

16 hours ago, gdanbo said:

Hey, thank you so much! The first thing works, for the second thing, yes, I put it there, I'm not really an expert and I don't really know how to make it run only once

Bool HasItRan = False;

void Process(){
  if(!HasItRan){
    //runcode
  }
}

 

Thank you

Link to comment
Share on other sites

13 hours ago, epicmrjuan said:

Bool HasItRan = False;

void Process(){
  if(!HasItRan){
    //runcode
  }
}

 

dont think thats be best solution as it still runs for more than a tick so you should switch instead.

Link to comment
Share on other sites

Thanks!

1 hour ago, NoNameSet said:

dont think thats be best solution as it still runs for more than a tick so you should switch instead.

 

14 hours ago, epicmrjuan said:

Bool HasItRan = False;

void Process(){
  if(!HasItRan){
    //runcode
  }
}

 

 

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...