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.

Uber Noob C# for Space Engineers

Discussion in 'Programming Questions and Suggestions' started by MCM, Jul 17, 2016.

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

    Messages:
    65
    Hi Guys just learning C# for SE . Is there a tutorial for how the folder structures are ..As what lines must be called before
    and what you can put after... Plz
    ???
     
    Last edited: Jul 18, 2016
  2. MCM Trainee Engineer

    Messages:
    65
    Um is it possible to give a physical item the attributes of other block/Resorce and to give it a trigger and upon that trigger make it disappear
     
  3. Wicorel Senior Engineer

    Messages:
    1,242
    Short answer: No.

    Longer:

    What to do you mean physical item? Scripts only have access to the blocks that show in the terminal UI.

    What to you mean attributes? You cannot give new attributes to any terminal block from scripts. You can get the attributes from one block and set another block's attributes to be the same (On/Off, etc).

    Scripts have no access to the actions (triggers) in blocks.

    Scripts cannot delete blocks, so they cannot make it dissappear.
     
    • Like Like x 1
  4. Malware Master Engineer

    Messages:
    9,552
    @Wicorel given the context of the original post, talk of folder structures etc, I must assume op is asking about mod scripts. Which is why I haven't been responding myself :)

    @MCM there are three kinds of scripts available for SE:
    • Ingame scripts - behind the fourth wall, can only access things the Engineer can
    • Mod scripts - breaks the fourth wall, is allowed a lot more
    • Plugin scripts - super advanced, total freedom, cannot be distributed via the Workshop

    It's helpful if you'd be a bit more specific in your queries :)
     
    • Like Like x 1
  5. Harrekin Master Engineer

    Messages:
    3,077
    Option one: I like living in space

    Option two: Is my life part of a game?

    Option three: I am God!
     
    • Like Like x 1
    • Funny Funny x 1
  6. MCM Trainee Engineer

    Messages:
    65
    Hey Guys been away from pc for a few days ...Thanks for Your Replies.. Yep Mod Script if not Plugin Script....So i have made a model as a physical item...Its in game but dose nothing but stack..With a mod script could i make that give energy to suit when EnergyLowThreshold pops up on screen and to make that item be Consumed..

    Code:
    <?xml version="1.0"?>
    <Definitions
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <PhysicalItems>
            <PhysicalItem xsi:type="MyEntityStatComponentDefinition">
                <Id>
                    <TypeId>ConsumableItem</TypeId>
                    <SubtypeId>MCM_Extra_Battery</SubtypeId>
                </Id>
                <DisplayName>MCM_Extra_Battery</DisplayName>
                <Icon>Textures\Icons\MCM_Extra_Battery.dds</Icon>
                <Size>
                    <X>0.8</X>
                    <Y>0.24</Y>
                    <Z>0.08</Z>
                </Size>
                <Mass>20</Mass>
                <Output>20.5V</Output>
                <EnergyLevel>100</EnergyLevel>
                <Model>Models\MCM_Extra_Battery_Small.mwm</Model>
                <PhysicalMaterial>Metal</PhysicalMaterial>
                <SuitBatteryStorage>
                    <Resource>
                        <Id>
                            <TypeId>Electricity</TypeId>
                            <SubtypeId>SuitRechargeDistributor</SubtypeId>
                        </Id>
                    </Resource>
                </SuitBatteryStorage>
                <Capacity>100</Capacity>
                <ResourceSourceGroup>Battery</ResourceSourceGroup>
                <MaxPowerOutput>100</MaxPowerOutput>
                <ResourceSinkGroup>BatteryBlock</ResourceSinkGroup>
            </PhysicalItem>
        </PhysicalItems>
    </Definitions>
    
    --- Automerge ---
    I tried to make a script. Trying to learn C# for SE but its kinda brain melting as most tuts use console and default naming and then trying to find out what can be call and in what order they can be called from SE..Or am i just confusing myself... I made this mess of a script in VS with the reference library..>>> O and lines from source code files (^_^) i got it to where it gives no errors on load into SE world or F11 ...LOL but does nothing

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using System.IO;
    using Sandbox.Common;
    using Sandbox.Common.ObjectBuilders;
    using Sandbox.Definitions;
    using Sandbox.Engine;
    using Sandbox.Engine.Physics;
    using Sandbox.Engine.Multiplayer;
    using Sandbox.ModAPI;
    using Sandbox.ModAPI.Interfaces;
    using Sandbox.Game;
    using Sandbox.Game.Entities;
    using Sandbox.Game.Gui;
    using VRage.Common.Utils;
    using VRage.Game.Entity;
    using VRageMath;
    using VRage;
    using VRage.ObjectBuilders;
    using VRage.Game.Components;
    using VRage.ModAPI;
    using VRage.Utils;
    using VRage.Game;
    using Sandbox.Game.GameSystems.Electricity;
    using Sandbox.Game.Entities.Character;
    using Sandbox.Game.EntityComponents;
    using ProtoBuf;
    using Sandbox.Game.Components;
    using System.ComponentModel;
    using VRage.Game.ModAPI.Interfaces;
    using Sandbox.ModAPI.Ingame;
    using VRage.Game.ModAPI;
    using System.Diagnostics;
    using System.Threading;
    
    namespace EnergyContainerObject
    {
        [MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation)]
        [MyEntityComponentDescriptor(typeof(MyObjectBuilder_PhysicalObject))]
        public class MCM_Extra_Battery : MyEntity
        {
    
            public static float curEnergy = 1.0f;
            public static float MaxCapacity = 1.0f;
            public static float decEnergy = 0.20f;
            public static float FillLevel = 0.30f;
    
            void Start()
            {
                curEnergy = 0.90f;
            }
    
            void Update()
            {
                if (curEnergy < MaxCapacity)
                {
                    curEnergy += FillLevel * productionUpdateInterval;
                    Debug.Write(curEnergy);
                }
            }
    
            public void OnTrigger(MyResourceDistributorComponent other)
            {
                if (ResourceSource.HasCapacityRemainingByType(MyResourceDistributorComponent.ElectricityId) || ResourceSink.RequiredInputByType(MyResourceDistributorComponent.ElectricityId) > 0.25f)
                {
                    curEnergy -= decEnergy * productionUpdateInterval;
                    Debug.Write(curEnergy);
                }
            }
    
            public MyCharacter m_owner { get; private set; }
            public MyResourceSinkComponent ResourceSink { get; private set; }
            public MyResourceSourceComponent ResourceSource { get; private set; }
            public float m_productionUpdateInterval { get; private set; }
    
            MCM_Extra_Battery energycontainerobject;
    
            private int m_lastUpdateTime;
    
            private MyEntity m_lastParent = null;
    
            public const float EnergyCriticalThreshold = 0.10f;
            public const float EnergyLowThreshold = 0.25f;
            private const int productionUpdateInterval = 100;
    
            public bool IsEnergyCritical { get { return (ResourceSource.RemainingCapacity / MyEnergyConstants.BATTERY_MAX_CAPACITY) < EnergyCriticalThreshold; } }
            public bool IsEnergyLow { get { return (ResourceSource.RemainingCapacity / MyEnergyConstants.BATTERY_MAX_CAPACITY) < EnergyLowThreshold; } }
    
            internal void RecalculatePowerRequirement(bool chargeImmediatelly = true)
            {
                ResourceSink.Update();
                RecalculatePowerRequirement(chargeImmediatelly);
                if (MyEnergyConstants.REQUIRED_INPUT_LIFE_SUPPORT != 0.25f && MyEnergyConstants.BATTERY_MAX_CAPACITY != 0.25f) ProfilerShort.Begin("SuitRecharge");
                SuitRechargeDistributor.ToString();
    
                var defaultSourceInfo = new MyResourceSourceInfo
                {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId,
                    DefinedOutput = MyEnergyConstants.BATTERY_MAX_POWER_OUTPUT, // TODO: Load max output from definitions
                    ProductionToCapacityMultiplier = 60 * 60
                };
            }
    
            public override void UpdateBeforeSimulation10()
            {
                base.UpdateBeforeSimulation10();
                if (this == MCM_Extra_Battery.SuitBattery || MyEnergyConstants.BATTERY_MAX_CAPACITY != 0.25f) { string.Format("Subtype: {0}, FillLevel: {1}, CurrentCapacity: {2}, MaxCapacity: {3}", m_characterDefinition, FillLevel, FillLevel * MaxCapacity, MaxCapacity); }
                {
                    ProfilerShort.Begin("SuitRecharge");
                    SuitRechargeDistributor.ToString();
                }
                ProfilerShort.End();
            }
    
    
            public object ProductionToCapacity
            {
                get
                {
                    return ProductionToCapacity;
                }
    
                set
                {
                    ProductionToCapacity = value;
                }
            }
    
            public float ConsumptionPerSecond
            {
                get
                {
                    return ConsumptionPerSecond;
                }
    
                set
                {
                    ConsumptionPerSecond = value;
                }
            }
    
            public float RechargePerSecond
            {
                get
                {
                    return RechargePerSecond;
                }
    
                set
                {
                    float chargeImmediatelly = 1;
                    RechargePerSecond = chargeImmediatelly;
                }
            }
    
            public float RechargedEnergy
            {
                get
                {
                    return RechargedEnergy;
                }
    
                set
                {
                    RechargedEnergy = MyEnergyConstants.BATTERY_MAX_CAPACITY;
                }
            }
    
            public float EnergyTransfer
            {
                get
                {
                    return EnergyTransfer;
                }
    
                set
                {
                    EnergyTransfer = MyResourceDistributorComponent.SinkGroupPrioritiesTotal;
                }
            }
    
            public float NewCapacity
            {
                get
                {
                    return NewCapacity;
                }
    
                set
                {
                    NewCapacity = 1.0f;
                }
            }
    
            public object SuitRechargeDistributor { get; private set; }
            public object m_characterDefinition { get; private set; }
    
            private readonly MyStringHash m_resourceSinkGroup = MyStringHash.GetOrCompute("Charging");
            private readonly MyStringHash m_resourceSourceGroup = MyStringHash.GetOrCompute("Battery");
    
            private static object SuitBattery;
            private float isBatteryEnergyLow;
    
            public MCM_Extra_Battery(MyCharacter m_owner, MyResourceSinkComponent resourceSink, MyResourceSourceComponent resourceSource, float m_productionUpdateInterval)
            {
                this.m_owner = m_owner;
                ResourceSink = resourceSink;
                ResourceSource = resourceSource;
                this.m_productionUpdateInterval = m_productionUpdateInterval;
    
                var MCM_Extra_Battery = new MyResourceSourceInfo
                {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId,
                    DefinedOutput = MyEnergyConstants.BATTERY_MAX_POWER_OUTPUT, // TODO: Load max output from definitions
                    ProductionToCapacityMultiplier = 60 * 60
                };
            }
    
        }
    
    }
    
     
    Last edited: Jul 24, 2016
Thread Status:
This last post in this thread was made more than 31 days old.