Log in to reply
 

[Question] [C#] How does the function GET_CLOSEST_OBJECT_OF_TYPE/World.GetNearbyProps exactly work?



  • Hi Fellow modders,

    I have been working on new mod, in which I am required to gather the prop information around player.
    So I tried to use below natives. However, I couldn't get it work.

    PFB is the snippet of my code, and let me know if I am doing something wrong anywhere?

    C#
    Native Style

    • Prop _TempProp = Function.Call<Prop>(Hash.GET_CLOSEST_OBJECT_OF_TYPE, PedPlayer.position.x, PedPlayer.position.y, PedPlayer.position.z, 5.0f, -94404248, 1, 0, 1); // -94404248 the model hash is used for tree_stump_01

    and by this

    • Prop[] _TempProp = World.GetNearbyProps(new Vector3(playerxposition, playeryposition, playerzposition), 10f);

                            foreach (var item in _TempProp)
                            {
                                if (item.Model.Hash == -94404248)
                                     {
                                       UI.Notify("Object Found");
                                       Blip Objectblip = World.CreateBlip(item.Position);
                                       Objectblip.Color = BlipColor.Yellow;
                                     }
                            }
      

    but nothing really comes up as the result.

    Lastly, my findings,

    1. I tried to spawn the specific object first(tree_stump in this case), and later tried to search the object with these natives, and strangely it works then. But not for the objects/props which are already there in map.

    2. I don't know for sure, but I think the objects/props it only able to find which are non static. The static ones, it just simply overlooks? If this is the case, then any workaround for this?

    Any help around this is really appreciated.

    @Experts( @stillhere @CamxxCore @aimless @ikt @Unknown-Modder @Cyron43 @Jitnaught @meimeiriver)
    You guys are more experienced than me, any way you could help me here?

    P.S. Before posting this, I tried the NativeDB page(it doesn't consist much of an information, but an update, that this native now has upto 8 parameters)


  • MODERATOR

    Well it seems like this object is a static one (as you mentioned). These don't have a script guid so scripts won't be able to access it. You'd need to do it by accessing the map data directly in memory.
    I don't do memory stuff in C# so I can't help you here.



  • @ashishcw Sorry mate, I can't tell you more than @Unknown-Modder. Static objects are inaccessible, hence the name. I have never dared to directly poke around in memory. I hope one of the C++ gurus can help you with that.



  • @Cyron43 said in [Question] [C#] How does the function GET_CLOSEST_OBJECT_OF_TYPE/World.GetNearbyProps exactly work?:

    @ashishcw Sorry mate, I can't tell you more than @Unknown-Modder. Static objects are inaccessible, hence the name. I have never dared to directly poke around in memory. I hope one of the C++ gurus can help you with that.

    I heard C++ is much better for memory manipulation anyway. But I'll stick with C#. :)

    But yeah, I've encounter plenty bushes and such that just won't budge, and are, to our scripts, as absent.

    P.S. I was just looking at the source for SPA again, and saw something like

    Public Sub ClearArea(X As Single, Y As Single, Z As Single)
        Dim arguments As InputArgument() = New InputArgument() {X, Y, Z, 100, True, False, False, False}
        Native.Function.Call(Hash.CLEAR_AREA, arguments)
        Dim arguments2 As InputArgument() = New InputArgument() {X, Y, Z, 100, True, True, True, True, True}
    End Sub
    

    Not sure if Hash.CLEAR_AREA would work off of PedPlayer.position too.

    EDIT: Area likely won't be cleared, including the non-guid objects, but it's at least worth a try to see whether, internally, the game clears more than we can do with individual objects.



  • @meimeiriver BTW you need to surround any C# code which deals with direct memory access (except calls into the shvdn Memorypool) with the unsafe keyword and also allow unsafe code in the project properties. Just saying in case you don't know.
    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/unsafe

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/unsafe-code-pointers/



  • @Cyron43 said in [Question] [C#] How does the function GET_CLOSEST_OBJECT_OF_TYPE/World.GetNearbyProps exactly work?:

    @meimeiriver BTW you need to surround any C# code which deals with direct memory access (except calls into the shvdn Memorypool) with the unsafe keyword and also allow unsafe code in the project properties. Just saying in case you don't know.
    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/unsafe

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/unsafe-code-pointers/

    Good stuff! :) Thanks!



  • @Unknown-Modder Alright, thanks for the heads up, as I knew it was static, but just wasn't sure about it. As they say, it's always good to have an expert opinion. :)

    @Cyron43 Thank you for your input mate. And thanks for those links, I learn each day something new.

    @meimeiriver Thanks for your input. I hope, I will find a working sample soon.



  • @ashishcw Luckily I have done a bit of research in this area, so I can offer some guidance. The static map objects are stored and referred to as "CBuildings" internally, which are dynamically loaded with the map when you move around the world. Using some less- than- beautiful code, we can grab a handle to those objects and move them around or delete them even. The trouble is, they will reappear in the same place after that location in the map is rendered again, so it is not a totally conventional solution if the goal is to remove or hide said objects. You would be better off to hook some functions responsible for spawning the objects to filter them out manually or just change the map data files using OpenIV. Anyway, here is the actual function in my MapInfoTool where I grab the information about surrounding 'CBuildings' from the internal array: https://github.com/CamxxCore/MapInfoTool/blob/master/MapInfoTool/src/Memory/MemoryAccess.cs#L271 Happy to explain or help further if you plan to implement this code somewhere.



  • @CamxxCore said in [Question] [C#] How does the function GET_CLOSEST_OBJECT_OF_TYPE/World.GetNearbyProps exactly work?:

    The trouble is, they will reappear in the same place after that location in the map is rendered again, so it is not a totally conventional solution if the goal is to remove or hide said objects

    That happens with GET_CLOSEST_OBJECT_OF_TYPE too: objects tend to reappear when you leave the area and come back. That's by design, of course, so you need to re-assert the removal periodically (either at OnTick, or when you've determined you're within sufficient proximity of the object).

    Removing them from their respective ymaps is possible, of course, and I usually resort to that (for places where I really need to remove a bush or something which would otherwise stick thru my home). Problem with bushes of that kind, though, is that often you'll wind up with the bush gone, but a fugly LOD having taken its place (the latter of which was part of a larger LOD set). Then you need to remove that too.

    Thanks for the code! I'll try and study it.



  • @CamxxCore First of all, I am sorry for the delayed in response, about the static object finding in the memory pool, That's amazing finding, you simply are best...!!! :D I guess, I get to learn new thing every day. Thank you for your help here and that link to the source-code of yours. I will certainly look into it.

    About implementation, yes I am planning to implement it, but Not in a way to remove objects or making them disappear. I actually was working on an idea. So should I PM you? Probably that would be better for me to explain a thing or two to explain, as where and how am I planning to implement this.! Thanks in advance.!

    @administrators You can close this question. Thank you.!



  • Please, I need help. My goal is to remove objects from a specific point on the map. I managed with Codewalker, but for some objects, it remains the LOD. How do I remove this too?


Log in to reply
 

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