Jump to content
Martinez.E

Need help with working rifle range (Army)

Recommended Posts

have tried using multiple scripts and it never syncs up with everyone. 

 

This is the current script im using in editor and it works fine..

 

//                 How to use. 
// 1. Place a popup target and name it to pt1 
// 2. copy it 8 times and it will auto name the targets
// 3. place this line in a trigger or init  nul=[max,set,time] execVM "popup.sqf" 
// max  is the total number of targets that will popup
// set is the max number of targets that can popup per set upto a max of 3
// time is the amount of time to hit the targets before they go down

  
_maxtarg  = _this select 0;
_numtargs = _this select 1;
_skill    = _this select 2;

_targets = [pt1,pt1_1, pt1_2, pt1_3, pt1_4, pt1_5, pt1_6, pt1_7];// target names 
_many    =  count _targets; // count the number of possible targets

_inc     = 0;// keeps track of the number of popup targets triggered 
_score   = 0;// keep count of the targets hit


{_x  animate["terc",1]} forEach _targets;//puts the targets down before the start

_rnumber1=0; 
_rnumber2=0;
_rnumber3=0;

_flag1=0;
_flag2=0;

nopop=true; // sets them to stay down until triggered to popup

hint "Setting up the Range";
sleep 2;
hint "Ready";
sleep 2;


while {_inc<_maxtarg} do 
{
_rnumber1 = random _many;
_int = _rnumber1%1;
_rnumber1 = _rnumber1-_int;


// 1. Check for duplicate targets 
while {(_rnumber1 == _rnumber2) or (_rnumber1 == _rnumber3) or (_rnumber2 == _rnumber3)} do
{  
_rnumber2 = random _many;
_int = _rnumber2%1;
_rnumber2 = _rnumber2-_int;

_rnumber3 = random _many;
_int = _rnumber3%1;
_rnumber3 = _rnumber3-_int;
};
// 1. END

// 2. Set the targets that will popup
_rtarget1 = _targets select _rnumber1;
_rtarget2 = _targets select _rnumber2;
_rtarget3 = _targets select _rnumber3;
// 2. END

// 3. Popup target one always active
_rtarget1 animate["terc", 0];
_inc=_inc+1;
// 3. END

// 3a. Check to see if more than one target is required and opopup at random
// 3b. second target
If (_numtargs > 1 ) then
{
if ((random 2 > 1) and (_inc < _maxtarg)) then
{
_rtarget2 animate["terc", 0];
_inc=_inc+1;
_flag1=1;
};
};
//3b. END

//3c. Third target
If (_numtargs > 2 ) then
{
if ((random 2 < 1) and (_inc < _maxtarg)) then
{
_rtarget3 animate["terc", 0];
_inc=_inc+1;
_flag2=1;
};
};
// 3c. END
// 3a. END

// 4. Time allowed for shooting.
sleep _skill; 
// 4. END 

// 5. Check to see if targets have been hit and count the score
 if (_rtarget1 animationPhase "terc" > 0.1) then
{
		_score = _score+1;
		    };
 if ((_rtarget2 animationPhase "terc" > 0.1) and (_flag1 == 1)) then

{
		_score = _score+1;
		    };
 if ((_rtarget3 animationPhase "terc" > 0.1) and (_flag2 == 1)) then
{
		_score = _score+1;
		    };
// 4. END		    

// 5. Display Score		    
 hint format ["Targets :%1 Hit :%2",_inc,_score];
// 5. END

// 6. Reset targets down and restet flags
_rtarget1 animate["terc", 1];
_rtarget2 animate["terc", 1];
_rtarget3 animate["terc", 1];
_flag1=0;
_flag2=0;
// 6. END

sleep 2;
};
sleep 8;
hint "Session Complete";

What i need it to do though..is i need it to be able to do like 10 Prone then it needs to give a little time or have hints to say "Next 10 targets will be from the kneeling position" "Reload a magazine" etc. i need it to do this for all 3 positions (Kneeling, prone, standing)

 

Please help

Share this post


Link to post
Share on other sites

stance

hint

sleep

Arma3:_Event_Handlers#Hit

Take a look at all of these and that'll get you on the right track.

Hit for tracking he hits on the targets

sleep for waiting for 10 seconds

hint for hinting "Next 10 targets"

then stance to return the stance of the target.

Ex:

 

{
	sleep 10;
		if((stance player) isEqualTo  "STAND") then {
			hint  "You are standing!";
	sleep 10;
			hint "now, kneel and shoot those three targets";	
		
	};
};

and for the hit.

_Tar addEventHandler["Hit",{(_this select 0) setVariable["TargetHit",(true),false];}];

then to check it in a trigger or something

CONDITION:
(target_1 getVariable "TargetHit")

 

Share this post


Link to post
Share on other sites

Where, in relation to the script i posted, will all of that go? 

 

idk if its possible but id like to show each lane in the top right or in the chat so my guys can record the scores.

 

Share this post


Link to post
Share on other sites
1 minute ago, Martinez.E said:

Where, in relation to the script i posted, will all of that go? 

 

idk if its possible but id like to show each lane in the top right or in the chat so my guys can record the scores.

 

Well it really all depends on how you're executing this as well. 

Yes it is very possible to show each lane in the top right, but you're looking at more of the dialog and displays kind of stuff:

https://community.bistudio.com/wiki/Dialog_Control

Share this post


Link to post
Share on other sites
59 minutes ago, Martinez.E said:

 

idk if its possible but id like to show each lane in the top right or in the chat so my guys can record the scores.

 

What scores? simple hit or something with points to 10?

 

:don11:

Share this post


Link to post
Share on other sites

yeah something like that would be nice. the problem is i dont know how to to any of this. im sure i could be taught but i have no clue where it would go and how to run something like this.

Share this post


Link to post
Share on other sites

If you're on the way to write your custom display(s), i can give you some steps. Here is some working code for a result as video:

 

1. copy these 3 files in your mission file (where mission.sqm is):

https://www.dropbox.com/sh/f356vqjaz51dqzf/AAC43TgpErRTb0X9eFBP196ka?dl=0

 

- target_LR.paa is the picture of the displayed target;

 

- description.ext is at idle, just to define some display resources which inherit of RscPicture class. One target picture (paa above) 5 icons for dot impacts on target.

I limited the number of impacts up to 5, then the 6th override the 1st. You can add some rscPictures if you want more impacts. Increment the idc (control id number) and modify also in the code below if you want to display something!

 

- defines.hpp is my standard classes for custom displays like box, text, frame and pictures. More explanations here if you want to dig.

 

Now, back to editor. A firing range is composed with:

- one target, here a "Target_PopUp2_Moving_90deg_Acc2_F" class. Name it: tgtPopup1 (example for the codes). Add some other ones with different names if you want;

- one "ShootingPos_F" shooting position (useful to place the shooter in due position inside the trigger area);

- one trigger , say popTrg1 in my example. Add a trigger on each shooting position and name it accordingly. Triggers must be anyplayer present, server only, repeatable.

on condition: this

on activation:

0 = [thisTrigger,thislist,tgtPopup1] spawn {
  params ["_trg","_shooters","_tgt"];
  _shooter = _shooters select 0;
  _EHid = str(_this select 2);
  hint "open fire when ready";
  12345 cutRsc ["cardboardTarget","PLAIN",0.2,false];
  [_EHid, "onEachFrame", {
    _shooter = _this select 0;
    _tgt = _this select 1;
    _tgt_drawing = (uiNameSpace getVariable "popupboard") displayCtrl 300;
    _tgt_drawing  ctrlSetText "target_LR.paa";
    _tgt_drawing  ctrlSetPosition [0.424  * safezoneW + safezoneX, 0.73* safezoneH + safezoneY, 0.15 * safezoneW, 0.15 * safezoneH * 1.77778];
    _tgt_drawing  ctrlSetTextColor [1,1,1,1];
    _tgt_drawing  ctrlCommit 0;
   _impact1 = (uiNameSpace getVariable "popupboard") displayCtrl 301;
   _impact2 = (uiNameSpace getVariable "popupboard") displayCtrl 302;
   _impact3 = (uiNameSpace getVariable "popupboard") displayCtrl 303;
   _impact4 = (uiNameSpace getVariable "popupboard") displayCtrl 304;
   _impact5 = (uiNameSpace getVariable "popupboard") displayCtrl 305;
   _impacts = [_impact1,_impact2,_impact3,_impact4,_impact5];
 
   {_x ctrlSetText "A3\ui_f\data\map\VehicleIcons\iconexplosiveat_ca.paa"; _x ctrlSetTextColor [0,0,0,0]} forEach _impacts;
   if (_shooter getVariable ["shots",0] >0) then {
     _impact_nbr = (_shooter getVariable "shots") - 1;
     for "_i" from 0 to ((_impact_nbr) mod 5)  do {
       _impacts select (_i mod 5) ctrlSetPosition [(0.494 - (_tgt getVariable "results" select (_impact_nbr -_i) select 0))  * safezoneW + safezoneX, (0.854 - (_tgt getVariable "results" select (_impact_nbr -_i) select 1)) * safezoneH + safezoneY, 0.01 * safezoneW, 0.01 * safezoneH * 1.77778];
       _impacts select (_i mod 5) ctrlSetTextColor [1,1,1,1];
       _impacts select (_i mod 5) ctrlCommit 0;
     };
    }
  },[_shooter,_tgt]] call BIS_fnc_addStackedEventHandler;
  waitUntil {sleep 0.5; !triggerActivated _trg};
  12345 cutRsc ["default","PLAIN",0.2];
  hint parsetext "<t>End of serial<br/>Check safety<t/>";
  _shooter setVariable ["shots",0];
  [_EHid, "onEachFrame"] call BIS_fnc_removeStackedEventHandler;
};

 

As you can see, this trigger, named popTrg1, refers to one target, named tgtPopup1. If you need to copy/paste, mind the target's name at first line.

 

Last step, add this code in init field of the target tgtPopup1:

 

if (isServer) then {
  this setVectorUp [0,0,1];
  this setVariable ["results",[]];
  this setVariable ["nopop",true,true];
  this animate ["terc",1];
  this addEventHandler ["hitpart", {
    _this spawn {
      _dX_impact = 0;
      _dZ_impact = 0;
      _tgt = _this select 0 select 0;
      _shooter = _this select 0 select 1;
      _coord_impact = _this select 0 select 3;
      _shooter setVariable ["shots",(_shooter getvariable ["shots",0]) + 1];
      _center_tgt = (getposasl _tgt) vectorAdd [0.138,-0.04,1.03];
      _center_X = [_center_tgt select 0, _center_tgt select 1, 0];
      _impact_X = [_coord_impact select 0, _coord_impact select 1, 0];
      _vector_impact_hor = _impact_X vectorDiff _center_X;
      _vector_dir_hor = [- ((vectorDir _tgt) select 1), (vectorDir _tgt) select 0, 0];
      _sign = (_vector_impact_hor vectorDotProduct _vector_dir_hor)/abs (_vector_impact_hor vectorDotProduct _vector_dir_hor);
      _dX_impact = 0.22 * (_coord_impact distance2D _center_tgt) * _sign;
      _dZ_impact = 0.39 * ((_coord_impact select 2) -  ((_center_tgt select 2)));
      (_tgt getVariable "results") pushback [_dX_impact,_dZ_impact];
      hint parsetext format ["<t size='1.30' font='PuristaMedium' color='#ffffff'>shots<br/><t size='1' align='left'>%1<br/>%2<br/><br/>Hits: %3<br/>Distance to tgt: %4 m<br/>last impact acc: %5 cm<br/>",toLower (rank _shooter), name _shooter,player getVariable "shots",round (player distance _tgt),round (100 * (_coord_impact distance _center_tgt))];
    }
  }];
  this spawn {
    while {true} do {
      if (triggerActivated popTrg1) then {
        waitUntil {_this animationPhase "terc" >0.5};
        sleep (4 + random 4);
        _this animate ["terc",0];
        waitUntil {_this animationPhase "terc" <0.5};
        sleep (2 + random 2);
        _this animate ["terc",1];
      } else {
        if (_this animationPhase "terc" !=1) then  {_this animate ["terc",1]};
 
      };
      sleep 0.5;
    };
  };

This code refers once to the trigger popTgr1. can you find the line? Good, you can add this code in some other init field of targets but change the trigger name. One target code, one trigger area code.

 

I can answer to your questions and comments. I hope this works fine. Not tested in MP so far. But should work.

You'll have to adjust the positions of impacts, slightly modifying the ctrlSetPosition in the loop for impacts, in first script. (present referring values: 0.494 for x, ,0.854 for y on screen).

Have fun!

 

 

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×