C# get closest prop
-
Help! Does anyone know how to get the closest prop? Not props or prop[]
-
@NotCrunchyTaco @rappo @Jitnaught @LeeC2202 @FoxtrotDelta
-
This native might help:
Object GET_CLOSEST_OBJECT_OF_TYPE(float x, float y, float z, float radius, Hash modelHash, BOOL isMission, BOOL p6, BOOL p7)
-
@Jitnaught I tried that with Prop propname = Native func what would I do then?
-
@Jitnaught it says cannot covert void to GTA.Prop or how would I carry the the method/variable over to another set of curly brackets?
-
@NotCrunchyTaco Prop closestProp = GTA.Native.Function.Call<Prop>(x, y, z, radius, model, ismission, p6, p7);
-
@Jitnaught I tried it doesn't work
-
@Jitnaught Any other ideas?
-
@NotCrunchyTaco Have you tried casting the returned object out as a Prop using that function? It might have to return an object, so you might be able to cast it to a Prop.
So
Prop _prop = (Prop)Function.Call<object>(Function.Call etc... );
-
Try with GetNearbyProps and get the prop that is at index 0 of the prop[] array, the first one added to the array might be the closest (idk for sure).
-
@LeeC2202 Yes I have tried that... Would there be a way to carry propName from one set of curly brackets to another?
-
@stillhere I've tried that before. When you do that it gets all of them and doesn't really let you do anything
-
@stillhere The scripts definitely use that above call. This is a line from one of the agency_heist scripts.
object::get_closest_object_of_type(150.59f, -762.38f, 258.3f, 1f, 878161517, 1, 0, 1);
-
@LeeC2202 Okay thanks I will try it. By making it from C++ to c#
-
@NotCrunchyTaco Easiest way to test is to write a small mod to spawn a specific object and then use that to test for it. I'm a bit busy right now, so I haven't got time to try it I'm afraid.
-
@LeeC2202 That's alright I will try it
-
@NotCrunchyTaco said in C# get closest prop:
@LeeC2202 Yes I have tried that... Would there be a way to carry propName from one set of curly brackets to another?
If I understand your question, you can make the prop name variable a global variable so that you can access it from anywhere within your script.
@LeeC2202 seems like that only works if you're looking for a specific object rather than all objects/props. Hm actually I seem to recall in SHVDN a function like World.GetClosest with an entity type input (sorry if I'm not making sense).
-
@LeeC2202 THANKS IT WORKED!!!!!!!!!!!!!!!!!!!!!
-
@NotCrunchyTaco Cool.
-
@NotCrunchyTaco What you were saying before about carrying the propName over, did you mean like this?
entity::freeze_entity_position(object::get_closest_object_of_type(-805.17f, 173.98f, 72.69f, 0.1f, joaat("prop_cigar_03"), 0, 0, 1), true);
You can see that the object returned from the get_closest_object is being directly used as a parameter in another function.
-
@LeeC2202 Now I can finish my soccer mod
-
@Jitnaught said in C# get closest prop:
@NotCrunchyTaco Prop closestProp = GTA.Native.Function.Call<Prop>(x, y, z, radius, model, ismission, p6, p7);
What are p6 and p7, please? I'm trying to remove a bush, like:
returnedProp = Function.Call<Prop>(Hash.GET_CLOSEST_OBJECT_OF_TYPE, -561.7426f, 4439.272f, 24.94009f, 0.1f, 1277635601, 0); // prop_bush_lrg_03 if (returnedProp != null && returnedProp.Handle != 0) returnedProp.Delete();
But it won't budge; and it seems I'm missing the last 2 parameters.
-
@meimeiriver
It's appears to be undocumented. However you can look at the decompiled scripts to see what parameters R* passes to the function.
Ex:iLocal_29 = get_closest_object_of_type(ENTITY::GET_ENTITY_COORDS(iLocal_28, 1), 15f, 874602658, 1, 0, 1);
p6 and p7 being 0 and 1 respectively.
Source.A radius of 0.1 might be too small, try 1.0f perhaps?
Also according to the native DB it seems there is an 8th parameter now.
-
@stillhere said in C# get closest prop:
@meimeiriver
It's appears to be undocumented. However you can look at the decompiled scripts to see what parameters R* passes to the function.
Ex:iLocal_29 = get_closest_object_of_type(ENTITY::GET_ENTITY_COORDS(iLocal_28, 1), 15f, 874602658, 1, 0, 1);
p6 and p7 being 0 and 1 respectively.
Source.A radius of 0.1 might be too small, try 1.0f perhaps?
Also according to the native DB it seems there is an 8th parameter now.
Thanks for the reply.
I already knew p5 is the 'mission' flag (aka: ignore when it's a mission-critical prop), but didn't know about p6 and p7.
I also already tried a radius of 1.0f, btw (I don't know exactly how that works, but I figured the pos of a bush might be dynamic, after a fashion, moving in the wind and all; but, alas, that wasn't it). I also tried a case-sensitive hash, as the object (in its pertinent ymap) is listed as Prop_Bush_Lrg_03. Sadly, that made no difference either.
I can try and experiment with the last 2 parameters too (if SHV has them even implemented).
N.B. I really want this method of removing a bush. I can 'easily' remove it from its ymap, of course; but cs1_14b_long_4.ymap (where it comes from) exists in several places, whose DLC's then all have to go inside the mods folder. And then you're not done yet, as you then painstakingly have to deal with all the LOD levels, lest you're stuck with the lodded shadow of the bush.
-
@stillhere Odd, I can't get this simple painting to go away either:
returnedProp = Function.Call<Prop>(Hash.GET_CLOSEST_OBJECT_OF_TYPE, -558.1558f, 4444.424f, 35.65982f, 0.1f, -1071622219, 0); // apa_p_h_acc_artwalll_03 if (returnedProp != null && returnedProp.Handle != 0) returnedProp.Delete();
I tried all variations of the last 3 flags; but, the handle of these objects (bush and painting) always appears to be '0'.