Beispiel #1
0
        /// <param name="args">Recipient grid, recipient block, message</param>
        private static void ProgrammableBlock_SendMessage(MyFunctionalBlock block, ListReader <Ingame.TerminalActionParameter> args)
        {
            if (args.Count != 3)
            {
                Logger.DebugLog("Wrong number of arguments, expected 3, got " + args.Count, Logger.severity.WARNING);
                if (MyAPIGateway.Session.Player != null)
                {
                    block.AppendCustomInfo("Failed to send message:\nWrong number of arguments, expected 3, got " + args.Count + '\n');
                }
                return;
            }

            string[] stringArgs = new string[3];
            for (int i = 0; i < 3; i++)
            {
                if (args[i].TypeCode != TypeCode.String)
                {
                    Logger.DebugLog("TerminalActionParameter #" + i + " is of wrong type, expected String, got " + args[i].TypeCode, Logger.severity.WARNING);
                    if (MyAPIGateway.Session.Player != null)
                    {
                        block.AppendCustomInfo("Failed to send message:\nTerminalActionParameter #" + i + " is of wrong type, expected String, got " + args[i].TypeCode + '\n');
                    }
                    return;
                }

                stringArgs[i] = (string)args[i].Value;
            }

            int count = Message.CreateAndSendMessage(block.EntityId, stringArgs[0], stringArgs[1], stringArgs[2]);

            if (MyAPIGateway.Session.Player != null)
            {
                (block as IMyTerminalBlock).AppendCustomInfo("Sent message to " + count + " block" + (count == 1 ? "" : "s"));
            }
        }
Beispiel #2
0
        private static void SendMessage(MyFunctionalBlock block)
        {
            ManualMessage instance;

            if (!Registrar.TryGetValue(block.EntityId, out instance))
            {
                throw new ArgumentException("block id not found in registrar");
            }

            block.RebuildControls();

            if (instance.m_sending)
            {
                if (instance.m_targetShipName.Length < 3)
                {
                    block.AppendCustomInfo("Ship Name(s) must be at least 3 characters");
                    return;
                }
                if (instance.m_targetBlockName.Length < 3)
                {
                    block.AppendCustomInfo("Block Name(s) must be at least 3 characters");
                    return;
                }

                int count = Message.CreateAndSendMessage(block.EntityId, instance.m_targetShipName.ToString(), instance.m_targetBlockName.ToString(), instance.m_message.ToString());
                if (MyAPIGateway.Session.Player != null)
                {
                    (block as IMyTerminalBlock).AppendCustomInfo("Sent message to " + count + " block" + (count == 1 ? "" : "s"));
                }

                instance.m_sending = false;
            }
            else
            {
                instance.m_sending = true;
            }
        }