Jump to content

Getting Crew Variable and Adding Resources: Please help!


Recommended Posts

I'm developing a plugin now...

It's going well, actually, except crew detection... ugh.

I want to make the part generate "Methane" as a Resource (:sticktongue:) and put it in a small, internal container type thingy in the part before it goes to a bigger one, which I'm pretty sure the default resource system allows for.

I just can't figure out how to detect crew, looking at source codes with crew detection didn't work. Oh, well...

Any help, anyone? Anyone? :)

And what about resource generation? I know, I know: ModuleGenerator in the stock game... but how do I make it generate ONLY when there's a Kerbal in the seat?

Could I do a Required Resource type thing in the crew seat's crew module, and then make a negative value? :)

Thanks in advance! :D

FYI: Yes, this will be a toilet seat. For the lolz, guys. And for those Sandboxers who love experimenting with mods as their endgame (kinda like me, you're not alone! :D)

Thanks. :)

-Naten

Edited by Naten
Link to comment
Share on other sites

I am working on something where I have to identify which Kerbals IVA is active and I'm having a hard time figuring that out. I can't find a reference to which Kerbal the camera is attached to.

PartReference.ProtoModuleCrew gives you a list of ProtoCrewMembers in that particular part reference. That might help you.

Link to comment
Share on other sites

I am working on something where I have to identify which Kerbals IVA is active and I'm having a hard time figuring that out. I can't find a reference to which Kerbal the camera is attached to.

PartReference.ProtoModuleCrew gives you a list of ProtoCrewMembers in that particular part reference. That might help you.

Can I convert this into a Boolean? And is this a list<> thingy? I dunno hau. :P

Here's something, could this work? Thanks! :)


namespace NatenMethaneFuels:Extensions
{
...public class NatenKerbalFart : PartModule
...{
......private void OnUpdate()
......{
.........if (list<PartReference.ProtoModuleCrew> !=0)
.........{
............this.part.RequestResource("MethaneWaste", -1);
.........}
......}
...}
}

Link to comment
Share on other sites

I don't know if it returns null when there is no crew or not but I assume this might work:


Part yourPartReference = yourPart;

if ([I]yourPartReference[/I].ProtoModuleCrew.count > 0)

And this would cover you if in case it returns null with no crew


if ([I]yourPartReference[/I].ProtoModuleCrew != null && [I]yourPartReference[/I].ProtoModuleCrew.count > 0 )

You don't need the List<> stuff in there unless your creating new list. You're just getting a reference to one.

Obviously, 'yourPartReference' will need to be a reference to your part attached to the ActiveVessel. Something similar to this can get you that


Part yourPartReference;
foreach (Part part in FlightGlobals.ActiveVessel.parts)
{
if (part.name.Contains("yourPartName"))
{
yourPartReference = part
}
}

None of the above is tested, so it may need some tweaking to work.

Link to comment
Share on other sites

I'm really sorry I had to ask this, but what is a part reference?

Is it the part config file's "part = THIS" value, or do I need to add it with the below thing... oh. I'm starting t oget it.

Is "yourPartName" defined by the part.cfg? :D

Thanks. :)

-Naten

Link to comment
Share on other sites

A part reference is a variable of type Part that contains an instance of the part object in game. Read up on some object-oriented programming to really understand what an object and instance is. But you'll need to find the instance of your part attached to your vessel object to do anything useful. The Part object is created using values from the cfg, like the part name, the modules it has, what model it uses. So, yes, 'yourPartName' is set by the name you set in the cfg.

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...