Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Reactor Status Script

Discussion in 'Programming Questions and Suggestions' started by Audiacious, Apr 26, 2018.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Audiacious Trainee Engineer

    Messages:
    47
    I have made a nice engineering section with 4 compartments with 2 reactors each. What I am looking for is a script that can take light groups for each reactor group and basically match the status light on the reactors. Does anyone know of a script that can do this, I have been unable to find one unfortunately.
     
  2. Ekuah Trainee Engineer

    Messages:
    99
    I could script something for you.
    Okay it would be crude, and real programmers would cringe, but I can try.
     
  3. Burstar Apprentice Engineer

    Messages:
    463
    I'm unclear as to what you need? If you want lights to come on when you turn on reactors you could bind lights and reactors to a turn on timerblock.

    If you need indicators for if the reactor is inoperable due to either damage or a lack of fuel, I don't know of a script that uses lights to do this, but AutoLCDs 2 script can show reactor status on an LCD in several ways:

    Damage level of the block
    Power output of the block
    The terminal windows text
    The cargo level of the block
    The actual inventory in the block
    and more.

    It won't trigger lights though.
     
  4. Regn Trainee Engineer

    Messages:
    74
    Something like this, maybe?
    Haven't tested it.

    Ps. I can't remember what the lights looked like compared to what status. Haven't launched the game in a while.

    Put e.g. "ReactorGroup1" in the CustomData option of Reactor 1, then put the same text in the CustomData option of the interior lights you want to swap color on. The text should be passed on from the reactors to match the lights.

    Code:
    enum ReactorStatus
    {
    	TurnedOff,
    	NeedRepair,
    	OutputsPower,
    	Idle
    };
    
    Color green = new Color(0, 255, 0);
    Color yellow = new Color(255, 255, 0);
    Color red = new Color(255, 0, 0);
    Color blue = new Color(0, 0, 255);
    
    void Reactors()
    {
    
    	var reactors = new List<IMyReactor>();
    	GridTerminalSystem.GetBlocksOfType(reactors);
    
    	var status = ReactorStatus.Idle;
    
    	if (reactors.Count > 0)
    	{
    		foreach (var reactor in reactors)
    		{
    
    			if (!reactor.Enabled)
    			{
    				status = ReactorStatus.TurnedOff;
    			}
    
    			if (!reactor.IsFunctional)
    			{
    				status = ReactorStatus.NeedRepair;
    			}
    
    			if (reactor.IsWorking)
    			{
    				if (reactor.CurrentOutput > 0f)
    				{
    					status = ReactorStatus.OutputsPower;
    				} else
    				{
    					status = ReactorStatus.Idle;
    				}
    			}
    			
    			ReactorLights(reactor.CustomData, status);
    
    		}
    	}
    
    }
    
    void ReactorLights(string customData, ReactorStatus reactorStatus)
    {
    
    	var interiorLights = new List<IMyInteriorLight>();
    	GridTerminalSystem.GetBlocksOfType(interiorLights);
    
    	if (interiorLights.Count > 0)
    	{
    		foreach (var interiorLight in interiorLights)
    		{
    			
    			// Skip light.
    			if (interiorLight.CustomData != customData)
    			{
    				continue;
    			}
    
    			// Is turned off, swap to green.
    			if (reactorStatus == ReactorStatus.TurnedOff)
    			{
    				SwapColor(interiorLight, blue);
    			}
    
    			// Needs repair, swap to red.
    			if (reactorStatus == ReactorStatus.NeedRepair)
    			{
    				SwapColor(interiorLight, red);
    			}
    
    			// Is outputting power, swap to green.
    			if (reactorStatus == ReactorStatus.OutputsPower)
    			{
    				SwapColor(interiorLight, green);
    			}
    
    			// Is idling, swap to yellow.
    			if (reactorStatus == ReactorStatus.Idle)
    			{
    				SwapColor(interiorLight, yellow);
    			}
    
    		}
    	}
    
    }
    
    void SwapColor(IMyInteriorLight light, Color color)
    {
    	if (light.Color != color)
    	{
    		light.Color = color;
    	}
    }
    
    public void Main(string argument, UpdateType updateSource)
    {
    
    	Reactors();
    	
    }
     
Thread Status:
This last post in this thread was made more than 31 days old.