Quantcast

Jump to content

» «
Photo

Help performing function on every ped in ped array

3 replies to this topic
Dev614
  • Dev614

    Player Hater

  • Members
  • Joined: 26 Sep 2015
  • United-States

#1

Posted 3 weeks ago Edited by Dev614, 3 weeks ago.

I'm trying to perform the functions GET_PED_TYPE and IS_PED_IN_ANY_VEHICLE on every ped in the ped array of peds near me (using World.GetNearbyPeds(Game.Player.Character.Position, 200f)). I'm stuck here, I'm trying to check for any ped near me that is in a vehicle, and if he is in the vehicle, if he is a gang member and if so, I want to change the relationship group so he no longer attacks "Hated" peds and causes traffic jams.


ikt
  • ikt

    _

  • Members
  • Joined: 02 Oct 2006
  • None

#2

Posted 3 weeks ago

Do you know how to iterate over arrays?

Dev614
  • Dev614

    Player Hater

  • Members
  • Joined: 26 Sep 2015
  • United-States

#3

Posted 3 weeks ago Edited by Dev614, 3 weeks ago.

I've been trying to set up a loop to no avail.

 

Would it go something like this?

?? and then follow it with an if statement checking if it's equal to a certain value? I'm just learning to code, forgive my ignorance.

Ped[] peds = World.GetNearbyPeds(Game.Player.Character.Position, 200f);

foreach (Ped p in peds)
{
        Function.Call(Hash.GET_PED_TYPE);
}

Or would a for statement be better? Something like:

Ped[] peds = World.GetNearbyPeds(Game.Player.Character.Position, 200f);
int pedcount = peds.Length;

for (int i = 1; i <= pedcount; i++)
{
      Function.Call(Hash.GET_PED_TYPE);
}

Dev614
  • Dev614

    Player Hater

  • Members
  • Joined: 26 Sep 2015
  • United-States

#4

Posted 3 weeks ago

@ikt I've got the script up and running using that foreach function, just a little edited. Thank you for the resource! I was experimenting with the foreach function earlier but I set it up wrong, the resource you shared showed me my error. I appreciate it! :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users