EDIT: this is the complete script.
Sorry for the amount of ";" lines
;Chek if the chopper is above the minimum launch altitude
? (getPos heli select 2) <20 : hint "The chooper must be at least 20 meters above the ground!"; exit
player removeaction siluro
;Check if there's a Torpedo still available
?NumSil == 0 : player sidechat "All Torpedoes fired" && exit
;Set and check the number of Torpedoes remaining
NumSil = NumSil -1
_torprem = NumSil
;Check if the player already fired a Torpedo. This select from wich side of the chopper the Torpedo will be created
? NumSil == 1 : goto "RightSide"
;Left-mounted Torpedo generated, fired and attached to a parachute
player sidechat format ["Torpedo away! %1 remains.", _torprem]
_torp = "LaserGuidedBomb" createVehicle [(getPos heli select 0)-3,(getPos heli select 1),(getPos heli select 2)-1]
_torp setDir (getDir heli)
_torp setVelocity [(velocity heli select 0)*0.2,(velocity heli select 1)*0.2,(velocity heli select 2)*0.2]
_chute = "parachute" createVehicle [(getPos _torp select 0),(getPos _torp select 1)-3,(getPos _torp select 2)-0.5]
goto "LoopChute"
;Right-mounted Torpedo generated, fired and attached to a parachute
#RightSide
player sidechat format ["Torpedo away! %1 remains.", _torprem]
_torp = "LaserGuidedBomb" createVehicle [(getPos heli select 0)+3,(getPos heli select 1),(getPos heli select 2)-1]
_torp setDir (getDir heli)
_torp setVelocity [(velocity heli select 0)*0.2,(velocity heli select 1)*0.2,(velocity heli select 2)*0.2]
_chute = "parachute" createVehicle [(getPos _torp select 0),(getPos _torp select 1)-2,(getPos _torp select 2)-0.5]
#LoopChute
_chute setpos [(getPos _torp select 0),(getPos _torp select 1)-2,(getPos _torp select 2)-0.5]
?(getpos _torp select 2) <= 3 : goto "Continue"
~0.1
goto "LoopChute"
#Continue
;The initial (and rough) probability of hitting the target, given by the distance between the Torpedo and the target....
?(_torp distance sub) >1000 : _DistPerc = 1
?(_torp distance sub) <1000 : _DistPerc = 2
?(_torp distance sub) <800 : _DistPerc = 4
?(_torp distance sub) <600 : _DistPerc = 8
?(_torp distance sub) <400 : _DistPerc = 16
?(_torp distance sub) <200 : _DistPerc = 32
;....by the position of the target to the angle of acquisition of the Torpedo's targeting system wich I set to 120 degrees....
_source = _torp
_target = sub
_sourcedir = getdir _torp
_degree = ((getpos _target select 0) - (getpos _source select 0)) atan2 ((getpos _target select 1) - (getpos _source select 1))
?_degree < 0:_degree = _degree + 360
;The better the alignement of the Torpedo respect the target the higher the chance to hit
;This simulate the time spended by the Torpedo in maneuvering for a proper alignement
_degree = _degree - _sourcedir
?_degree >= 61 : _Angleperc = 16 ; hint format ["più %1, risulta %2, atteso 16", _degree, _Angleperc]
?_degree <= 40 : _Angleperc = 18 ; hint format ["più %1, risulta %2, atteso 18", _degree, _Angleperc]
?_degree <= 20 : _Angleperc = 20 ; hint format ["più %1, risulta %2, atteso 20", _degree, _Angleperc]
;The amount of time in seconds the Torpedo need to cover the distance between itself and the target
;I've decided to set the speed of the Torpedo at 30 knots (about 72 km/h if I'm not wrong, so 20 mt/s)
~2
_speedtorp = 20
_speedsub = speed sub / 3.6
_dist = (_torp distance sub)
_timeleft = _dist / (_speedtorp - _speedsub)
hint format ["%1", _timeleft]
;Torpedo is deleted before hitting the ground
@(getpos _torp select 2) <= 2
deletevehicle _torp
deletevehicle _chute
;Set the amount of decoys the sub will launch after the Torpedo is detected.
;Every decoy launched decrease the chance to hit the target by 1%
;Decreasing _factor value, increase the "number" of decoys launched
;_subskill = skill sub
;_factor = 10
;_DecoyFactor = _subskill * (_timeleft / _factor)
;The final overall chance to hit
;_HitPerc = ToHit + ((_DistPerc + _Angleperc) - _DecoyFactor)
_HitPerc = ToHit + (_DistPerc + _Angleperc)
;The awaiting....
;player sidechat format ["%1 seconds before impact. Chances to hit: %2/100. %3 decoys launched." _timeleft, _HitPerc, _DecoyFactor]
player sidechat format ["Chances to hit: %1/100.", _HitPerc]
_count = 15
#Timer
~1
_count = _count - 1
? (_count == 0) : goto "AlmostEnd"
TitleText [format ["%1", _count], "Plain Down"]
goto "Timer"
;The final result
#AlmostEnd
;If the speed of the target is higher than the Torpedo's one, It will never reach It's target
? _speedsub >= _speedtorp : player sidechat "Target speed too high. Engagement lost."; exit
titletext [" ","Plain Down"]
_number = random 100
? _number <= _HitPerc : goto "Destroyed"
;Bad end
player sidechat format ["Target missed! %1 Torpedoes remains.", _torprem]
goto "End"
;Good End
#Destroyed
sub setdammage 1
flare = "Pipebomb" camCreate (getPos sub)
flare = "SmokeShell" camCreate (getPos sub)
~1.5
player sidechat "Impact! Target hit!"
;Now the player can try another launch
#End
siluro = player addaction ["Launch Torpedo","Torpedo.sqs"]
;script end
exit