Jump to content

Best way to determine if a vessel is a kerbal


Recommended Posts

Given a Vessel ( which may or may not be the active vessel), what is the best way to determine if it is a Kerbal or not?  This needs to be checked in the GameEvents.onVesselModified, it seems that when a Kerbal goes EVA, the vessel is modified, but I haven't  yet been able to properly identify if it's a kerbal

I've come up with the following which seems to work, is there a better way (ie: faster):

void testVessel(Vessel v)
{
	if (v.rootPart.Modules.Contains("Kerbal"))
                return;
      
    // do something here if NOT a kerbal
      
}

Also, this doesn't seem to work either:

if (v.isEVA && v.GetComponent<KerbalEVA>() != null)
                return;

 

I can't just compare the vessel name to the name of the crew, since it is conceivable that someone might name a ship the same as the kerbal inside.

Edited by linuxgurugamer
Link to comment
Share on other sites

The module name is KerbalEVA so I don't see how it would work with v.rootPart.Modules.Contains("Kerbal")

and the fastest would be v.rootPart.Modules.Contains<KerbalEVA>() 

Link to comment
Share on other sites

7 minutes ago, sarbian said:

The module name is KerbalEVA so I don't see how it would work with v.rootPart.Modules.Contains("Kerbal")

and the fastest would be v.rootPart.Modules.Contains<KerbalEVA>() 

Thanks, I did find that was working.

Related question, I'm getting an "onVesselWasModified" event for the parent vessel  when a kerbal goes EVA.  Is there an easy way to determine if this event was generated because of an EVA?

Link to comment
Share on other sites

Make sure to test with other scenario than EVA with a hatch (like ejected from a command seat ? Forgot how that one works) so be sure your code is not dependent on event created by UI code.. 

Link to comment
Share on other sites

On 7/25/2017 at 9:42 AM, sarbian said:

Make sure to test with other scenario than EVA with a hatch (like ejected from a command seat ? Forgot how that one works) so be sure your code is not dependent on event created by UI code.. 

It was different, as was crew transferred, but I have them both working now.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

×
×
  • Create New...