Forum Jump :

Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#1 Posted at 2014-07-18 19:04        
     
My friend and I are trying to learn the ranks of all the units in a mission, as a part of a bigger project. I have this code that I'm not even sure if it's working, kinda asked the question in a note in the script but it makes more sense like that. Hopefully it's a small thing that I'm missing, all the "Magical _x" and the arrays make it too complicated for me :'( . Also if there is a more efficient way of doing this can somebody point me in the right direction?

{	_rank = rank _x;
	if (_rank == "PRIVATE") then {
		/*Example code: _x removeWeaponGlobal "Laserdesignator"; Will that "_x" work for all the privates?
		For example can I give ALL the corporals a berret and ALL the privates a helmet with this script?
		*/
	};
	if (_rank == "CORPORAL") then {
		//Example code: hint format["Hello Corporal %1",_x]
	};
	if (_rank == "SERGEANT") then {
		//Example code: hint format["Hello Sergeant %1",_x]
	};
	if (_rank == "LIEUTENANT") then {
		//Example code: hint format["Hello Lieutenant %1",_x]
	};
	if (_rank == "CAPTAIN") then {
		//Example code: hint format["Hello Captain %1",_x]
	};
	if (_rank == "MAJOR") then {
		//Example code: hint format["Hello Major %1",_x]
	};
	if (_rank == "COLONEL") then {
		//Example code: hint format["Hello Colonel %1",_x]
	};
} forEach allUnits;

This post was edited by 654wak654 (2014-07-18 19:28, ago)

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 1484
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#2 Posted at 2014-07-18 20:07        
     
Not quite that simple as just using rank with all units will give civillains and all sides with that rank the same weapons.
It would also try and give vehicles with that rank the same equipment.


Also rather than use a list of IF statements it would be better to use switch/case as when it finds a true result it doesn't terminates the search.


{	_rank = rank _x;
if (_x iskindOf "man" and side _x == West) then {) then {// exclude vehicles and crew and limit to West side


switch _rank  do {

      case "PRIVATE" : {
		/*Example code: _x removeWeaponGlobal "Laserdesignator"; Will that "_x" work for all the privates?
		For example can I give ALL the corporals a berret and ALL the privates a helmet with this script?
		*/
		_x setdamage 1;
	};
	
	case  "CORPORAL" : {
		//Example code: hint format["Hello Corporal %1",_x]
	};
	
	case "SERGEANT" : {
		//Example code: hint format["Hello Sergeant %1",_x]
	};
	
	case "LIEUTENANT" : {
		//Example code: hint format["Hello Lieutenant %1",_x]
	};
	
	case "CAPTAIN" : {
		//Example code: hint format["Hello Captain %1",_x]
	};
	
	case "MAJOR" : {
		//Example code: hint format["Hello Major %1",_x]
	};
	case "COLONEL" : {
		//Example code: hint format["Hello Colonel %1",_x]
	};
 };// end case	
};// end if
} forEach allunits;


Advertisement


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#3 Posted at 2014-07-18 20:31        
     
Should I switch this
if (_x iskindOf "man" and side _x == West) then {) then {
With this :P
if (_x iskindOf "man" and side _x == West) then {

Other than that:
It would be really hard to express myself if this was a face to face conversation because I'd scream like a girl or something, this is plain amazing! You solved the whole thing! I've been seeing your and kylania' s work all over the internet for 6 months when learning things. Looked around so much until I gave up and asked for help (first time) about arma stuff, and a legend helped me out. You will most definitely have credits in the finished piece of work.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 1484
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#4 Posted at 2014-07-19 00:52        
     
if (_x iskindOf "man" and side _x == West) then { correct it was typo sorry