Jump to content
Sign in to follow this  
davidoss

Function to dynamic change marker alpha

Recommended Posts

Hi.

 

Is there a way to make this smaller and smarter?

 

fnc_set_mrkalpha = {

    params ["_marker", "_players", "_defence", "_units", "_statics", "_units_cnt"];

        _players = playableUnits + switchableUnits;
    
        while {!defenced} do {
    
            sleep 10;
            
            _defence = [];
            _units = (getMarkerPos _marker) nearEntities ["Man", 150];
            _statics = (getMarkerPos _marker) nearEntities ["StaticWeapon", 150];

            {
                
                if ((side _x) isEqualTo WEST && !(_x in _players) && !(isPlayer _x)) then {
                
                
                    _defence pushback _x;
                
                };
            
            
            } forEach _units;
            
            sleep 3;
            
            _statics = _statics select {(_x emptyPositions "Gunner") == 0};
            _units_cnt = {alive _x} count (_defence + _statics);
        
                switch (true) do {
            
                    case (_units_cnt isEqualTo 8): {
                    
                        _marker setMarkerColor "colorBLUFOR";
                        _marker setMarkerAlpha ((_units_cnt*0.1) min 1);
                        
                    };
                    
                    case (!(_units_cnt isEqualTo 8) && _units_cnt > 3): {
                    
                        _marker setMarkerColor "colorBLUFOR";
                        _marker setMarkerAlpha ((_units_cnt*0.1) min 1);
                    
                    };
                    
                    case (!(_units_cnt isEqualTo 8) && _units_cnt <= 3 && !(_units_cnt isEqualTo 0)): {
                    
                        _marker setMarkerColor "colorBLUFOR";
                        _marker setMarkerAlpha ((_units_cnt*0.1) min 1);
                        reinforce = false;
                    };
                    
                    case (_units_cnt isEqualTo 0): {

                        _marker setMarkerColor "colorOPFOR";
                        _marker setMarkerAlpha 1;
                        reinforce = false;
                    
                    };        
                    
                    default { _marker setMarkerAlpha ((_units_cnt*0.1) min 1);};
                };
                
            
                if (_units_cnt <= 3 &&
                    {alive _x && (_x distance (getMarkerPos _marker)) < 200 } count _players > 0 &&
                    !reinforce) then {
                    
                    _marker spawn fnc_reinforcment;
            
                };
        };

};

Share this post


Link to post
Share on other sites

For starters, change

switch (true) do {
   case (_units_cnt isEqualTo 8): {

to

switch (_units_cnt) do {
   case 8: {

Personally, I'd do it like this

if (_units_cnt != 0) then {
	_marker setMarkerColor "colorBLUFOR";
	_marker setMarkerAlpha ((_units_cnt*0.1) max 1);
	reinforce = false;
} else {
	_marker setMarkerColor "colorOPFOR";
	_marker setMarkerAlpha 1;
	reinforce = false;	
};

Share this post


Link to post
Share on other sites

This is definitely what i am looking for but :

((_units_cnt*0.1) max 1)

return always 1 no mater which number is value of  _units_cnt variable.

Share this post


Link to post
Share on other sites

This is definitely what i am looking for but :

((_units_cnt*0.1) max 1)

return always 1 no mater which number is value of  _units_cnt variable.

You're right, it should be ((_units_cnt*0.1) min 1), stupid me.

  • Like 1

Share this post


Link to post
Share on other sites

 

linearConversion [0,8, _units_cnt,0,1, true]

That should also work.

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  

×