Announcement

Collapse
No announcement yet.

The Scripting How-To Thread

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

  • The Scripting How-To Thread

    With a lot of players taking their hand to ArmA2's mission editor, I've also been hearing (and asking!) a lot of script-related questions. What do you do when no one is around, or no one has the answer you need? Ask here! For starters...

    Is it possible to sort ammo crate contents to your liking, as opposed to alphabetically? ACE for ArmA1 did this to some extent by breaking up weapons into categories, but I don't know how this was done.

  • #2
    Re: The Scripting How-To Thread

    Nice thread, here's one I've been looking for an answer to not sure if it's scripting persay but; is it possible to have JIP and no respawn and if so how.

    Comment


    • #3
      Re: The Scripting How-To Thread

      If you have scripting questions, use the search-function at the forum at www.ofpec.com, or BIS' forum.

      If that doesn't help you, then start asking people :)

      Oh, and as for the ammo crates. I do suggest that you use cPBO and Kegety's UnRap to open up the config files in ACE and see how they've done it. No better way of learning than to seehow others have done.



      Comment


      • #4
        Re: The Scripting How-To Thread

        Nice thread, here's one I've been looking for an answer to not sure if it's scripting persay but; is it possible to have JIP and no respawn and if so how.
        Have the respawn marker in some sort of confined cage so players can't physically rejoin the battle. Moreover, they should be put into a separate 'dead' group so they can't communicate with their team. Finally, you can enable a trigger for a spectator script which can be accessed only when inside that cage.

        Comment


        • #5
          Re: The Scripting How-To Thread

          I'm trying to add an action to certain units that are near an MTVR but for some reasons, it does not work. This is what I have:

          init_action.sqf
          Code:
          _target = _this select 0;
          
          while {alive _target} do
          {
          	if (count(nearestobject [_target, "MTVR"]) > 0) then
          	{
          		deploySand = _target addAction ["Deploy Sandbag","deploySand.sqf"];
          	}
          	else
          	{
          		_target removeAction deploySand;
          	};
          };
          Also, I put this in the init field of the unit:



          Code:
          nul00 = [this] execVM "init_action.sqf";
          Don't know what I'm doing wrong. Was wondering if someone could double check it. Thanks.


          IN GAME ARMA: |TG-Irr| Lq.Snake

          Comment


          • #6
            Re: The Scripting How-To Thread

            Would it be out of the question to add the action to the MTVR itself? That way everyone nearby would automatically see the action.

            Comment


            • #7
              Re: The Scripting How-To Thread

              Fun with carpet bombing...

              Code:
              if (isServer) then
              {
              
              	_bombStart = getMarkerPos (_this select 0);
              	_bombEnd = getMarkerPos (_this select 1);
              	_bombs = _this select 2;
              	_type = _this select 3;
              	_spread = _this select 4;
              	_sleep = _this select 5;
              
              	_Z = (_bombStart select 2) + 50;
              
              	_vector = [(_bombEnd select 0) - (_bombStart select 0), (_bombEnd select 1) - (_bombStart select 1)];
              
              	_vectorLength = (sqrt (((_vector select 0) * (_vector select 0)) + ((_vector select 1) * (_vector select 1))));
              
              	_unitVector = [(_vector select 0) / _vectorLength, (_vector select 1) / _vectorLength];
              	_vector = [(_vector select 0) / _bombs, (_vector select 1) / _bombs];
              	_vectorPerp = [_unitVector select 1, (_unitVector select 0) * -1];
              
              	for [{_x = 1},{_x <= _bombs},{_x = _x + 1}] do
              	{
              		null = _type createVehicle [(_bombStart select 0) + (_x * (_vector select 0)) + (_spread * (_vectorPerp select 0)), (_bombStart select 1) + (_x * (_vector select 1)) + (_spread * (_vectorPerp select 1)), _z];	
              		null = _type createVehicle [(_bombStart select 0) + (_x * (_vector select 0)) + (_spread * (_vectorPerp select 0)), (_bombStart select 1) + (_x * (_vector select 1)) - (_spread * (_vectorPerp select 1)), _z];	
              		sleep _sleep;
              	};
              
              };
              call it somewhere with this:

              Code:
              null = ["CarpetBombStart", "CarpetBombEnd", 10, "Bo_GBU12_LGB", 10, 0.5] execVM "carpetBombing.sqf";
              Parameter List:
              1 - Starting Marker
              2 - Ending Marker
              3 - # of Bombs
              4 - Type of Bomb
              5 - Bomb spread
              6 - Sleep between bombs

              If you wanted to get really fancy you could do something like this on a radio call:

              Code:
              onMapSingleClick "'CarpetBombStart' setMarkerPos _pos; onMapSingleClick """";";
              Just be sure to put another call for the ending location (or put it in there with the next onMapSingleClick). Then call your bombing run.

              Im going to fool around with this some more, probably have an A10 do the bombing. But for now it works fairly well.
              Last edited by DLBlue; 07-15-2009, 03:58 PM.
              ---Bellicosity---

              Comment


              • #8
                Re: The Scripting How-To Thread

                Originally posted by Fincuan View Post
                Would it be out of the question to add the action to the MTVR itself? That way everyone nearby would automatically see the action.
                I suppose I can but the MTVR is composed by a script right when the mission starts. It is not actually in the editor. However, I can delete the MTVR vehicle in the composition and just add it in through the editor. The only problem is that I only want certain playable units to be able to have that action when near the MTVR.


                IN GAME ARMA: |TG-Irr| Lq.Snake

                Comment


                • #9
                  Re: The Scripting How-To Thread

                  Ah copy that. You could add a check into the sandbag building script that only allows certain units to use it. Everyone would thus get the action, but only the units you want would be able to do anything with it. The unit who has used the action is passed as an argument to the called script, see more here: http://community.bistudio.com/wiki/addAction

                  An array of parameters is passed to the called script:
                  [target, caller, ID, (arguments)]
                  target: Object - the object which the action is assigned to
                  caller: Object - the unit that activated the action
                  ID: Integer - ID of the activated action
                  arguments: Anything - arguments given to the script if you are using the extended syntax
                  Alternatively, if you really only want to show the action to certain units you could create a trigger that is moved together with the MTVR:
                  Code:
                  _myTrigger = createTrigger ["EmptyDetector", getPos MTVR];
                  _myTrigger setTriggerArea [5,5, 0, false];
                  _myTrigger setTriggerActivation ["WEST", "PRESENT", true];
                  _myTrigger setTriggerStatements [
                  				"this && (**INSERT CONDITION HERE FOR THOSE WHO CAN USE THIS**) && local player",
                  				"sandbagAction = player addAction ['Deploy sandbag', 'deploySand.sqf', [], 5, true, true, ''];",
                  				"player removeAction sandbagAction;"
                  				];
                  This trigger should add an action the any west unit who enters it and is authorized to have the action as per your condition, and then remove the action should the unit leave the trigger's activation area. It's untested but should work. You'll just have to setPos the trigger(does attachTo work with triggers?) at certain interval to keep it on the MTVR.

                  edit: The trigger script above should of course be run on every client.
                  Last edited by Fincuan; 07-15-2009, 06:07 PM. Reason: Formatting the code to a more readable form

                  Comment


                  • #10
                    Re: The Scripting How-To Thread

                    New question!

                    I have three separate pilots -- 2 different Huey pilots and a Harrier pilot. I want to lock each aircraft so that only the player that corresponds to that vehicle can enter. Right now, I'm using this:

                    Code:
                    if (!isServer) exitWith{};
                    
                    _vehicle = _this select 0;
                    _position = _this select 1;
                    _enterer = _this select 2;
                    
                    _enterer_name = typeOf _enterer;
                    
                    if (_position == "driver") then {
                    	if (_enterer_name != "USMC_Soldier_Pilot") then {
                    		driver _vehicle action["Eject",_vehicle];
                    	};
                    };
                    
                    if (true) exitWith {};
                    (by Xeno, modified by Lq.Snake).

                    My problem is that this script relies on the type of player (ie. classname), rather than the name of the player. This means that I can't lock the Harrier specific to the Harrier pilot, only to pilots in general!

                    Each of my pilots have a different name assigned in the editor (Huey_Pilot_1, Huey_Pilot_2, Harrier_Pilot). Ideally, I would be able to screen for these NAMES, instead of CLASSES. Is there a way to do this?

                    Comment


                    • #11
                      Re: The Scripting How-To Thread

                      Originally posted by Sc[ + ]pe View Post
                      New question!

                      I have three separate pilots -- 2 different Huey pilots and a Harrier pilot. I want to lock each aircraft so that only the player that corresponds to that vehicle can enter. Right now, I'm using this:

                      Code:
                      if (!isServer) exitWith{};
                      
                      _vehicle = _this select 0;
                      _position = _this select 1;
                      _enterer = _this select 2;
                      
                      _enterer_name = typeOf _enterer;
                      
                      if (_position == "driver") then {
                      	if (_enterer_name != "USMC_Soldier_Pilot") then {
                      		driver _vehicle action["Eject",_vehicle];
                      	};
                      };
                      
                      if (true) exitWith {};
                      (by Xeno, modified by Lq.Snake).

                      My problem is that this script relies on the type of player (ie. classname), rather than the name of the player. This means that I can't lock the Harrier specific to the Harrier pilot, only to pilots in general!

                      Each of my pilots have a different name assigned in the editor (Huey_Pilot_1, Huey_Pilot_2, Harrier_Pilot). Ideally, I would be able to screen for these NAMES, instead of CLASSES. Is there a way to do this?
                      Im not a scripter by any means but when I was experimenting with the editor, I noticed that whn you create a unit, there is a slot for you to Name it. Cant you just name the Pilot "Harrier Pilot" then in your script for the Harrier have like
                      Code:
                      if (_position == "driver") then {
                      	if (_enterer_name != "Harrier_Pilot") then {
                      		driver _vehicle action["Eject",_vehicle];
                      just a guess by me
                      |TG-Irr| Zantheus

                      Comment


                      • #12
                        Re: The Scripting How-To Thread

                        Something like this? You'll just have to make sure the in-editor vehicle and pilot names match the two arrays. Again this is untested so it might have stupid errors :)

                        Code:
                        if (!isServer) exitWith{};
                        
                        _vehicle = _this select 0;
                        _position = _this select 1;
                        _enterer = _this select 2;
                        
                        //Get the "editor names" for the vehicle and the pilot
                        _enterer_name = format["%1",_enterer];
                        _vehicle_name = format["%1",_vehicle];
                        
                        //An array of possible vehiclenames(set in editor), followed by an array of possible pilotnames(again set in editor).
                        //First pilot in the list will be able to pilot only the first vehicle, second pilot the second etc...
                        _vehicles = ["Harrier", "Huey_1", "Huey_2"];
                        _pilots = ["Harrier_pilot", "Huey_pilot_1", "Huey_pilot_2"];
                        
                        //Find pilot's and vehicles indexes in the arrays. Returns -1 if not in array.
                        _pilotindex = _pilots find _enterer_name;
                        _vehicleindex = _vehicles find _vehicle_name;
                        
                        //Make the checks.
                        if ( (_position == "driver") and (_vehicleindex >= 0) ) then
                        {
                        	//Kick pilot out if indexes don't match or index is <0
                        	if  ( (_pilotindex < 0) or (_vehicleindex != _pilotindex) ) then
                        	{
                        		driver _vehicle action["Eject",_vehicle];
                        	};
                        };
                        Last edited by Fincuan; 07-16-2009, 06:37 AM. Reason: Stupid errors...

                        Comment


                        • #13
                          Re: The Scripting How-To Thread

                          Thanks Fincuan, that looks exactly like what I was trying to do!

                          Zantheus, your method doesn't work because _enterer_name returns a class value, not a character-specific name. In fact, that's exactly what I tried when I first modified this code!!

                          EDIT: Fincuan, you're a genius. It works perfectly, and from what you've written I came up with these two vehicle-specific scripts:

                          Code:
                          if (!isServer) exitWith{};
                          
                          _vehicle = _this select 0;
                          _position = _this select 1;
                          _enterer = _this select 2;
                          
                          _enterer_name = format["%1",_enterer];
                          
                          if (_position == "driver") then
                          {
                          	if ((_enterer_name != "Huey_Pilot_1") or (_enterer_name != "Huey_Pilot_2")) then
                                  {
                          		driver _vehicle action["Eject",_vehicle];
                          	};
                          };
                          
                          if (true) exitWith {};
                          Code:
                          if (!isServer) exitWith{};
                          
                          _vehicle = _this select 0;
                          _position = _this select 1;
                          _enterer = _this select 2;
                          
                          _enterer_name = format["%1",_enterer];
                          
                          if (_position == "driver") then
                          {
                          	if (_enterer_name != "Harrier_Pilot") then
                                  {
                          		driver _vehicle action["Eject",_vehicle];
                          	};
                          };
                          
                          if (true) exitWith {};
                          I decided to do it this way because although your code works elegantly, it also rules out the possibility of multiple players have the option of driving the same vehicle (in this case, I want both UH-1Y pilots to be able to fly either bird). In order to do that in an array, I need something complicated like this:

                          Code:
                          if (!isServer) exitWith{};
                          
                          _vehicle = _this select 0;
                          _position = _this select 1;
                          _enterer = _this select 2;
                          
                          //Get the "editor names" for the vehicle and the pilot
                          _enterer_name = format["%1",_enterer];
                          _vehicle_name = format["%1",_vehicle];
                          
                          //An array of possible vehicle names (set in editor), followed by an array of possible pilot names (again set in editor)
                          //First pilot in the list will be able to pilot only the first vehicle, second pilot the second etc.
                          _vehicles = ["Huey_1", "Huey_2", "Harrier"];
                          _pilots = ["Huey_Pilot_1", "Huey_Pilot_2", "Harrier_Pilot"];
                          
                          //Find pilot's and vehicles indexes in the arrays. Returns -1 if not in array
                          _pilotindex = _pilots find _enterer_name;
                          _vehicleindex = _vehicles find _vehicle_name;
                          
                          //Make the checks
                          if ( (_position == "driver") and (_vehicleindex >= 0) ) then
                          {
                          	//Kick pilot out if indexes don't match or index is <0
                          	if  (_pilotindex < 0) then
                          	{
                          		driver _vehicle action["Eject",_vehicle];
                          	};
                          	if ((_pilotindex == 0) or (_pilotindex == 1)) then
                          	{
                          		if(_vehicleindex == 2) then
                          		{
                          			driver _vehicle action["Eject",_vehicle];
                          		};
                          	};
                          	if(_pilotindex == 2) then
                          	{
                          		if((_vehicleindex == 0) or (_vehicleindex == 1)) then
                          		{
                          			driver _vehicle action["Eject",_vehicle];
                          		};
                          	};
                          };
                          I figure that separating each vehicle into a script of its own will avoid confusion, and save me from checking my array each time I want to add a new vehicle type. This way, each vehicle can be muddled with individually!

                          Thanks for the help. This thing has been bugging me for hours!



                          EDIT#2: Another new question. I want to replace the default "Eject" action on certain aircraft with the HALO_getout "Eject" action. IE, if a player is in the right aircraft and hits "Eject", they will HALO instead of insta-parachute deployment. Originally, I accomplished this by:

                          Code:
                          this addaction ["HALO","halojump.sqf"];
                          Code:
                          player action [ "eject", VEHICLENAME];
                          player setvelocity [0,0,0];
                          [player] exec "ca\air2\halo\data\Scripts\HALO_getout.sqs";

                          However, this gives the undesired result of having an additional action menu item. Instead, I'd rather just replace the Eject action altogether on certain aircraft. Is there a way to do this? I thought it would be thru an eventHandler, but I couldn't get it to jive.
                          Last edited by Sc[ + ]pe; 07-16-2009, 09:33 AM.

                          Comment


                          • #14
                            Re: The Scripting How-To Thread

                            I have a quick question about testing scripts. Do the script files get loaded by ArmA2 on preview? As in does the mission you're editing have to be reloaded every time you make a change in one of your script files or does it pick up those changes when you preview the mission?

                            Comment


                            • #15
                              Re: The Scripting How-To Thread

                              I think I read somewhere that the script gets compiled each time its called so theoretically you wouldn't even have to repreview the mission to see a change in the script but I always do it anyways (preview it again).
                              ---Bellicosity---

                              Comment

                              Connect

                              Collapse

                              TeamSpeak 3 Server

                              Collapse

                              Advertisement

                              Collapse

                              Twitter Feed

                              Collapse

                              Working...
                              X