Announcement

Collapse
No announcement yet.

Scripting Help

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scripting Help

    Hey guys, I'm trying to get a script to work where I could add an action to a vehicle that would play an audio clip (coming from the vehicle) that everyone nearby could hear. I posted this question on a forum, and a guy gave me this script, but there is a scripting error (and I'm clueless with scripting errors and scripting in general). Just wondering if any of you guys would know how to fix it, as the guy hasn't replied to my post in awhile. Here is the link to the forum that contains the script he gave me (2nd to last post), and the error message that I keep getting at the start of the mission (last post).

    http://www.ofpec.com/forum/index.php?topic=32925.0

  • #2
    Re: Scripting Help

    Mighty complicated script, but what I see wrong is there is no semi-colons at the end of your generated code.

    Change the script to this, and see if it works:

    Code:
    // 0 : Turn on Speakers
    // -1 : Turn off Speakers
    
    private["_car","_id","_arg","_var"];
    _car = _this select 0;
    _id = _this select 2;
    _arg = _this select 3;
    
    switch (_arg) do {
    	case 0:	{
    		_car removeAction _id;
    		
    		if (alive _car) then {
    			call compile format["ROMM_%1AUDIO = true;", _car];
    			[_car] spawn {
    				_car = _this select 0;
    				_var = call compile format["ROMM_%1AUDIO", _car];
    				while {_var AND alive _car} do {
    					_car setvehicleinit "this say 'sample1'";
    					processinitcommands;
    					sleep 15;
    				};
    			};
    			_car addaction ["Disable Audio","ROMM_carAudio.sqf",[1]];
    		};
    	};
    	case -1: {
    		if NOT(isnil format["ROMM_%1AUDIO", _car]) then {_car removeAction _id};
    		if (alive _car) then {
    			call compile format["ROMM_%1AUDIO = false;", _car];
    			_car addaction ["Enable Audio","ROMM_carAudio.sqf",[0]];
    		};
    	};
    };

    Comment


    • #3
      Re: Scripting Help

      Originally posted by beita View Post
      Mighty complicated script, but what I see wrong is there is no semi-colons at the end of your generated code.

      Change the script to this, and see if it works:

      Code:
      // 0 : Turn on Speakers
      // -1 : Turn off Speakers
      
      private["_car","_id","_arg","_var"];
      _car = _this select 0;
      _id = _this select 2;
      _arg = _this select 3;
      
      switch (_arg) do {
      	case 0:	{
      		_car removeAction _id;
      		
      		if (alive _car) then {
      			call compile format["ROMM_%1AUDIO = true;", _car];
      			[_car] spawn {
      				_car = _this select 0;
      				_var = call compile format["ROMM_%1AUDIO", _car];
      				while {_var AND alive _car} do {
      					_car setvehicleinit "this say 'sample1'";
      					processinitcommands;
      					sleep 15;
      				};
      			};
      			_car addaction ["Disable Audio","ROMM_carAudio.sqf",[1]];
      		};
      	};
      	case -1: {
      		if NOT(isnil format["ROMM_%1AUDIO", _car]) then {_car removeAction _id};
      		if (alive _car) then {
      			call compile format["ROMM_%1AUDIO = false;", _car];
      			_car addaction ["Enable Audio","ROMM_carAudio.sqf",[0]];
      		};
      	};
      };
      Nope, still doesn't work. I get the same error message as the one in the screenshot.

      Comment


      • #4
        Re: Scripting Help

        Well, that code is way above my head.

        Depending on how you want it to work, you might simply want to add the action to the init line of the vehicle in the editor ...

        What exactly do you want done? Explain it thoroughly, and there might be an easier way to do it ...

        Comment


        • #5
          Re: Scripting Help

          Originally posted by beita View Post
          Well, that code is way above my head.

          Depending on how you want it to work, you might simply want to add the action to the init line of the vehicle in the editor ...

          What exactly do you want done? Explain it thoroughly, and there might be an easier way to do it ...
          Well, I wanted to add an action to a vehicle where it would play a sound file (in a loop), so that everyone that is near the vehicle can hear it. But I don't want the sound file to play over itself if the players activated the action more than once while the sound is playing. I also wanted an action that would stop the vehicle from playing the sound (and of course, players should still be able to turn the sound back on). This action would be placed on several vehicles. I tried the script from the very first post, but only the person that actually activated the action would be able to hear it and no one else, unless they too activated the action themselves.

          Comment


          • #6
            Re: Scripting Help

            copy and paste if possible the exact error message on the top left hand of the screen.
            I have an idea but I just want to make sure.

            TGU Instructor TG Pathfinder

            Former TGU Dean Former ARMA Admin Former Irregulars Officer

            "Do not seek death. Death will find you. But seek the road which makes death a fulfillment." - Dag Hammarskjold

            Comment


            • #7
              Re: Scripting Help

              Originally posted by LowSpeedHighDrag View Post
              copy and paste if possible the exact error message on the top left hand of the screen.
              I have an idea but I just want to make sure.

              Comment


              • #8
                Re: Scripting Help

                can you give us the line you initiated the script with? i.e.

                [carname, ??, number, word, something] execVM "thatscript.sqf";

                and just a shot in the dark, but is the vehicle named in the editor? from the error it appears as if the code is trying to make a variable name with spaces ... this won't work... i.e., it is trying to execute this command:

                ROMM_13de1400 27990: gmv_hmmvw.p3dAUDIO = false;

                but the author wanted it to look like this:

                ROMM_yourCarNameHereAUDIO = false;

                something like this usually happens if the vehicle wasn't given a name in the editor.....

                Comment


                • #9
                  Re: Scripting Help

                  Originally posted by Homer Johnston View Post
                  can you give us the line you initiated the script with? i.e.

                  [carname, ??, number, word, something] execVM "thatscript.sqf";

                  and just a shot in the dark, but is the vehicle named in the editor? from the error it appears as if the code is trying to make a variable name with spaces ... this won't work... i.e., it is trying to execute this command:

                  ROMM_13de1400 27990: gmv_hmmvw.p3dAUDIO = false;

                  but the author wanted it to look like this:

                  ROMM_yourCarNameHereAUDIO = false;

                  something like this usually happens if the vehicle wasn't given a name in the editor.....
                  No, the vehicles aren't named in the editor.

                  Here is the Init line for the vehicle:
                  Code:
                  nil = [this,"","",-1] execVM "ROMM_carAudio.sqf"
                  This is the script for ROMM_carAudio.sqf:
                  Code:
                  // 0 : Turn on Speakers
                  // -1 : Turn off Speakers
                  
                  private["_car","_id","_arg","_var"];
                  _car = _this select 0;
                  _id = _this select 2;
                  _arg = _this select 3;
                  
                  switch (_arg) do {
                  	case 0:	{
                  		_car removeAction _id;
                  		
                  		if (alive _car) then {
                  			call compile format["ROMM_%1AUDIO = true", _car];
                  			[_car] spawn {
                  				_car = _this select 0;
                  				_var = call compile format["ROMM_%1AUDIO", _car];
                  				while {_var AND alive _car} do {
                  					_car setvehicleinit "this say 'sample1'";
                  					processinitcommands;
                  					sleep 15;
                  				};
                  			};
                  			_car addaction ["Disable Audio","ROMM_carAudio.sqf",[1]];
                  		};
                  	};
                  	case -1: {
                  		if NOT(isnil format["ROMM_%1AUDIO", _car]) then {_car removeAction _id};
                  		if (alive _car) then {
                  			call compile format["ROMM_%1AUDIO = false", _car];
                  			_car addaction ["Enable Audio","ROMM_carAudio.sqf",[0]];
                  		};
                  	};
                  };

                  Comment


                  • #10
                    Re: Scripting Help

                    damn, that's fairly clever. But he made a couple little mistakes (if you care to tell him, he passed variables [0] and [1], which should have been 0 and -1). You'll have to name the car, or else add code that will name it (I think it is possible). Doesn't matter what the name is, as long as there's no spaces in it. Then try this code... however, I don't think his method will work in MP... if you don't get a solution to it in the next couple days I will try, currently lots to do...

                    Code:
                    was garbage. deleted this to make thread easier to read. see my next post.
                    Don't forget to change the sound name to your own, and the loop length (sleep 15)! Cheers & stuff.
                    (btw if any of you are curious I would be willing to walk you through that code, it gets a lot simpler once you format it "correctly"...)
                    Last edited by Homer Johnston; 02-12-2009, 02:45 AM. Reason: removed bad code

                    Comment


                    • #11
                      Re: Scripting Help

                      oops. thought it worked when I tested it. turned out me moron :D

                      here, this should work now. i also think it WILL work in MP, actually. it still needs to finish playing through the sound after it starts though... that fact may be changeable if you need it, but will take a little more time than this fix did...

                      Code:
                      // 0 : Turn on Speakers
                      // -1 : Turn off Speakers
                      
                      private["_car","_id","_arg","_var"];
                      _car = _this select 0;
                      _id = _this select 2;
                      _arg = _this select 3;
                      
                      switch (_arg) do
                      {
                      	case 0:
                      	{
                      		_car removeAction _id;
                      		if (alive _car) then
                      		{
                      			call compile format["ROMM_%1AUDIO = true", _car];
                      			[_car] spawn
                      			{
                      				_car = _this select 0;
                      				_var = call compile format["ROMM_%1AUDIO", _car];
                      				while {_var AND alive _car} do
                      				{
                      					_car setvehicleinit "this say 'YOURSOUNDNAME'";
                      					processinitcommands;
                      					sleep 15;
                      					_var = call compile format["ROMM_%1AUDIO", _car]; //Re-check if audio is on or off
                      				};
                      			};
                      			_car addaction ["Disable Audio","ROMM_carAudio.sqf",-1];
                      		};
                      	};
                      	case -1:
                      	{
                      		if NOT(isnil format["ROMM_%1AUDIO", _car]) then
                      		{
                      			_car removeAction _id
                      		};
                      		if (alive _car) then
                      		{
                      			call compile format["ROMM_%1AUDIO = false", _car];
                      			_car addaction ["Enable Audio","ROMM_carAudio.sqf",0];
                      		};
                      	};
                      };

                      Comment


                      • #12
                        Re: Scripting Help

                        That works perfectly, thanks alot Homer!

                        Comment


                        • #13
                          Re: Scripting Help

                          I have to say fellas, I am superbly impressed with the level of support being offered between the mission makers new and old here and it is very pleasing to see us a community working as such together.

                          Props to you all.

                          I would just like to reiterate a level of control with regards scripts.....lots of scripts running are VERY bad for a MP server as has been proven for several years now here at TG ArmA.

                          Adding some fun new elements is great, but please for the sake of gameplay, and server reliability, keep these to a minimum.

                          Once again congrats on the great level of support this part of the forum is offering.

                          Well done fellas.

                          BD1
                          BlackDog1




                          "What we do in life... echoes in eternity!"

                          Comment

                          Connect

                          Collapse

                          TeamSpeak 3 Server

                          Collapse

                          Advertisement

                          Collapse

                          Twitter Feed

                          Collapse

                          Working...
                          X