Help please! Functions and code doesn't work

Hello,

I need help. You are my last hope. Otherwise I will give up my project.
I am trying to use certain functions in C# but it doesn’t work! I am trying to code a mod. And for that project I need to use an entity iteration. I have found that functions:
FIND_FIRST_PED and FIND_NEXT_PED
In Lua it works well. But in C# it doesn’t work at all!
In the in-game console I have an error
Also I don’t really understand how these functions work, it seems that they return 2 values. Here is a piece of the code:

public class Class1 : BaseScript 
{
     public Class1()
     {
     Tick += OnTick;
      }

     public async Task OnTick()
     {
          await Delay(0);
          var handle = 0;
          var success = false;
          OutputArgument entityOut = new OutputArgument();
          Function.Call<int>(Hash.FIND_FIRST_PED, entityOut);
          int ped = entityOut.GetResult<int>();

           do
           {
                  Vector3 Pos = Function.Call<Vector3>(Hash.GET_ENTITY_COORDS, ped);
                  API.DrawMarker(1, Pos.X, Pos.Y, Pos.Z - 1f, 0f, 0f, 0f, 0f, 0f, 0f, .8f, 8f, 2f, 255, 255, 0, 75, false, false, 2, false, null, null, false);

                  OutputArgument nextEntityOut = new OutputArgument();
                  success = Function.Call<bool>(Hash.FIND_NEXT_PED, handle, nextEntityOut);
                  ped = nextEntityOut.GetResult<int>();
          }
          while (success == true);
          Function.Call(Hash.END_FIND_PED, handle);
    }

foreach (Ped ped in new PedsPool())
{
    // do whatever you want to Ped
}

woow! It works! Thank you very much @hydrogen !!! :hugs:
I am so happy!

Just a last question: How can I call a function and avoid “Value does not fall within the expected range” error, in a tick.
For example:

public async Task OnTick()
{
        foreach (Ped ped in new PedsPool())
        {
            FunctionToApplyToEachPed(ped);
        }
}

FunctionToApplyToEachPed(Ped currentPed)
{
           Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, currentPed, 5, true);
           Function.Call(Hash.SET_PED_COMBAT_MOVEMENT, currentPed, 3);
           Function.Call(Hash.SET_PED_COMBAT_RANGE, currentPed, 2);
}

Thanks for your replies

Look at what each of those functions need for parameters. If it says int ped you need to do currentPed.Handle. If it says Ped ped, then you can pass the entire ped object itself.

@Briglair You are right. It was this function:

void SET_PED_AS_NO_LONGER_NEEDED(Ped* ped);

Everything works when it is commented.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.