Here's a nice little script to have a unit of choice chase a target unit and detonate itself with a big bang once it gets close enough. The chase uses a lead pursuit algorithm so the suicide bomber will effectively attempt to intercept a moving target if his speed allows it. The suicide bomber will also explode when his patience runs out (tmeout) or when killed. The blast is powerful enough to take out a T-80.
Most straightforward use is simple - set up a trigger to activate "on detected", and call the script from there with as first argument the "suicide bomber" unit (works best with civilian men or vehicles), and as a second the target - i.e. the unit that activated the trigger ( list <triggername> select 0).
Comments/improvements welcome... Â Enjoy :-)
Johan.
;--------------------------------------------------------------------------------------
;
; Suicide Bomber script for Operation Flashpoint Resistance
; by Johan Van Camp
;
;--------------------------------------------------------------------------------------
; call with [bomber,(list bombertrig select 0) exec "suicidebomber.sqs"
_bomber = _this select 0
_target = _this select 1
; delay between intercept point calculations
_delay = 2
; Set a timeout counter to avoid this script running eternally
_c = 30
; Assume the bomber can run at at least speed 23 (speed of man running)
_vb = 23
; Try to make sure our bomber runs at full speed to the target and doesnt get distracted
_bomber setSpeedMode "FULL"
_bomber setBehaviour "SAFE"
#loop
_c = _c - 1
? (_c==0)||(!alive _bomber) Â : goto "end"
~_delay
; Only chase if the bomber actually sees the target
? _bomber knowsabout _target <= 1 : goto "loop"
; Here comes some applied trigonometry... Rudimentary lead pursuit algorithm to get the
; bomber to the target by calculating an intercept point based on the targets current
; heading and velocity and the bombers potential velocity
; Grab some coordinates for easy manipulation
_targpos = getpos _target
_tx= _targpos select 0
_ty= _targpos select 1
_tz= _targpos select 2
_bomberpos = getpos _bomber
_bx= _bomberpos select 0
_by= _bomberpos select 1
_bz= _bomberpos select 2
; Convert OFP angles (0 degrees = Y-axis) into standard geometric angles (0 degrees = X-axis)
; for our further calculations to keep things nice and simple
_ta= 90 - getdir _target
? _ta < 0 : _ta = _ta + 360
; calculate targets speed and distances split in x and y components
_vtx = speed _target * cos (_ta)
_vty = speed _target * sin (_ta)
_sx = _tx - _bx
_sy = _ty - _by
_s  = sqrt(_sx^2 + _sy^2)
; Check if bombers actual speed is exceeding our expectations and if so conservatively increase our assumed maximal speed
_vba = speed _bomber
? _vba > _vb : _vb = (_vba + _Vb) / 2
; Calculate the intercept angle
_oa=acos (_sx/_s)
? _sy > 0 : _oa = -_oa
_h = ((_sx*_vty)-(_sy*_vtx))/_vb
_ia = (asin (_h/_s))-_oa
; Put angle in right quadrant and clean up presentation
? (((_sx*sin(_ia))-_h)/_sy) * (cos(_ia)) < 0 : _ia = 180 - _ia
? _ia < 0 : _ia = _ia + 360
; Now we have the bombers velocity components for the intercept
_vbx = _vb * cos(_ia)
_vby = _vb * sin(_ia)
; And with this we can finally work out the actual intercept point
_t = _sx / (_vbx - _vtx)
_ix = _bx + (_vbx * _t)
_iy = _by + (_vby * _t)
; Put the current waypoint at the calculated intercept point
_bomber move [_ix,_iy,0]
; Check if were close enough to detonate - if not continue the chase
? _bomber distance _target > 10 : goto "loop"
#end
; Time to say adios muchahos - nice visual feature if our bombers a man (not a vehicle)
; wait 2 seconds to let the animation play
; _bomber playMove "EffectStandSalute"
; ~2
; And lets make a nice big explosion... create multiple bombs and detonate them
; This is enough of a blast to take out a T-80 or a full infantery squad
_c=5
_boem = []
#bombs
_boem = _boem + [("bomb" camCreate getpos _bomber)]
_c=_c-1
? _c > 0 : goto "bombs"
"_x setdamage 1" foreach _boem
; end of script