Log in to reply

Ped.isdead issue [C#]

  • Hi,
    I have been trying to make a code so that when I all killed all 13 of spawned in peds it will take me onto the next stage of the code. I made this if (Lost1.IsDead && Lost2.IsDead && Lost3.IsDead && Lost4.IsDead && Lost5.IsDead && Lost6.IsDead && Lost7.IsDead && Lost8.IsDead && Lost9.IsDead && Lost10.IsDead && Lost11.IsDead && Lost12.IsDead && Lost13.IsDead)
    but as you can see it is really long and it does not move me onto the next part.

    Any help would be great.


  • To make it shorter, move the peds into a List<Ped> or Ped[] then use LINQ to check all of them.

    if (lostPeds.All(x => x == null || !x.Exists() || x.IsDead))
        //next stage

  • @Jitnaught Ah, OK. I have all the peds in a List<Ped> already, how would I use a LINQ? I have never had to use one of these before. I understand the code and I can put that into my .cs but I am not sure on how to use a LINQ on my List<Ped>. Could you please show me or tell me how to do so?


  • LINQ is the .All(...) part of that snippet. Make sure to add using System.Linq; to the top of your code.

  • @Jitnaught Oh, OK. Thanks. I have added that to my using part and ill give the code you sent a go. Thanks a tonne.

  • @Jitnaught I have given the code a try, however, it didn't work. I am still stuck in the same case. Is there anything else that could work?

  • That was only for making the line shorter. Why the code is not advancing to the next stage could be of many reasons. We would need to see more of your code.

    One thing you could do is add subtitles in various parts of your code, as a way to easily debug where your code is getting stuck. It may be getting stuck somewhere else in the code.

  • @Jitnaught Not to worry fixed it, thanks.

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.