Hello. Working on a plugin, and running into an issue trying to get the MapMarkerCH47 for a CH47Helicopter (or vice versa). The frustrating part is that at one point I did get the related objects, but I mistakenly deleted the code that would have allowed me to find this association. I don't know if I had the entire object but I at least found the reference. I know this because I saw both the CH47Helicopter and some AI component in my debug printing.
The reason I want to do this is because I can check the prefab on the CH47Helicopter and determine if I can remove the marker for it if it's player spawned (Code:void DumpToConsole(object obj) { Puts(JsonConvert.SerializeObject(obj)); } void OnEntitySpawned(BaseNetworkable entity) { // Puts(entity.GetType().Name); if (entity is CH47Helicopter) { // DumpToConsole(entity.GetType().GetMethods()); var links = (entity as CH47Helicopter).GetEntityLinks(true); Puts("*"); DumpToConsole(links); Puts("**"); } }
assets/prefabs/npc/ch47/ch47.entity.prefab)
Thanks in advance!
Getting the MapMarkerCH47 for a CH47Helicopter?
Discussion in 'Rust Development' started by MrPoundsign, May 10, 2018.
-
I'm still learns how to do this all so I'm just gonna throw out ideas and i have no idea if any of them are possible and i cant look into the assemble im not at my computer atm.
1. Track children when you spawn the CH47 and any child data
2.Use wild cards of map markers -
Thanks for the response, I appreciate it.
-
The CH47Helicopter class has a CreateMapMarker function. This function sets the mapMarkerInstance field. Even though this field is private, you can still access it with a bit of reflection. (Note: rust has been exposing variables over the last few patches, the code below will work if this field is swapped to public, however, it should be changed for optimization)
Code:CH47Helicopter heli = (CH47Helicopter)entity; MapMarkerCH47 mapMarker = (MapMarkerCH47)heli.GetType().GetField("mapMarkerInstance", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(heli);
In this, GetField is using BindingFlags Public and NonPublic, this prevents the code from erroring in the event that rust changes the field to public.
As a side note, I did not check if the field actually contains a MapMarkerCh47 object. It is a BaseEntity by default, however, it should cast just find.
As another note, You can also set the value of private variables with code like this
Code:light.GetType().GetField("secondsRemaining", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(light, 100000f);
-
-
To find the class name for the Helicopter, I created a plugin that ran the following.
Code:BaseEntity entity = player.GetCursorObject(); player.ChatMessage(entity.GetType().Name);
Code:public static class PlayerExtensibles { public static BaseEntity GetCursorObject(this BasePlayer player) { RaycastHit RayHit; bool flag1 = Physics.Raycast(player.eyes.HeadRay(), out RayHit, 5f); BaseEntity TargetEntity = flag1 ? RayHit.GetEntity() : null; return TargetEntity; } }