Results 1 to 14 of 14

Thread: Adding a timer for a message

  1. #1
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Adding a timer for a message

    Could someone be kind enough please to help with the syntax for a delay timer.

    I have the following to display a message at the start of the mission. I've tried to take code from other scripts to add in a timer, but the ones I have found seem to have other events and such in them and I think I mess things up when trying to just add the timer code. How can I add say a 15 scond delay for this message to show please?

    using System;
    using maddox.game;
    using maddox.game.world;
    using System.Collections.Generic;

    public class Mission : AMission
    {

    public override void OnBattleStarted()
    {
    GamePlay.gpHUDLogCenter("Mission starting.");
    }



    }

    If I can get messages working then I can at least use them to test more complicated events as I try to learn them.
    I am Yo-Yo not YoYo (that's someone else)

  2. #2
    Team Fusion Artist's Avatar
    Join Date
    Mar 2010
    Posts
    2,877
    Post Thanks / Like
    Total Downloaded
    319.97 MB

    Re: Adding a timer for a message

    Read this:
    Code:
    ///
    /// Broadcasting Events and Mission Status
    ///
    /// @Author    Artist
    /// @Version   1.0.0
    ///
    ///
    /// === Example integration into Mission ===
    ///
    /// //$include <put-your-path-here>/Broadcast-vX.y.z.cs
    ///
    ///
    /// class Mission : AMission {
    ///     ...
    ///     public Broadcast m_Broadcast = null;
    ///     ...
    ///     public override void OnBattleStarted()
    ///     {
    ///         ...
    ///         m_Broadcast = new Broadcast(this, Time);
    ///         /// Print mission's status and time left in stated intervals (minutes)
    ///         m_Broadcast.AddAutoMessageChat(Broadcast.ARMY_ALL, 5, GetMissionStatusText);
    ///         ...
    ///     }
    ///     public string GetMissionStatusText()
    ///     {
    ///         string sResponse = "Mission status is ...";
    ///         return sResponse;
    ///     }
    ///     public void OnSomeEvent()
    ///     {
    ///         ...
    ///         m_Broadcast.ToChatAndScreen(Broadcast.ARMY_ALL, "airfield XYZ has been destroyed!");
    ///         ...
    ///     }
    ///
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class Broadcast {
        /// Delegate definition
        /// Delegate naming with class as prefix, funny errors if delegates from different classes have same name
        public delegate string Broadcast_GetString();
    
        /// some constants for readability
        public const int ARMY_ALL  = -1;
        public const int ARMY_NONE = 0;
        public const int ARMY_RED  = 1;
        public const int ARMY_BLUE = 2;
        
        /// Internals
        /// Class for auto messages
        protected class AutoMessage {
            public Broadcast_GetString m_dgGetString = null;
            public int m_iInterval = 0;
            public int m_iArmy = -1;
            public int m_iLastTick = 0;
            public bool m_bToChat   = false;
            public bool m_bToScreen = false;
        }
        protected AMission m_Mission = null;
        protected ITime    m_Time    = null;
        protected List<AutoMessage> m_aAutoMessages = null;
        /// <summary>
        /// Constructor
        /// </summary> 
        /// <param name="Mission">The Mission (use 'this')</param>
        public Broadcast(AMission Mission, ITime Time)
        {
            m_Mission = Mission;
            m_Time = Time;
            m_aAutoMessages = new List<AutoMessage>();
        }
        /// <summary>
        /// Add a message to be broadcasted in the chat at a stated interval.
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="iMinutes">Brodcast interval in minutes</param>
        /// <param name="dgFunc">A function that returns the message as string</param>
        public bool AddAutoMessageChat(int iArmy, int iMinutes, Broadcast_GetString dgFunc)
        {
            return AddAutoMessage(iArmy, iMinutes, false, true, dgFunc);
        }
        /// <summary>
        /// Add a message to be broadcasted on the screen at a stated interval.
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="iMinutes">Brodcast interval in minutes</param>
        /// <param name="dgFunc">A function that returns the message as string</param>
        public bool AddAutoMessageScreen(int iArmy, int iMinutes, Broadcast_GetString dgFunc)
        {
            return AddAutoMessage(iArmy, iMinutes, true, false, dgFunc);
        }
        /// <summary>
        /// Add a message to be broadcasted in the chat, on the screen, or both at a stated interval.
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="iMinutes">Brodcast interval in minutes</param>
        /// <param name="dgFunc">A function that returns the message as string</param>
        public bool AddAutoMessage(int iArmy, int iMinutes, bool bToScreen, bool bToChat, Broadcast_GetString dgFunc)
        {
            AutoMessage Am = new AutoMessage();
            Am.m_dgGetString = dgFunc;
            Am.m_iArmy       = iArmy;
            Am.m_iInterval   = iMinutes*60*36;
            Am.m_iLastTick   = m_Time.tickCounter();
            Am.m_bToChat     = bToChat;
            Am.m_bToScreen   = bToScreen;
            m_aAutoMessages.Add(Am);
            return true;
        }
        /// <summary>
        /// Check for and send auto messages due
        /// </summary> 
        /// <param name="iCurTick">Current game/time tick</param>
        public void DoAutoMessages()
        {
            int iCurTick = m_Time.tickCounter();
            foreach(AutoMessage Am in m_aAutoMessages)
            {
                if(Am.m_iLastTick + Am.m_iInterval < iCurTick)
                {
                    Am.m_iLastTick = iCurTick;
                    if(Am.m_bToChat)
                    {
                        ToChat(Am.m_iArmy, Am.m_dgGetString());
                    }
                    if(Am.m_bToScreen)
                    {
                        ToScreen(Am.m_iArmy, Am.m_dgGetString());
                    }
                }
            }
        }
        /// <summary>
        /// Broadcast message in the chat
        /// Constructor
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="sAnnouncement">The text</param>
        public void ToChat(int iArmy, string sAnnouncement)
        {
            ToChat(iArmy, sAnnouncement, new object[] { });
        }
        /// <summary>
        /// Broadcast message in the chat
        /// Constructor
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="sAnnouncement">The text</param>
        /// <param name="aParams">additional params for GamePlay.gpLogServer</param>
        public void ToChat(int iArmy, string sAnnouncement, object[] aParams)
        {
            if(ARMY_ALL == iArmy)
            {
                m_Mission.GamePlay.gpLogServer(null, sAnnouncement, aParams);
            }
            else
            {
                List<Player> Players = GetRecipents(iArmy);
                if (0 < Players.Count)
                {
                    m_Mission.GamePlay.gpLogServer(Players.ToArray(), sAnnouncement, aParams);
                }
            }
        }
        /// <summary>
        /// Broadcast message both in the chat and on the screen
        /// Constructor
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="sAnnouncement">The text</param>
        public void ToChatAndScreen(int iArmy, string sAnnouncement)
        {
            ToChatAndScreen(iArmy, sAnnouncement, new object[] { });
        }
        /// <summary>
        /// Broadcast message both in the chat and on the screen
        /// Constructor
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="sAnnouncement">The text</param>
        /// <param name="aParams">additional params for GamePlay.gpLogServer / GamePlay.gpHUDLogCenter</param>
        public void ToChatAndScreen(int iArmy, string sAnnouncement, object[] aParams)
        {
            if(ARMY_ALL == iArmy)
            {
                m_Mission.GamePlay.gpHUDLogCenter(null, sAnnouncement, aParams);
                m_Mission.GamePlay.gpLogServer(null, sAnnouncement, aParams);
            }
            else
            {
                List<Player> Players = GetRecipents(iArmy);
                if (0 < Players.Count)
                {
                    m_Mission.GamePlay.gpHUDLogCenter(Players.ToArray(), sAnnouncement, aParams);
                    m_Mission.GamePlay.gpLogServer(Players.ToArray(), sAnnouncement, aParams);
                }
            }
        }
        /// <summary>
        /// Broadcast message on the screen
        /// Constructor
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="sAnnouncement">The text</param>
        public void ToScreen(int iArmy, string sAnnouncement)
        {
            ToScreen(iArmy, sAnnouncement, new object[] { });
        }
        /// <summary>
        /// Broadcast message on the screen
        /// Constructor
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <param name="sAnnouncement">The text</param>
        /// <param name="aParams">additional params for GamePlay.gpHUDLogCenter</param>
        public void ToScreen(int iArmy, string sAnnouncement, object[] aParams)
        {
            if(ARMY_ALL == iArmy)
            {
                m_Mission.GamePlay.gpHUDLogCenter(null, sAnnouncement, aParams);
            }
            else
            {
                List<Player> Players = GetRecipents(iArmy);
                if (0 < Players.Count)
                {
                    m_Mission.GamePlay.gpHUDLogCenter(Players.ToArray(), sAnnouncement, aParams);
                }
            }
        }
        /// <summary>
        /// Collect players to broadcast to
        /// </summary> 
        /// <param name="iArmy">1 = red, 2 = blue, -1 = both</param>
        /// <returns>list of players</return>
        private List<Player> GetRecipents(int iArmy)
        {
            List<Player> Players = new List<Player>();
            
            /// Singleplayer mode or dedicated server
            if (m_Mission.GamePlay.gpPlayer() != null)
            {
                if (m_Mission.GamePlay.gpPlayer().Army() == iArmy || iArmy == ARMY_ALL)
                Players.Add(m_Mission.GamePlay.gpPlayer());
            }
            /// Multiplayer (Host Server on Client)
            if (m_Mission.GamePlay.gpRemotePlayers() != null || m_Mission.GamePlay.gpRemotePlayers().Length > 0)
            {
                foreach (Player p in m_Mission.GamePlay.gpRemotePlayers())
                {
                    if (p.Army() == iArmy || iArmy == ARMY_ALL)
                    Players.Add(p);
                }
            }
            return Players;
        }
    }

  3. #3
    Team Fusion Artist's Avatar
    Join Date
    Mar 2010
    Posts
    2,877
    Post Thanks / Like
    Total Downloaded
    319.97 MB

    Re: Adding a timer for a message

    Timer
    Code:
    public class Mission : AMission {
    
        ....
        private void EndMission()
        {
            ...
            Timeout(60, () => {
                m_Broadcast.ToChatAndScreen(Broadcast.ARMY_ALL, "Server restarting in 1 minute!!!");
            });
           ....
        }
    }

  4. Likes Yo-Yo, danperin liked this post
  5. #4
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Adding a timer for a message

    Read the code for the Mileage mission, it uses the Stopwatch.

    The timeout call has not worked reliably for me.

  6. #5
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Adding a timer for a message

    Quote Originally Posted by ATAG_Oskar View Post
    Read the code for the Mileage mission, it uses the Stopwatch.

    ...
    Thanks, where can I find that please, I can't see it in the stock missions, or the download section on this site?
    Last edited by Yo-Yo; Jul-23-2020 at 11:17.
    I am Yo-Yo not YoYo (that's someone else)

  7. #6
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

  8. Likes Yo-Yo, danperin liked this post
  9. #7
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Adding a timer for a message

    Thanks, the Timeout one was what I had been trying to get to work, and I did just manage it!

    I'll try the other code in that Milage mission after I get some more basics under my belt.
    I am Yo-Yo not YoYo (that's someone else)

  10. #8
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Adding a timer for a message

    BTW - An alternative for message on screen, is play a sound file of "Samples" folder.

    Since some sound files are broken - all with size less than 50kb, so you can record a new sound and use their names - the game only play the names of "Samples" folder.

  11. Likes Yo-Yo, N/A liked this post
  12. #9
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Adding a timer for a message

    An example trying create a bit of "drama" with voices in an script in this single mission, at start of mission fuel of AI wingman ends and he complaim.

    https://theairtacticalassaultgroup.c...downloadid=223

    An "It's CloD!" is that voice sounds (of Samples folder) not always match the message on screen.

    Other is that voice records is too muted - even with Voice adjust on maximum, it's almost inaudible.

  13. Likes danperin liked this post
  14. #10
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Adding a timer for a message

    Quote Originally Posted by 1lokos View Post
    An example trying create a bit of "drama" with voices in an script in this single mission, at start of mission fuel of AI wingman ends and he complaim.

    https://theairtacticalassaultgroup.c...downloadid=223

    An "It's CloD!" is that voice sounds (of Samples folder) not always match the message on screen.

    Other is that voice records is too muted - even with Voice adjust on maximum, it's almost inaudible.
    Thanks I'll check it out.
    I am Yo-Yo not YoYo (that's someone else)

  15. #11
    Novice Pilot ITAF_Airone1989's Avatar
    Join Date
    Aug 2020
    Posts
    95
    Post Thanks / Like
    Total Downloaded
    812.8 KB

    Re: Adding a timer for a message

    Sorry guys, I'm sure I read something about show a message just to red or blue side, but I cannot find it anymore...
    Particulary, I wish to show the message after 10, 15, 20 and 25 minutes from the beginning of the mission.
    Could somebody help me?
    Thank you very much

  16. #12
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Adding a timer for a message

    I you add timer to this, instead "OnAircraftTookOff"?

    Case 1 send message for Red, Case 2 send message for Blue

    Code:
        public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
        {
            base.OnAircraftTookOff(missionNumber, shortName, aircraft);
    
            if (GamePlay.gpPlayer().Place() != aircraft)
                return;
            
            switch (aircraft.Army())
            {
                case 1:
                    if (aircraft.Type() == AircraftType.Bomber)
                    { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Red Bomber, Bomb it all"); }
                    else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Red Fighter, fight them all"); }
                  break;
                case 2:
                    if (aircraft.Type() == AircraftType.Bomber)
                    { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Das bomber!"); }
                    else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Das jager!"); }
                  break;
    
            }
        }

  17. #13
    Novice Pilot ITAF_Airone1989's Avatar
    Join Date
    Aug 2020
    Posts
    95
    Post Thanks / Like
    Total Downloaded
    812.8 KB

    Re: Adding a timer for a message

    Thank you 1lokos but it's a multiplater map, so I need to send some message to both blue/red players during the game, but I need to be sure this messages will be delivered in the right moment...
    Any idea?

  18. #14
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Adding a timer for a message

    Try this.



    Code:
        const int ARMY_BLUE = 2;
        const int ARMY_RED = 1;
    
    
    
        private Player[] players(int army) {
    
            List<Player> list = new List<Player>();
            Player[] ps = GamePlay.gpRemotePlayers();
            foreach (Player p in ps) {
                if (p.Army() == army) {
                    list.Add(p);
                }
            }
            return list.ToArray();
        }
    
    
    
    	private void func() {
    	
            GamePlay.gpHUDLogCenter(players(ARMY_BLUE), "My Message");
    	}
    Last edited by ATAG_Oskar; Oct-02-2020 at 11:38.

  19. Likes OBT~Polak liked this post

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •