Results 1 to 17 of 17

Thread: Timer in Script not work

  1. #1
    Combat pilot Veteran66's Avatar
    Join Date
    Jan 2013
    Posts
    120
    Post Thanks / Like
    Total Downloaded
    206.20 MB

    Timer in Script not work

    Hi all

    Message and Sound work fine, but with the Timer not, what is wrong?
    -----------------------------------------------------------------------------------------------------------------------------

    if ("trigger_zielgetroffen1".Equals(shortName) && active)

    double initTime = 0.0;
    Timeout(initTime += 20.0, () =>

    {
    GamePlay.gpHUDLogCenter("Ziel getroffen 1");
    System.Media.SoundPlayer player = new System.Media.SoundPlayer(BaseMissionPath + "sound1.wav");
    player.Play();
    }
    My System:
    Windows 11
    RAM 64,0 GB
    Intel i7 3.80GHz
    NIVIDIA GeForce RTX 3070

  2. #2
    Ace Bonditaria's Avatar
    Join Date
    Oct 2015
    Location
    Rotterdam
    Posts
    1,160
    Post Thanks / Like
    Total Downloaded
    2.82 GB

    Re: Timer in Script not work

    You have an uneven number of brackets in the line "Timeout(initTime += 20.0, () =>" ?

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

    Re: Timer in Script not work

    After you fixed the missing brace Bonditaria pointed out - if that was not just not a copy paste error - try with first command only

    Code:
    if ("trigger_zielgetroffen1".Equals(shortName) && active)
    {
        double initTime = 0.0;
        Timeout(initTime += 20.0, () => {
            GamePlay.gpHUDLogCenter("Ziel getroffen 1");
            // System.Media.SoundPlayer player = new System.Media.SoundPlayer(BaseMissionPath + "sound1.wav");
            // player.Play();
        });
    }

  4. #4
    ATAG_Colander's Avatar
    Join Date
    Nov 2011
    Location
    Bir Tawil
    Posts
    11,128
    Post Thanks / Like
    Total Downloaded
    255.73 MB

    Re: Timer in Script not work

    And...
    initTime is not really needed/used there. You can just do this:
    Code:
    if ("trigger_zielgetroffen1".Equals(shortName) && active)
    {
        Timeout(20.0, () => {
            GamePlay.gpHUDLogCenter("Ziel getroffen 1");
            // System.Media.SoundPlayer player = new System.Media.SoundPlayer(BaseMissionPath + "sound1.wav");
            // player.Play();
        });
    }

  5. Likes Veteran66 liked this post
  6. #5
    Combat pilot Veteran66's Avatar
    Join Date
    Jan 2013
    Posts
    120
    Post Thanks / Like
    Total Downloaded
    206.20 MB

    Re: Timer in Script not work

    thx, work fine
    My System:
    Windows 11
    RAM 64,0 GB
    Intel i7 3.80GHz
    NIVIDIA GeForce RTX 3070

  7. #6
    Novice Pilot Pernix2's Avatar
    Join Date
    Jul 2016
    Posts
    96
    Post Thanks / Like
    Total Downloaded
    35.19 MB

    Re: Timer in Script not work

    Good evening.
    I would like to hear the music in my headphones while I fly my biplane over the Libyan desert.
    I tried to insert the script, attached above, in the File.cs, but nothing, it doesn't work.
    Can anyone tell me step by step how to do it?
    Thank you

    Pernix

  8. #7
    Supporting Member
    Join Date
    Dec 2019
    Posts
    486
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Timer in Script not work

    Quote Originally Posted by Pernix2 View Post
    Good evening.
    I would like to hear the music in my headphones while I fly my biplane over the Libyan desert.
    I tried to insert the script, attached above, in the File.cs, but nothing, it doesn't work.
    Can anyone tell me step by step how to do it?
    Thank you

    Pernix
    You'd need to let people know what level of scripting you are at, do you make missions already, don't know a thing etc.

    I'd suggest to start a new thread with code from a test mission you are trying to get to work and see if someone can help.

    I don't have time to help right now, but if you are totally a novice check out my guide in the stickies and set up a mission that triggers some text when you take off, or after some timer, or on a trigger you fly thorugh. Then when you know that is working, add in the music playing script at that very point and see if you can get it to work.

    If you are not a total beginner then the first mission of my 303 campaign (for our freedom and yours) plays music when you are within a certain distance of an enemy (I think that is what I used). Download my campaign, open up the first mission and you should be able to find the bit playing the music and pull it apart from there.

    If you want to 'just hear music whilst flying', I'd suggest just use a music player like foobar2000 with whatever it is you require. I picked up some cheap WWII/30s/40s themed music that I use for 'atmopsphere'.
    I am Yo-Yo not YoYo (that's someone else)

  9. #8
    Novice Pilot Pernix2's Avatar
    Join Date
    Jul 2016
    Posts
    96
    Post Thanks / Like
    Total Downloaded
    35.19 MB

    Re: Timer in Script not work

    Quote Originally Posted by Yo-Yo View Post
    You'd need to let people know what level of scripting you are at, do you make missions already, don't know a thing etc.

    I'd suggest to start a new thread with code from a test mission you are trying to get to work and see if someone can help.

    I don't have time to help right now, but if you are totally a novice check out my guide in the stickies and set up a mission that triggers some text when you take off, or after some timer, or on a trigger you fly thorugh. Then when you know that is working, add in the music playing script at that very point and see if you can get it to work.

    If you are not a total beginner then the first mission of my 303 campaign (for our freedom and yours) plays music when you are within a certain distance of an enemy (I think that is what I used). Download my campaign, open up the first mission and you should be able to find the bit playing the music and pull it apart from there.

    If you want to 'just hear music whilst flying', I'd suggest just use a music player like foobar2000 with whatever it is you require. I picked up some cheap WWII/30s/40s themed music that I use for 'atmopsphere'.
    Hi everyone.
    Thanks Yo-Yo for your directions, but just to make you understand my level, I wasn't even able to install your campaign (despite following your directions). I get along well with missions, I'm not a beginner, but I limit myself to reworking the ".cs file", not rewriting it every time. (I'm more excited about the historical aspect of the events).
    I tried to follow your instructions, but I still can't get the music, when a trigger goes off, if I don't bother, I'll attach the test ".cs file" below, so if some friend can help me understand where I err.
    P.S. I place the ".waw file" in the same folder where I place the other 3 (mis,briefing,cs), is that correct?(the last one part is for the music file, but I can't hear it....I think it doesn't work).
    Thank you
    Pernix

    Code:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using maddox.game;
    using maddox.game.world;
    using System.Media;
    using maddox.GP;
    using System.IO;
    using System.Reflection;
    using System.Timers; 
    using part; 
    
    public class Mission : AMission
    {
    	public void _DespawnEmptyPlane(AiActor actor)
    	{
    		if (actor == null)
    		{ 
    			return;
    		}
    
    			Player[] Players = GamePlay.gpRemotePlayers();
    
    	bool PlaneIsEmpty = true;
    
    		foreach (Player i in Players)
    		{
    			if ((i.Place() as AiAircraft) == (actor as AiAircraft))
    			{
    				PlaneIsEmpty = false;
    				break;
    			}
    		}
    
    		if (PlaneIsEmpty)
    		{ 
    			(actor as AiAircraft).Destroy(); 
    		}
    	}
    
    	public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    	{
    		base.OnPlaceLeave(player, actor, placeIndex);
    		Timeout(5, () =>
    		{
    			_DespawnEmptyPlane(actor);
    		});
    	}
        
    private void sendScreenMessageTo(int army, string msg, object[] parms)
        {
            List<Player> Players = new List<Player>();
    
            //Singleplayer or Dedi Server
            if (GamePlay.gpPlayer() != null)
            {
                if (GamePlay.gpPlayer().Army() == army || army == -1)
                    Players.Add(GamePlay.gpPlayer());
            } // Multiplayer
            if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)
            {
                foreach (Player p in GamePlay.gpRemotePlayers())
                {
                    if (p.Army() == army || army == -1)
                        Players.Add(p);
                }
            }
            if (Players != null && Players.Count > 0)
                GamePlay.gpHUDLogCenter(Players.ToArray(), msg, parms);
        }
    
    
        private void sendChatMessageTo(int army, string msg, object[] parms)
        {
            List<Player> Players = new List<Player>();
    
            //Singleplayer or Dedi Server
            if (GamePlay.gpPlayer() != null)
            {
                if (GamePlay.gpPlayer().Army() == army || army == -1)
                    Players.Add(GamePlay.gpPlayer());
            } // Multiplayer
            if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)
            {
                foreach (Player p in GamePlay.gpRemotePlayers())
                {
                    if (p.Army() == army || army == -1)
                        Players.Add(p);
                }
            }
            if (Players != null && Players.Count > 0)
                GamePlay.gpLogServer(Players.ToArray(), msg, parms);
        }
    
    
        public override void OnTrigger(int missionNumber, string shortName, bool active)
        {
     
    			if ("g1".Equals(shortName))
    			{
    				AiAction Action = GamePlay.gpGetAction("g1");
    					if (Action != null)
    					{
    						Action.Do();
    						GamePlay.gpGetTrigger(shortName).Enable = false;
    					}
    				Timeout(5, () => sendScreenMessageTo(2, "11", null));
    				Timeout(11, () => sendScreenMessageTo(2, "22", null));
    				Timeout(27, () => sendScreenMessageTo(2, "BLUE TEAM, Escort Ju87 from Calais, alt 4.5K", null));
    				Timeout(30, () => sendScreenMessageTo(2, "BLUE TEAM, Ju87 obj is Dover port", null));
    
    			} 
    
    					
    			if ("g2".Equals(shortName))
    			{
    				AiAction Action = GamePlay.gpGetAction("g2");
    					if (Action != null)
    					{
    						Action.Do();
    						GamePlay.gpGetTrigger(shortName).Enable = false;
    					}
    				Timeout(10, () => sendScreenMessageTo(1, "33", null));
    				Timeout(20, () => sendScreenMessageTo(1, "44", null));
    				Timeout(27, () => sendScreenMessageTo(1, "RED TEAM, Scramble! New contact group, Ju87 from Calais", null));
    				Timeout(30, () => sendScreenMessageTo(1, "RED TEAM, Bombers Mid Channel angels 15, direction Dover", null));
    
    			} 
    			
    
        			if ("ju87".Equals(shortName))
    			{
    				AiAction Action = GamePlay.gpGetAction("ju87");
    					if (Action != null)
    					{
    						Action.Do();
    						GamePlay.gpGetTrigger(shortName).Enable = false;
    					} 
          if ("trigger_ju87".Equals(shortName) && active)
    {
        Timeout(5.0, () => {
            GamePlay.gpHUDLogCenter("ju87");
            // System.Media.SoundPlayer player = new System.Media.SoundPlayer("True-Patriot.wav");
            // player.Play();
        });
    }
    				}	 	
            }	
    	}
    Last edited by ATAG_Colander; Oct-11-2023 at 10:12. Reason: Added code tags

  10. #9
    Ace Bonditaria's Avatar
    Join Date
    Oct 2015
    Location
    Rotterdam
    Posts
    1,160
    Post Thanks / Like
    Total Downloaded
    2.82 GB

    Re: Timer in Script not work

    your lines for the player are commented out;


    // System.Media.SoundPlayer player = new System.Media.SoundPlayer("True-Patriot.wav");
    // player.Play();

    remove the "//"and retest please.

  11. #10
    Supporting Member
    Join Date
    Dec 2019
    Posts
    486
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Timer in Script not work

    Quote Originally Posted by Pernix2 View Post
    Hi everyone.
    I wasn't even able to install your campaign (despite following your directions).
    Maybe you don't have Tobruk?

    And what error message do you get in the console in game?

    Judging by the track name I guess you've pulled the code from my mission, where you notice I specify the path not just the filename, I do some stuff to put the path into a variable called 'audiopath' then concatenate with the audiofilename as:

    System.Media.SoundPlayer player = new System.Media.SoundPlayer(audiopath + "True-Patriot.wav");

    If the console error message is saying the file cannot be found, try manually typing it in

    I just made a mission that triggerd the track ok, using this:

    System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Users\your_user_name \Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Single"+ "True-Patriot.wav");

    Of course I have amended it to say 'your_user_name' rather than my user name on my pc

    Just made sure the wav file was in the same folder as all those single missions.
    Last edited by Yo-Yo; Oct-11-2023 at 09:36.
    I am Yo-Yo not YoYo (that's someone else)

  12. #11
    Novice Pilot Pernix2's Avatar
    Join Date
    Jul 2016
    Posts
    96
    Post Thanks / Like
    Total Downloaded
    35.19 MB

    Re: Timer in Script not work

    Quote Originally Posted by Bonditaria View Post
    your lines for the player are commented out;


    // System.Media.SoundPlayer player = new System.Media.SoundPlayer("True-Patriot.wav");
    // player.Play();

    remove the "//"and retest please.

    Thanks Bondi, but it doesn't work...isn't the location of the ".Wav" file wrong? Is it right that he is with the other three?
    thanks bye
    Pernix

  13. #12
    Novice Pilot Pernix2's Avatar
    Join Date
    Jul 2016
    Posts
    96
    Post Thanks / Like
    Total Downloaded
    35.19 MB

    Re: Timer in Script not work

    Quote Originally Posted by Yo-Yo View Post
    Maybe you don't have Tobruk?
    Yes, I have Tobruk, even if the mission I attached is BOB.
    Bye

  14. #13
    Supporting Member
    Join Date
    Dec 2019
    Posts
    486
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Timer in Script not work

    Try this, just change the path where it says 'your_user_name' and drive letter if appropriate etc.

    My game by default puts tobruk.100 in the Parts so I deleted it and it seems to still work. The only complication in the code here is a bool to prevent the trigger firing more than once.

    Mis file:

    Code:
    [PARTS]
      core.100
      bob.100
    [MAIN]
      MAP Land$English_Channel_1940
      DespawnAfterLandingTimeout 600
      BattleArea 0 0 393215 393215 5000
      TIME 10.0000002421439
      WeatherIndex 0
      CloudsHeight 1000
      BreezeActivity 10
      ThermalActivity 10
      player BoB_RAF_B_218Sqn.000
    [GlobalWind_0]
      Power 3.000 0.000 0.000
      BottomBound 0.00
      TopBound 1500.00
      GustPower 0
      GustAngle 45
    [splines]
    [AirGroups]
      BoB_RAF_B_218Sqn.01
    [BoB_RAF_B_218Sqn.01]
      Flight0  1
      Class Aircraft.HurricaneMkI_100oct
      Formation LINEABREAST
      CallSign 26
      Fuel 100
      Weapons 1
      Skill 0.84 0.53 0.53 0.37 0.37 0.53 0.53 0.53
      Aging 0
    [BoB_RAF_B_218Sqn.01_Way]
      NORMFLY 245564.16 259011.35 500.00 300.00
      NORMFLY 253231.97 259048.09 500.00 300.00
    [CustomChiefs]
    [Stationary]
    [Buildings]
    [BuildingsLinks]
    [Trigger]
      soundTrigger TPassThrough 0 248232 258989 1250
    .cs file

    Code:
    using System;
    using System.IO;
    using System.Media;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using maddox.game;
    using maddox.game.world;
    
    public class Mission : AMission
    {
    
    bool prevent = false;
    
    
    
    
    
    	public override void OnTrigger(int missionNumber, string shortName, bool active)
        	{
            	if ("soundTrigger".Equals(shortName))
            		{
    					if (prevent == false) 
    					{
      			       			GamePlay.gpHUDLogCenter("Start music");
    
    
    
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Users\your_user_name\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Single\"+ "True-Patriot.wav");
    player.Play();
    
    
    							prevent = true;
            			}
    					else
    					{
    					//Do nothing					
    					}
    
    				}	
        	}
    }
    I am Yo-Yo not YoYo (that's someone else)

  15. Likes Pernix2 liked this post
  16. #14
    Supporting Member
    Join Date
    Dec 2019
    Posts
    486
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Timer in Script not work

    Quote Originally Posted by Pernix2 View Post
    Yes, I have Tobruk, even if the mission I attached is BOB.
    Bye
    What doesn't work? What mssages do you get in the game console? You can post in the relevant thread for the missions, or PM me?

    And I realise my basic mission above is not timer related, my intention/suggestion is just that you get the sound file playing first before then putting it within anything more complicated.
    Last edited by Yo-Yo; Oct-11-2023 at 09:54.
    I am Yo-Yo not YoYo (that's someone else)

  17. #15
    ATAG_Colander's Avatar
    Join Date
    Nov 2011
    Location
    Bir Tawil
    Posts
    11,128
    Post Thanks / Like
    Total Downloaded
    255.73 MB

    Re: Timer in Script not work

    I think the issue is that the "player" variable is destructed after the timer function ends.


    // Start of timer anonymous function
    {

    // Variable "player" is created and the wav file loaded
    System.Media.SoundPlayer player = new System.Media.SoundPlayer("True-Patriot.wav");

    // the variable is told to start playing the sound asynchronously.
    player.Play();

    // function ends and the "player" variable is destroyed which stops the sound from playing
    }

  18. Likes RAF74_Buzzsaw liked this post
  19. #16
    Novice Pilot Pernix2's Avatar
    Join Date
    Jul 2016
    Posts
    96
    Post Thanks / Like
    Total Downloaded
    35.19 MB

    Re: Timer in Script not work

    Quote Originally Posted by Yo-Yo View Post
    Try this, just change the path where it says 'your_user_name' and drive letter if appropriate etc.

    My game by default puts tobruk.100 in the Parts so I deleted it and it seems to still work. The only complication in the code here is a bool to prevent the trigger firing more than once.

    Mis file:

    Code:
    [PARTS]
      core.100
      bob.100
    [MAIN]
      MAP Land$English_Channel_1940
      DespawnAfterLandingTimeout 600
      BattleArea 0 0 393215 393215 5000
      TIME 10.0000002421439
      WeatherIndex 0
      CloudsHeight 1000
      BreezeActivity 10
      ThermalActivity 10
      player BoB_RAF_B_218Sqn.000
    [GlobalWind_0]
      Power 3.000 0.000 0.000
      BottomBound 0.00
      TopBound 1500.00
      GustPower 0
      GustAngle 45
    [splines]
    [AirGroups]
      BoB_RAF_B_218Sqn.01
    [BoB_RAF_B_218Sqn.01]
      Flight0  1
      Class Aircraft.HurricaneMkI_100oct
      Formation LINEABREAST
      CallSign 26
      Fuel 100
      Weapons 1
      Skill 0.84 0.53 0.53 0.37 0.37 0.53 0.53 0.53
      Aging 0
    [BoB_RAF_B_218Sqn.01_Way]
      NORMFLY 245564.16 259011.35 500.00 300.00
      NORMFLY 253231.97 259048.09 500.00 300.00
    [CustomChiefs]
    [Stationary]
    [Buildings]
    [BuildingsLinks]
    [Trigger]
      soundTrigger TPassThrough 0 248232 258989 1250
    .cs file

    Code:
    using System;
    using System.IO;
    using System.Media;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using maddox.game;
    using maddox.game.world;
    
    public class Mission : AMission
    {
    
    bool prevent = false;
    
    
    
    
    
    	public override void OnTrigger(int missionNumber, string shortName, bool active)
        	{
            	if ("soundTrigger".Equals(shortName))
            		{
    					if (prevent == false) 
    					{
      			       			GamePlay.gpHUDLogCenter("Start music");
    
    
    
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Users\your_user_name\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Single\"+ "True-Patriot.wav");
    player.Play();
    
    
    							prevent = true;
            			}
    					else
    					{
    					//Do nothing					
    					}
    
    				}	
        	}
    }

    Hello Yo-Yo.
    thank you so much
    Finally this script works, I ran the little mission, and when it is indicated on the screen the music actually starts. except that the music doesn't stop, not even when I leave the mission. I had to close the game, and then it stopped. it should at least end at the end of the mission... or at a definable time.
    thanks bye

  20. Likes Yo-Yo liked this post
  21. #17
    Supporting Member
    Join Date
    Dec 2019
    Posts
    486
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Timer in Script not work

    Quote Originally Posted by Pernix2 View Post
    Hello Yo-Yo.
    thank you so much
    Finally this script works, I ran the little mission, and when it is indicated on the screen the music actually starts. except that the music doesn't stop, not even when I leave the mission. I had to close the game, and then it stopped. it should at least end at the end of the mission... or at a definable time.
    thanks bye
    Glad it worked.

    To stop the music when you leave the mission, you can add a blank track of just a second of nothing, and have that trigger when the OnBattleStoped event is triggered:
    Code:
     public override void OnBattleStoped()
        {
            base.OnBattleStoped();
    
            System.Media.SoundPlayer player4 = new System.Media.SoundPlayer(folderpath + "blank.wav");
            player4.Play();
    }
    Note the event is I think mispelt (stoped not stopped)

    Again folderpath is constructed elsewhere in my mission code that I cut this from, but is just the path to where the mission files are. If you got music to play, you know how to get another (blank) file to play. The important bit is just the use of the event to trigger an empty wav file as only one can play at a time.
    Last edited by Yo-Yo; Nov-09-2023 at 18:43.
    I am Yo-Yo not YoYo (that's someone else)

  22. Likes Pernix2 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
  •