Aktarus Posted September 7, 2017 Share Posted September 7, 2017 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) Link to comment Share on other sites More sharing options...
Aktarus Posted September 8, 2017 Author Share Posted September 8, 2017 (edited) 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 September 8, 2017 by Aktarus Link to comment Share on other sites More sharing options...
Guest Posted September 9, 2017 Share Posted September 9, 2017 (edited) 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 September 9, 2017 by Guest Link to comment Share on other sites More sharing options...
Aktarus Posted September 9, 2017 Author Share Posted September 9, 2017 (edited) @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 September 9, 2017 by Aktarus Link to comment Share on other sites More sharing options...
Guest Posted September 9, 2017 Share Posted September 9, 2017 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. Link to comment Share on other sites More sharing options...
alloc8or Posted September 9, 2017 Share Posted September 9, 2017 (edited) 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 September 9, 2017 by Unknown_Modder Link to comment Share on other sites More sharing options...
Aktarus Posted September 9, 2017 Author Share Posted September 9, 2017 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));} Link to comment Share on other sites More sharing options...
Aktarus Posted September 9, 2017 Author Share Posted September 9, 2017 Also, consider using unsafe code instead of output arguments. Sorry, why should I use unsafe code? I don't understand. Link to comment Share on other sites More sharing options...
alloc8or Posted September 9, 2017 Share Posted September 9, 2017 I'd ask the FiveM devs for support then. Output arguments are just ugly and require more code. Link to comment Share on other sites More sharing options...
Guest Posted September 9, 2017 Share Posted September 9, 2017 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. 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>(); Link to comment Share on other sites More sharing options...
Aktarus Posted September 9, 2017 Author Share Posted September 9, 2017 @LeeC2202, why I am pretty sure you can help me? 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 Link to comment Share on other sites More sharing options...
Guest Posted September 9, 2017 Share Posted September 9, 2017 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. Link to comment Share on other sites More sharing options...
Aktarus Posted September 9, 2017 Author Share Posted September 9, 2017 (edited) Yeah, you are right. Fivem is totally confusing, unfortunately... Thanks anyway to everyone Edited September 9, 2017 by Aktarus Link to comment Share on other sites More sharing options...
Aktarus Posted September 10, 2017 Author Share Posted September 10, 2017 (edited) 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 September 10, 2017 by Aktarus Link to comment Share on other sites More sharing options...
Aktarus Posted September 10, 2017 Author Share Posted September 10, 2017 (edited) 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 September 10, 2017 by Aktarus Link to comment Share on other sites More sharing options...
husseinh Posted September 12, 2017 Share Posted September 12, 2017 (edited) 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. Thanks alot and sorry for posting here i don't know if its allowed Edited September 12, 2017 by husseinh Link to comment Share on other sites More sharing options...
Aktarus Posted September 13, 2017 Author Share Posted September 13, 2017 (edited) 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. 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 September 13, 2017 by Aktarus Link to comment Share on other sites More sharing options...
husseinh Posted September 15, 2017 Share Posted September 15, 2017 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. 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:) Link to comment Share on other sites More sharing options...
Aktarus Posted September 16, 2017 Author Share Posted September 16, 2017 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. 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} Link to comment Share on other sites More sharing options...