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.

Request for script fix - due to scripting changes - Please :)

Discussion in 'Programming Questions and Suggestions' started by Weyrman, Oct 16, 2016.

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

    Messages:
    8
    I have come back to the game after some time away and some of my scripts no longer work due to API changes.
    Could someone take a look at this for me please: It objects to IMyInventoryOwner

    const string INVENTORY_DISPLAY_NAME_PREFIX = "STORAGE: ";
    const string TEXT_PANEL = "TextPanel";

    public struct Ore
    {
    public string Name;
    public string Abrv;
    public long Amount;

    public Ore(string name, string abrv)
    {
    Name = name;
    Abrv = abrv;
    Amount = 0;
    }
    public Ore(string name, string abrv, long amount) : this (name, abrv)
    {
    Name = name;
    Abrv = abrv;
    Amount = amount;
    }
    }

    IMyTerminalBlock FindBlockWithPrefix(string prefix) {
    List<IMyTerminalBlock> Blocks = new List<IMyTerminalBlock>();
    GridTerminalSystem.GetBlocks(Blocks);

    for (int i = 0; i < Blocks.Count; i++)
    {
    IMyTerminalBlock potentialDisplay = Blocks;
    if (potentialDisplay.CustomName.StartsWith(prefix))
    return potentialDisplay;
    }
    return null;
    }

    IMyTextPanel text_panel = null;

    void Main()
    {
    text_panel = GridTerminalSystem.GetBlockWithName(TEXT_PANEL) as IMyTextPanel;

    display("", false);

    const string PRFIX = "Drills:";


    List<IMyTerminalBlock> drills = new List<IMyTerminalBlock>();
    List<IMyTerminalBlock> drillstatus = new List<IMyTerminalBlock>();
    List<IMyTerminalBlock> containers = new List<IMyTerminalBlock>();

    GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(containers);
    GridTerminalSystem.SearchBlocksOfName(PRFIX, drillstatus);
    GridTerminalSystem.GetBlocksOfType<IMyShipDrill>(drills);

    /* iterate through the list and total up the max volume and current volume */
    float totalCurrentVolume = 0;
    float totalMaxVolume = 0;
    for(int i = 0; i < containers.Count; i++) {
    IMyInventory inv = (containersas IMyInventoryOwner).GetInventory(0);
    totalCurrentVolume += (float)inv.CurrentVolume;
    totalMaxVolume += (float)inv.MaxVolume;
    }

    int percentage;
    if(totalMaxVolume == 0)
    percentage = 0;
    else
    percentage = (int)(totalCurrentVolume / totalMaxVolume * 100);

    List<Ore> Totals = new List<Ore> {
    new Ore("Cobalt", "Co"),
    new Ore("Gold", "Au"),
    new Ore("Iron", "Fe"),
    new Ore("Magnesium", "Mg"),
    new Ore("Nickel", "Ni"),
    new Ore("Platinum", "Pt"),
    new Ore("Silicon", "Si"),
    new Ore("Silver", "Ag"),
    new Ore("Uranium", "U"),
    new Ore("Stone", "St")
    };

    // Get the drill contents
    for (int d = 0; d < drills.Count; d++)
    {
    var drillInvOwner = (IMyInventoryOwner)drills[d];
    var drillInv = drillInvOwner.GetInventory(0);

    var drillItems = drillInv.GetItems();

    for (int i = 0; i < drillItems.Count; i++)
    {
    string name = drillItems.Content.SubtypeName;
    int index = Totals.FindIndex(delegate(Ore ore) { returnore.Name== name; });
    if (index < 0)
    {
    Totals.Add(new Ore(name, name, drillItems.Amount.RawValue));
    }
    else
    {
    Ore temp = Totals[index];
    Totals[index] = newOre(temp.Name,temp.Abrv, temp.Amount + drillItems.Amount.RawValue);
    }
    }
    }

    // Post the results
    for (int i = 0; i < drillstatus.Count; i++)
    {
    string result = "";

    for (int j = 0; j < Totals.Count; j++)
    {
    if (Totals[j].Amount > 0)
    {
    string ore = Totals[j].Abrv;
    float total = (float)Totals[j].Amount / 1000000000f;
    result += "\n\r" + ore + ": " + total.ToString("N2") + "k";
    }
    }

    if (result == "") result += " None";
    result = result + "\nCargo:" + percentage + "%";

    display(result);
    }
    }

    void display(string text, bool append = true)
    {
    if (text_panel == null) return; // No data display found.
    text += "\n";
    text_panel.WritePublicText(text, append);
    text_panel.ShowTextureOnScreen();
    text_panel.ShowPublicTextOnScreen();
    }
     
  2. Weyrman Trainee Engineer

    Messages:
    8
    The above script is 2 small scripts cobbled together for use on my mining ship that I found on steam some time back. So it does 2 things, it tells me what is currently in the drill (what I am mining) and how full my storage is as a percentage and displays it on a text panel.
    I have quite basic VB skills and can follow the script enough yo know what it is doing but no knowledge how to fix it. As I said, it is just API changes that are the issue.
    I have even followed directions here to load up VS Community and load the script to try and muddle it right but I just don't know the syntax.
    Can someone please take pity on me and fix it for me, I really miss it
     
Thread Status:
This last post in this thread was made more than 31 days old.