;Part of the Multiple 'OnMapSingleClick' Command Handler
;    v1.1     By General Barron
;
;Disables added command after a specified delay or condition is met.


;index of code
_idx = _this select 0
;time before disabling
_delay = _this select 1
;condition to disable before delay
_cond = _this select 2

;skip to time delay if no condition
? call _cond : goto "delay"


;wait for specified time to pass, or condition to be met
_t = _time + _delay
@_time >= _t || call _cond
;exit if click command was already disabled
? ((GENB_mapclicks select _idx) select 1) == 0 : exit
;run removal code based on whether timeout or condition was reached
if(_time >= _t) then {2 call ((GENB_mapclicks select _idx) select 4)} else {1 call ((GENB_mapclicks select _idx) select 4)}
;disable click code
_idx call GENB_mapclick_remove
exit


;wait specified delay if no optional condition (more efficient than @ above)
#delay
~_delay
;exit if click command was already disabled
? ((GENB_mapclicks select _idx) select 1) == 0 : exit
;run removal code
1 call ((GENB_mapclicks select _idx) select 4)
;disable click code
_idx call GENB_mapclick_remove
exit

