Jump to content
Sign in to follow this  
sabot10.5mm

help with foreach

Recommended Posts

I'm trying to get the hitpoint damage when caching every vehicle, then set the damage when vehicle spawned.  script comes up with error   _hitpnt=getHitPointDamage ;_x; is it not possible to put 2 magic variables in a foreach?

 

_dgroup select 0 is the vehicle spawned

	if (isnil "_dGrp") then {_dGrp=[];_vehdmgrp=[];_vehdam = [];};
	
		_newpos=[_mkr,50] call EOS_fnc_findSafePos;
			if (surfaceiswater _newpos) then {_vehType=8;}else{_vehType=2;};
			
					_dGroup=[_newpos,_side,_faction,_vehType]call EOS_fnc_spawnvehicle;
					
						0=[(_dGroup select 2),"ARMskill"] call eos_fnc_grouphandlers;
						0 = [(_dGroup select 2),_mkr] call EOS_fnc_taskpatrol;
							_dGrp set [count _dGrp,_dGroup];
							if !(isnil "_vehdam") then {(_dGroup select 0) setHitPointDamage (_vehdam deleteat 0);};

"_vehdam select 0"  should have all the damage to set for the command

{_vehicle = _x select 0;_crew = _x select 1;_grp = _x select 2;
	if (!alive _vehicle || {!alive _x} foreach _crew) then {_dGrps= _dGrps - 1;};	
		{deleteVehicle _x} forEach (_crew);		
			if (!(vehicle player == _vehicle)) then {{deleteVehicle _x; _hitpnt=getHitPointDamage _x; _vehdam=set[count _vehdmgrp,_hitpnt];} forEach[_vehicle];};			{deleteVehicle _x} foreach units _grp;deleteGroup _grp;
}foreach _dGrp;

 

 

Share this post


Link to post
Share on other sites

Holy indentation batman!

What exactly is

{!alive _x} foreach _crew

supposed to do inside the if statement? It returns nothing.

You need to use at least select and something to check against:

{alive _x} select _crew isEqualTo 0

 

Also later you're doing:

deleteVehicle _x; _hitpnt=getHitPointDamage _x;

You can't receive properties from an object AFTER it has been deleted.

 

Better start out small and get some solid debugging and formatting going on.

90% of what you posted has nothing to do with getting hitpoint damage and is completely unrelated to your question.

 

Also nested forEach isn't necessary and can be avoided most of the time, it's still possible like this:

_stuff = [[1,2,3],[4,5,6],[7,8,9]];

{
	_nested = _x;

	{
		systemchat str _x;
	} forEach _nested;
} forEach _stuff;

 

For your storage of hitpoint damage try this:

_savedDamage = getAllHitPointsDamage vehicle player;
hint str _savedDamage;

_newVeh = typeof vehicle player createVehicle getposatl player;

_savedDamage params ["_hitpointNames","_hitpointSelections","_hitpointDamages"];

{
	_newVeh setHitPointDamage [_hitpointNames select _forEachIndex,_x];
	if (_x > 0) then {systemchat format ["Damaged: %1",_hitpointNames select _forEachIndex]};
} forEach _hitpointDamages;

Drop a vehicle on map, hop inside, execute code.

A new vehicle will be created nearby with the same damage as the old one.

Now shoot some tires out on the new vehicle, hop inside and execute the code again, another vehicle will spawn with the same tires shot out as the one that you're currently sitting in.

You can use one nested array as a key holder to access values on the same index in other nested arrays, no need for 2 nested forEach loops here.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

yeah but 90% of the code is from EOS . just wanted to getdamage of vehicles before they are cached and set the damage when they are spawned.

these vehicles have nothing to do with player they are spawned via EOS. this is all still learning experience for me

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
Sign in to follow this  

×