Jump to content

How do i add particle effect in plugin?


Recommended Posts

I've been working on fuel jettison nozzle mod. For now, I've done fuel subtracting plugin but now, I can't find way to add effect.

Sound seems to be easy to add with fxgroup. but how do i add smoke and fire?

My part is not a engine so moduleenginefx seems not appropriate and using KSPADDON seems too complicated.

I just wanna know how to add default effects. What I'm gonna make is a fuel jettison nozzle with long smoke trail, and fire trail when heated.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyKSPProject
{
    public class HelloKerbinMod : PartModule
    {
        FXGroup fx = new FXGroup("smoke");
        
        [KSPField(guiActive = true, guiActiveEditor = true, guiName = "Status", isPersistant = true)]
        string status;

        [KSPField(guiActive = true, guiActiveEditor = false, guiFormat = "F1", guiName = "Fuel Amount", guiUnits = "L", isPersistant = true)]
        double fuel;

        [KSPField(guiActive = true, guiActiveEditor = true, guiFormat = "F1", guiName = "Nozzle Size", guiUnits = "cm^2", isPersistant = true)]
        public float nozzleSize;

        [KSPField(guiActive = true, guiActiveEditor = false, guiFormat = "F0", guiName = "Tanks found", isPersistant = true)]
        public int tanks;

        [KSPEvent(active = true, externalToEVAOnly = false, guiActive = true, guiActiveEditor = false, guiActiveUncommand = false, guiActiveUnfocused = false, name = "toggleNozzle", guiName = "Toggle Nozzle")]
        public void toggleNozzle()
        {
            part.enabled = !part.enabled;
            if (fuel == 0)
            {
                status = "TANK EMPTY";
            }
            else
            {
                status = part.enabled ? "Opend" : "Closed";
            }
        }

        public void consumeFuel()
        {
            foreach (Part p in vessel.parts)
            {
                foreach (PartResource r in p.Resources)
                {
                    if (r.resourceName == "LiquidFuel" && r.amount > 0)
                    {
                        r.amount -= nozzleSize / tanks;
                        fx.setActive(true);
                    }

                    if (r.amount < 0)
                    {
                        r.amount = 0;
                    }
                }
            }
        }




        public override void OnLoad(ConfigNode node)
        {
            nozzleSize = float.Parse(node.GetValue("nozzleSize"));

            if (fuel == 0)
            {
                status = "TANK EMPTY";
            }
            else
            {
                status = part.enabled ? "Opend" : "Closed";
            }

            fx.name = "fx_smokeTrail_medium";

            part.enabled = false;
            part.deactivate();
            base.OnLoad(node);
        }

        public override void OnUpdate()
        {
            consumeFuel();
            if (!status.Contains("TEMP") && part.temperature >= 1000)
            {
                status += " TEMP WARNING!!";
            }
            base.OnUpdate();
        }

        public void Update()
        {
            EstimateFuel();
        }

        public void EstimateFuel()
        {
            double tmpfuel = 0;
            int tmptanks = 0;
            foreach (Part p in vessel.parts)
            {
                foreach (PartResource r in p.Resources)
                {
                    if (r.resourceName == "LiquidFuel")
                    {
                        tmpfuel += r.amount;
                        tmptanks++;
                    }
                }
            }
            fuel = tmpfuel;
            tanks = tmptanks;

            if (fuel <= 0)
            {
                part.enabled = false;
            }
        }
    }

}

here's the code. and let me ask one more thing.. why status is not refreshed at first time in flight scene? status field is blank when its started and starts to display something after when i activate KSPEVENT.

 

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