Announcement

Collapse
No announcement yet.

Move and Shoot Range - Script from Video Tutorial

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

  • Move and Shoot Range - Script from Video Tutorial

    Here is the script from the Move and Shoot range for the video tutorial on setting up a target range that is editable and configurable via Zues. It works in multiplayer on a dedicated server too.

    This script is started by an addAction placed on an object within the editor:

    Code:
    this addAction ["Start Move and Target Range", "moveAndShootRange.sqf"];
    moveAndShootRange.sqf
    Code:
    //first check if the course is active -----------------------------------------------------------------------
    if !(moveAndShootRangeActive == "false") exitWith {hint format ["%1 is already is active in the range. Please wait.", moveAndShootRangeActive];};
    
    nopop = true;
    moveAndShootRangeActive = name player;
    _myName = name player;
    publicVariable "moveAndShootRangeActive";
    allMsTargets = [msTarget1,msTarget2,msTarget3,msTarget41,msTarget4  2,msTarget43];
    msFourTargetPatterns = [[msTarget41,msTarget42,msTarget43],[msTarget41,msTarget43,msTarget42],[msTarget42,msTarget41,msTarget43],[msTarget42,msTarget43,msTarget41],[msTarget43,msTarget41,msTarget42],[msTarget43,msTarget42,msTarget41]];
    nextTarget = "target1";
    playerStartMoveAndShootTime = 0;
    _cleanUp = false;
    player setVariable ["quitMoveAndShootDrill",false];
    _targetsStatus = 0;
    _displayClearCourseMessage = false;
    
    //broadcast that the range is active by whom to except the active player (add and exception if the player is the server)--------------------
    mssg = format ["%1 is active in the Move And Target Range", moveAndShootRangeActive];
    mssg remoteExec ["hint",0,false];
    
    //set all targets in the range to be down ----------------------------------------------------------------------
    {
        _x animate ["terc",1];
        _x setVariable ["targetStatus","down"];
    }forEach allMsTargets;
    
    //add and option to quit the drill --------------------------------------------------------------------------------------------
    quitMsAction = -88;
    quitMsAction = player addAction ["<t color='#FF0000'>QUIT MOVE AND TARGET DRILL</t>", {player setVariable ["quitMoveAndShootDrill", true]}];
    
    //begin a loop to monitor targets to pop up and be hit ---------------------------------------------------------------------------
    while {moveAndShootRangeActive == _myName} do
    {
        if (player distance startMoveAndShootDrillPen <= 2 && playerStartMoveAndShootTime < 0.5) then
        {
            //start the drill timer
            playerStartMoveAndShootTime = time;
            hint "Go!";
        };
    
        if (nextTarget == "target1" && player distance msTargetOnePen <=2) then
        {
            hint "Shoot from this position.";
            msTarget1 setVariable ["targetStatus", "up"];
            [msTarget1,["Hit",{msTarget1 setVariable ["targetStatus","hit",true]}]] remoteExec ["addEventHandler",2,false];
            sleep .8;
            msTarget1 animate ["terc",0];
            nextTarget = "target2";        
        };
    
        if (nextTarget == "target2" && player distance msTargetTwoPen <=2) then
        {
            hint "Shoot from this position.";
            msTarget2 setVariable ["targetStatus", "up"];
            [msTarget2,["Hit",{msTarget2 setVariable ["targetStatus","hit",true]}]] remoteExec ["addEventHandler",2,false];
            sleep .8;
            msTarget2 animate ["terc",0];
            nextTarget = "target3";        
        };
    
        if (nextTarget == "target3" && player distance msTargetThreePen <=2) then
        {
            hint "Shoot from this position.";
            msTarget3 setVariable ["targetStatus", "up"];
            [msTarget3,["Hit",{msTarget3 setVariable ["targetStatus","hit",true]}]] remoteExec ["addEventHandler",2,false];
            sleep .5;
            msTarget3 animate ["terc",0];
            nextTarget = "targets4";        
        };
    
        if (nextTarget == "targets4" && player distance msTargetFourPen <=2) then
        {
            hint "Shoot from this position.";
            targetsActualPattern = msfourTargetPatterns select (floor random (count msfourTargetPatterns));
            msTarget41 setVariable ["targetStatus", "up"];
            [msTarget41,["Hit",{msTarget41 setVariable ["targetStatus","hit",true]}]] remoteExec ["addEventHandler",2,false];
            msTarget42 setVariable ["targetStatus", "up"];
            [msTarget42,["Hit",{msTarget42 setVariable ["targetStatus","hit",true]}]] remoteExec ["addEventHandler",2,false];
            msTarget43 setVariable ["targetStatus", "up"];
            [msTarget43,["Hit",{msTarget43 setVariable ["targetStatus","hit",true]}]] remoteExec ["addEventHandler",2,false];
            sleep .5;
            {
                _x animate ["terc",0];
                sleep 1.8;
            }forEach targetsActualPattern;        
            nextTarget = "targetsCompleted";
            _displayClearCourseMessage = true;
        };
    
        //check if all targets have been hit -------------------------------------------------------------------
        if (nextTarget == "targetsCompleted") then
        {
            _targetsStatus = 0;
            {
                if (_x getVariable "targetStatus" == "hit") then {_targetsStatus = _targetsStatus + 1;};
            }forEach allMsTargets;
        };
    
        //check if targets hit --------------------------------------------------------------------
        if (_targetsStatus > 5 ) then
        {
            // display hint if last targets are down to move to the end of the course
            if (_displayClearCourseMessage) then
            {
                hint "Target Down! Clear the course to complete.";
                _displayClearCourseMessage = false;
            };
    
            // trigger the script clean up and broadcast the results to all players
            if (player distance finishMoveAndShootDrillPen <= 2) then
            {
                _cleanUp = true;
                mssg = format ["%1 completed the course in %2 seconds!", moveAndShootRangeActive, time - playerStartMoveAndShootTime];
                mssg remoteExec ["hint",0,false];        
            };
        };
    
        //check if player has quit --------------------------------------------------------------------------
        if (player getVariable "quitMoveAndShootDrill") then
        {
            _cleanUp = true;
            mssg = format ["%1 has quit the Move And Target Drill.", moveAndShootRangeActive];
            mssg remoteExec ["hint",0,false];
        };
    
        //cleanUp -----------------------------------------------------------------------------------------
        if (_cleanUp) then
        {
            moveAndShootRangeActive = "false";
            publicVariable "moveAndShootRangeActive";
            sleep .5;
            {
                _x animate ["terc",0];
                _x setVariable ["targetStatus","auto",true];
                [_x,"Hit"] remoteExec ["removeAllEventHandlers",2,false];
            }forEach allMsTargets;
            playerStartMoveAndShootTime = 0;
            nextTarget = "rangeCleared";
            player removeAction quitMsAction;
            noPop = false;
        };
    
    };
    Here is the mission file from the Steam Workshop:
    http://steamcommunity.com/sharedfile.../?id=812101189

    Credit: Thanks to DMZ Scout for creating the original mission. I've removed all of his work except for the arsenal and players so I'm not sharing work that wasn't mine.

    Last edited by Unkl; 12-04-2016, 06:57 AM.
    |TG-189th| Unkl
    ArmA 3 Game Officer
    Dean of Tactical Gamer University
    189th Infantry Brigade Member

    SUBMIT A RIBBON NOMINATION OR CONTACT AN ARMA ADMIN

  • #2
    Good work Unkl!

    Comment


    • #3
      Ok so, how could one add a script to track hits vs misses to this? Virtual 3 Gun match anyone?!
      May God have mercy upon my enemies, because I won’t.
      -- Gen. George S. Patton


      |TG189th| Cody

      Comment


      • #4
        https://community.bistudio.com/wiki/...dlers#FiredMan

        You would put this event handler on the player that is active in the course and then within it use a variable to keep track of how many times that player fired. In this course there are only 5 targets to hit and thus you could wait until the end when all targets must be down and then do the math then.
        |TG-189th| Unkl
        ArmA 3 Game Officer
        Dean of Tactical Gamer University
        189th Infantry Brigade Member

        SUBMIT A RIBBON NOMINATION OR CONTACT AN ARMA ADMIN

        Comment


        • #5
          Note: edited original post with link to the mission files. You TG types can get the full mission from the server.
          |TG-189th| Unkl
          ArmA 3 Game Officer
          Dean of Tactical Gamer University
          189th Infantry Brigade Member

          SUBMIT A RIBBON NOMINATION OR CONTACT AN ARMA ADMIN

          Comment

          Connect

          Collapse

          TeamSpeak 3 Server

          Collapse

          Advertisement

          Collapse

          Twitter Feed

          Collapse

          Working...
          X