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.

Drones [Solved]

Discussion in 'Programming (In-game)' started by Justbeast11, Aug 5, 2017.

  1. Justbeast11

    Joined:
    Jul 4, 2017
    Messages:
    23
    Trophy Points:
    1
    Hey all, I've recently started modding space engineers, but I haven't really gotten into the in-game scripting yet. I've read this tutorial and have gotten everything right until it comes to the drone coming at the player. https://steamcommunity.com/sharedfiles/filedetails/?id=519946091 I use the script below in the programmable block (I actually got this script out of a programmable block on one of the default pirate ships). Anyway, I put the script in the programmable block, use the remote control block and set the programmable block to run with default argument just like the default pirate ships. After I set the whole ship to space pirates nothing happens. Any advice? Note: When I compile the script it does tell me
    if (weapon.HasInventory() && !weapon.GetInventory(0).IsItemAt(0)) continue; is outdated to use 'hasInventory property' instead. But I have no idea how to do that haha. Any help would be greatly appreciated!

    List<IMyTerminalBlock> list = new List<IMyTerminalBlock>();
    void Main(string argument)
    {
    Vector3D origin = new Vector3D(0, 0, 0);
    if (this.Storage == null || this.Storage == "")
    {
    origin = Me.GetPosition();
    this.Storage = origin.ToString();
    }
    else
    {
    Vector3D.TryParse(this.Storage, out origin);
    }
    GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(list);
    if (list.Count > 0)
    {
    var remote = list[0] as IMyRemoteControl;
    remote.ClearWaypoints();
    Vector3D player = new Vector3D(0, 0, 0);
    bool success = remote.GetNearestPlayer(out player);
    if (success)
    {
    bool gotoOrigin = false;
    GridTerminalSystem.GetBlocksOfType<IMyUserControllableGun>(list);
    if (list.Count == 0)
    {
    gotoOrigin = true;
    }
    else
    {
    bool hasUsableGun = false;
    for (int i = 0; i < list.Count; ++i)
    {
    var weapon = list;
    if (!weapon.IsFunctional) continue;
    if (weapon.HasInventory() && !weapon.GetInventory(0).IsItemAt(0)) continue;
    hasUsableGun = true;
    }
    if (!hasUsableGun)
    {
    gotoOrigin = true;
    }
    }
    if (Vector3D.DistanceSquared(player, origin) > 20000 * 20000)
    {
    gotoOrigin = true;
    }
    if (gotoOrigin)
    {
    remote.AddWaypoint(origin, "Origin");
    }
    else
    {
    remote.AddWaypoint(player, "Player");
    }
    remote.SetAutoPilotEnabled(true);
    }
    }
    }
     
  2. Wicorel

    Joined:
    Jan 10, 2015
    Messages:
    1,089
    Trophy Points:
    157
    GetNearestPlayer only works for ships owned by the Pirate faction, so it will not likely do what you want.

    For the posted problem, it is should be explained here in other posts. But you could also just get the current (fixed) script from a Pirate ship.
     
  3. Georgik

    Joined:
    Sep 30, 2015
    Messages:
    134
    Trophy Points:
    47
    He said
    So Pirate faction is not problem (maybe)
     
  4. Takeshi

    Joined:
    Oct 23, 2015
    Messages:
    154
    Trophy Points:
    47
    on a server or single Player?
    On Server this isnt possible because there is a recompile neccessary, so it wont work.
     
  5. Justbeast11

    Joined:
    Jul 4, 2017
    Messages:
    23
    Trophy Points:
    1
    It's in single player
     
  6. Wicorel

    Joined:
    Jan 10, 2015
    Messages:
    1,089
    Trophy Points:
    157
    Change the script to Echo out information like the coordinates to an LCD so you can see what the code is trying to do.
     
  7. Justbeast11

    Joined:
    Jul 4, 2017
    Messages:
    23
    Trophy Points:
    1
    I figured it out! I had to delete the owner information in the ships prefab for the programmable, timer, and remote control blocks.
     
  8. Ronin1973

    Joined:
    Feb 17, 2015
    Messages:
    3,986
    Trophy Points:
    207
    When programmable blocks change ownership, you may have to recompile the script.

    When working with Space Pirate factions you will want to go into Space Master mode and give yourself the power to access any terminal, be ignored by turrets, and so forth. You can always turn that stuff off when you're ready to test the pirate ship.

    This will also allow you to see what's going on with the programmable block: if it encounters an error, etc.

    You may also want to be careful with this particular script. When you store data, it's left there even if you recompile. Once you turn your pirate ship into a prefab, you'll want to open up the definition in something like Notepad++ and look for the "storage" string in the XML. You'll want to set it from "WhateverIsInTheStorageString" to "". (no space between the quote marks)

    Now when your pirate ship spawns, it will store the location it spawned in rather than the last location it spawned in when you were tinkering with it before it became a prefab.