Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Aktarus

[Lua] [C#] Finding Peds or Orbjects around

Recommended Posts

Aktarus

Hello,

 

I am trying to convert this piece of code (Lua) into C#. Any help?

extra natives component with entity iteration nativesusage example:```lualocal handle, ped = FindFirstPed()local successrepeat	local pos = GetEntityCoords(ped)	DrawMarker(1, pos.x, pos.y, pos.z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.8, 0.8, 2.0, 255, 255, 0, 75, 0, 0, 2, 0, 0, 0, 0)	success, ped = FindNextPed(handle)until not successEndFindPed(handle)

Share this post


Link to post
Share on other sites
Aktarus

I have tried that and it only works for the first ped (the Player) I don't know why the loop doesn't work. I suspect the "FIND_NEXT_PED" functions.

Any help?

I precise that this is for a Fivem project

            var handle = 0;            var success = false;            var 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);                var 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);
Edited by Aktarus

Share this post


Link to post
Share on other sites
Guest

Where did you get

Function.Call<int>(Hash.FIND_FIRST_PED, entityOut);

and

Function.Call<bool>(Hash.FIND_NEXT_PED, handle, nextEntityOut);

from?

 

Because as far as I can see, they don't exist on here. http://www.dev-c.com/nativedb/ and if they're not in there, then they don't exist.

 

You can't just create Natives, they have to be valid Native calls and those don't appear to be valid. That means they are probably LUA implementations, which won't work for anything except LUA.

 

If there is nothing that matches, then you are going to have to write the functions that mimic that behaviour, using the Natives that do exist.

Edited by Guest

Share this post


Link to post
Share on other sites
Aktarus

@LeeC2202 it actually exist in fivem extra native. Here: https://runtime.fivem.net/doc/reference.html#_0xfb012961

Most of the docuentation are for LUA, that's frustrating as I am trying to code in C#. That is why I am trying to convert the original code.

I understand the principle but it doesn't work.

By the way I have tried some other functions like "GET_PED_AROUND_PEDS" but nothing works.

Edited by Aktarus

Share this post


Link to post
Share on other sites
Guest

Ah, I apologise for my question then. I didn't realise that FiveM had it's own API extensions. I have only used ScriptHookVDotNet.

 

I have no idea how those FiveM functions work, so I am afraid I can't help you with those.

Share this post


Link to post
Share on other sites
Unknown_Modder

Wait, do you use ScriptHookVDotNet (never used FiveM so I'm not sure how its API works)? If so, use World.GetAllPeds. Also, consider using unsafe code instead of output arguments.

Edited by Unknown_Modder

Share this post


Link to post
Share on other sites
Aktarus

I have tried :

World.GetAllPeds();

Unfortunately, FiveM has deactivated this function (commented)

here is the file: world.cs

/// Gets an <c>array</c>of all <see cref="Ped"/>s in the World./// </summary>/// <param name="models">The <see cref="Model"/> of <see cref="Ped"/>s to get, leave blank for all <see cref="Ped"/> <see cref="Model"/>s.</param>public static Ped[] GetAllPeds(params Model[] models){	return Array.ConvertAll<int, Ped>(MemoryAccess.GetPedHandles(ModelListToHashList(models)), handle => new Ped(handle));}

Share this post


Link to post
Share on other sites
Aktarus

Also, consider using unsafe code instead of output arguments.

 

Sorry, why should I use unsafe code? I don't understand.

Share this post


Link to post
Share on other sites
Unknown_Modder

I'd ask the FiveM devs for support then.

 

Output arguments are just ugly and require more code.

Share this post


Link to post
Share on other sites
Guest

Output arguments are just ugly and require more code.

LOL, that's the worst argument I have seen against using a coding method... it's ugly. You should have seen a straight-lined 6502 smooth-scroll routine on the C64 in assembler if you wanted to see ugly code. :D

 

As for the more code part, I have this to get the ground height, perhaps you could elaborate with an equivalent "unsafe" version that uses less code.

	OutputArgument groundZ = new OutputArgument();	Function.Call(Hash.GET_GROUND_Z_FOR_3D_COORD, position.X, position.Y, position.Z + zoffset, groundZ, 0);	return groundZ.GetResult<float>();

Share this post


Link to post
Share on other sites
Aktarus

@LeeC2202, why I am pretty sure you can help me? :lol:

Please just check this:

The problem with these function (FindFirstPed() and FindNextPed() ) is that they return multiple values. In Lua it's easy to grab them:

local handle, ped = FindFirstPed()

the first value is stored in the variable handle and the second in the variable ped.

This code works very well.

But in C#... I am not an expert... I am stuck :miranda:

Share this post


Link to post
Share on other sites
Guest

The problem is, that FiveM code is just incredibly vague. Where is it collecting the peds based on, i.e. what is the origin point? What radius is it collecting the peds over?

 

I mean the typical SHVDN way would be something like this.

    Ped[] CollectedPeds = World.GetNearbyPeds(Game.Player.Character, 20f);    foreach (Ped collectedPed in CollectedPeds)    {        // Do Code here...    }

That would collect all peds within 20f of the player.

Share this post


Link to post
Share on other sites
Aktarus

Yeah, you are right. Fivem is totally confusing, unfortunately...

Thanks anyway to everyone

Edited by Aktarus

Share this post


Link to post
Share on other sites
Aktarus

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);}

If I put the each "Function.Call" directly in the foreach loop, that works. Like this for example:

public async Task OnTick(){        foreach (Ped ped in new PedsPool())        {            Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, ped , 5, true);            Function.Call(Hash.SET_PED_COMBAT_MOVEMENT, ped , 3);            Function.Call(Hash.SET_PED_COMBAT_RANGE, ped , 2);        }}

Thanks for your reply

 

Edited by Aktarus

Share this post


Link to post
Share on other sites
Aktarus

I have found the error. It was this function:

void SET_PED_AS_NO_LONGER_NEEDED(Ped* ped);

Everything works when it is commented.

Edited by Aktarus

Share this post


Link to post
Share on other sites
husseinh

Hi Guys,

 

I would like to get the coordinates of the Peds arround me.

Game.Player.Character.Position gives me the coordinates of Player(Me) but i don't know how to get the coordinates for others. :facedesk:

 

Thanks alot and sorry for posting here i don't know if its allowed

Edited by husseinh

Share this post


Link to post
Share on other sites
Aktarus

Hi Guys,

 

I would like to get the coordinates of the Peds arround me.

Game.Player.Character.Position gives me the coordinates of Player(Me) but i don't know how to get the coordinates for others. :facedesk:

 

Thanks alot and sorry for posting here i don't know if its allowed

Vector3 Pos = Function.Call<Vector3>(Hash.GET_ENTITY_COORDS, ped);

Then you can get the coordinates at pos.X, pos.Y and pos.Z

Edited by Aktarus

Share this post


Link to post
Share on other sites
husseinh

 

Hi Guys,

 

I would like to get the coordinates of the Peds arround me.

Game.Player.Character.Position gives me the coordinates of Player(Me) but i don't know how to get the coordinates for others. :facedesk:

 

Thanks alot and sorry for posting here i don't know if its allowed

Vector3 Pos = Function.Call<Vector3>(Hash.GET_ENTITY_COORDS, ped);

Then you can get the coordinates at pos.X, pos.Y and pos.Z

 

Thank you! Got it:)

Share this post


Link to post
Share on other sites
Aktarus

 

 

Hi Guys,

 

I would like to get the coordinates of the Peds arround me.

Game.Player.Character.Position gives me the coordinates of Player(Me) but i don't know how to get the coordinates for others. :facedesk:

 

Thanks alot and sorry for posting here i don't know if its allowed

Vector3 Pos = Function.Call<Vector3>(Hash.GET_ENTITY_COORDS, ped);

Then you can get the coordinates at pos.X, pos.Y and pos.Z

 

Thank you! Got it:)

 

 

Or there is also:

foreach (Ped ped in peds){     ped.Position}

Share this post


Link to post
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.


  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.