Jump to content

Kill a crew member + detect number of crew


Recommended Posts

That would be the easy way out. I'm trying to learn how to code C# in KSP, and i'm asking for help on the things I'm completely stuck on.

but I figured it out.


using UnityEngine;

namespace BASIK_Life_Support
{
public class LifeSupport : PartModule
{

public PartResource oxygen = null;


public void Update(ProtoCrewMember member)
{

PartResourceList prl = part.Resources;

foreach (PartResource wanted_resource in prl)
{
if (wanted_resource.resourceName == "Oxygen")
{
oxygen = wanted_resource;
}
}

if ( oxygen.amount <= 0)
{
part.RemoveCrewmember(member);
member.seat = null;
member.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
}

else
{
oxygen.amount -= (0.2 * part.protoModuleCrew.Count);
}
}
}
}

I hope it works

Edited by kineticPull
Link to comment
Share on other sites

That would be the easy way out. I'm trying to learn how to code C# in KSP, and i'm asking for help on the things I'm completely stuck on.

but I figured it out.


using UnityEngine;

namespace BASIK_Life_Support
{
public class LifeSupport : PartModule
{

public PartResource oxygen = null;


public void Update(ProtoCrewMember member)
{

PartResourceList prl = part.Resources;

foreach (PartResource wanted_resource in prl)
{
if (wanted_resource.resourceName == "Oxygen")
{
oxygen = wanted_resource;
}
}

if ( oxygen.amount <= 0)
{
part.RemoveCrewmember(member);
member.seat = null;
member.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
}

else
{
oxygen.amount -= (0.2 * part.protoModuleCrew.Count);
}
}
}
}

I hope it works

Asking for help is more of the easy way out than figuring it out from someone's code.

But two things about that: first off you are manually removing resources, do /not/ do that. Use part.RequestResource() to remove resources. Second, you are removing 0.2 units every /frame/. Multiply the amount by second with TimeWarp.fixedDeltaTime to have it behave correctly.

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