Jump to content
Alert23

Count All Targets in TrgArea

Recommended Posts

hi all,

i have this script so far:

SteelTargets = [Steel_Plate_F,Land_Target_Oval_Wall_Right_F,Land_Target_Oval_Wall_Left_F,Land_Target_Oval_Wall_Top_F,Land_Target_Oval_F];   
   
[] spawn {    
   
while {alive player} do {    
       
  _totalTargets = {_x in SteelTargets && !isObjectHidden _x && _x inArea ShootingRangeTrg} count SteelTargets;    
      [format ["Remaining Targets: %1", _totalTargets ],0,0,999,0,0,01] spawn BIS_fnc_dynamicText;    
  };   
};

i  placed 20  Targets in a shooting range and i want them to be displayed using the code above.

the code above throws me an error:  not defined variable _x

and the code displays: Remaining Targets: 0

can someone pls help me with this?

note: the targets have HitPart EH:

this addEventHandler ["HitPart", {  
playSound "HitPlateEffect";Target1 hideobject true;}];

so total number of Remaining Targets: should decrease if an target is hit.

Share this post


Link to post
Share on other sites

_x being undefined, means you have a undefined variable in SteelTargets.
Meaning any of these:

52 minutes ago, Alert23 said:

SteelTargets = [Steel_Plate_F,Land_Target_Oval_Wall_Right_F,Land_Target_Oval_Wall_Left_F,Land_Target_Oval_Wall_Top_F,Land_Target_Oval_F]; 

is undefined.

 

Besieds that.

 

52 minutes ago, Alert23 said:

_x in SteelTargets

that makes no sense at all, you are iterating through SteelTargets, and checking if the element inside SteelTargets is in SteelTargets, well of course it is.

 

Your variable names in SteelTargets look weird, are you sure you've set them like that in the editor?

  • Thanks 1

Share this post


Link to post
Share on other sites
4 hours ago, Dedmen said:

_x being undefined, means you have a undefined variable in SteelTargets.

4 hours ago, Dedmen said:

Your variable names in SteelTargets look weird, are you sure you've set them like that in the editor?

They are not variables they are OBJECT types. I presume OP means to count the number of targets of types left in the area, so they should be STRINGs.

Spoiler

//initPlayerLocal.sqf

_steelTargets = [ "Steel_Plate_F", "Land_Target_Oval_Wall_Right_F", "Land_Target_Oval_Wall_Left_F", "Land_Target_Oval_Wall_Top_F", "Land_Target_Oval_F" ];   

TAG_allTargets = [];
{
	_targetsByType = allMissionObjects _x select{ _x inArea ShootingRangeTrg };
	{
		_x addEventHandler[ "HitPart", {
			params[ "_target" ];
			
			playSound "HitPlateEffect";
			_target hideObjectGlobal true;
			
			TAG_allTargets = TAG_allTargets - [ _target ];
			[ format[ "Remaining Targets: %1", count TAG_allTargets ], 0, 0, 999, 0, 0, 1 ] spawn BIS_fnc_dynamicText;
		}];
	}forEach _targetsByType;
	TAG_allTargets append _targetsByType;
}forEach _steelTargets;

 

Rather than searching for target via type by using allMissionObjects you would be better off syncing them to something. Then getting them by synchronisedObjects.

Place a gameLogic and name it something like targetHolder. Select all targets in the editor and rightClick and sync to the gameLogic. Then...

Spoiler


//initPlayerLocal.sqf

_steelTargets = [ "Steel_Plate_F", "Land_Target_Oval_Wall_Right_F", "Land_Target_Oval_Wall_Left_F", "Land_Target_Oval_Wall_Top_F", "Land_Target_Oval_F" ];   

TAG_allTargets = [ targetHolder, _steelTargets, true ] call BIS_fnc_synchronizedObjects;
{
	_x addEventHandler[ "HitPart", {
		params[ "_target" ];
		
		playSound "HitPlateEffect";
		_target hideObjectGlobal true;
		
		_remainingTargets = TAG_allTargets select{ !isHidden _x };
		[ format[ "Remaining Targets: %1", count _remainingTargets ], 0, 0, 999, 0, 0, 1 ] spawn BIS_fnc_dynamicText;
	}];
}forEach TAG_allTargets;

 

 

 

  • Like 2

Share this post


Link to post
Share on other sites
20 hours ago, Dedmen said:

_x being undefined, means you have a undefined variable in SteelTargets.
Meaning any of these:

is undefined.

 

Besieds that.

 

that makes no sense at all, you are iterating through SteelTargets, and checking if the element inside SteelTargets is in SteelTargets, well of course it is.

 

Your variable names in SteelTargets look weird, are you sure you've set them like that in the editor?

thank you for that info i changed it to:

SteelTargets = [target1,target2,target3,target4,target5,target6,target7,target8,target9,target10,target11,target12,target13,target14,target15,target16,target17,target18,target19,target20];    
[] spawn {     
    
while {player inArea ShootingRangeTrg} do {     
        
   		 _totalTargets = {!isObjectHidden _x && _x inArea ShootingRangeTrg} count SteelTargets;     
        [format ["Remaining Targets %1", _totalTargets ],-0.92,-0.15,999,0,0,1] spawn BIS_fnc_dynamicText;     
  };    
};

and it works now.

 

15 hours ago, Larrow said:

They are not variables they are OBJECT types. I presume OP means to count the number of targets of types left in the area, so they should be STRINGs.

  Reveal hidden contents


//initPlayerLocal.sqf

_steelTargets = [ "Steel_Plate_F", "Land_Target_Oval_Wall_Right_F", "Land_Target_Oval_Wall_Left_F", "Land_Target_Oval_Wall_Top_F", "Land_Target_Oval_F" ];   

TAG_allTargets = [];
{
	_targetsByType = allMissionObjects _x select{ _x inArea ShootingRangeTrg };
	{
		_x addEventHandler[ "HitPart", {
			params[ "_target" ];
			
			playSound "HitPlateEffect";
			_target hideObjectGlobal true;
			
			TAG_allTargets = TAG_allTargets - [ _target ];
			[ format[ "Remaining Targets: %1", count TAG_allTargets ], 0, 0, 999, 0, 0, 1 ] spawn BIS_fnc_dynamicText;
		}];
	}forEach _targetsByType;
	TAG_allTargets append _targetsByType;
}forEach _steelTargets;

 

Rather than searching for target via type by using allMissionObjects you would be better off syncing them to something. Then getting them by synchronisedObjects.

Place a gameLogic and name it something like targetHolder. Select all targets in the editor and rightClick and sync to the gameLogic. Then...

  Reveal hidden contents



//initPlayerLocal.sqf

_steelTargets = [ "Steel_Plate_F", "Land_Target_Oval_Wall_Right_F", "Land_Target_Oval_Wall_Left_F", "Land_Target_Oval_Wall_Top_F", "Land_Target_Oval_F" ];   

TAG_allTargets = [ targetHolder, _steelTargets, true ] call BIS_fnc_synchronizedObjects;
{
	_x addEventHandler[ "HitPart", {
		params[ "_target" ];
		
		playSound "HitPlateEffect";
		_target hideObjectGlobal true;
		
		_remainingTargets = TAG_allTargets select{ !isHidden _x };
		[ format[ "Remaining Targets: %1", count _remainingTargets ], 0, 0, 999, 0, 0, 1 ] spawn BIS_fnc_dynamicText;
	}];
}forEach TAG_allTargets;

 

 

 

Thank you Larrow for this version.

will definitely use it.

 

i have another question related to this.

if i use bis_fnc_dynamicText like this i can define image or text size and also enable  shadow or disable:

TotalTargets = ["<img size='5' image='images\TotalTargets.paa' shadow='0'/>",0.861,1.064,5,0,0,1] spawn bis_fnc_dynamicText;

but i cant change it if i use bis_fnc_dynamicText in this:

[format ["Remaining Targets: %1", _totalTargets ],0.861,1.064,5,0,0,1] spawn BIS_fnc_dynamicText;

how could i add text size or enable/disable shadow to the line above ?

 

thank you in advance.

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

×