Greetings,
Hope you dont mind me starting off with a question about Sefe's guided missile script.
By chance i found the script posted on the official ofp forums, with little information on how to set it up.
So i got the script and would like to use the addon Tomahawkmissile as the missile being generated by the script.
(being launched of a cruiser of shore)
the idea i have is that the script is called when an AI or a player points a Laser at a target.
Is this possible and how do i actually set this up?
Great thanks in advance.
ps: i hope Ofpec will be up soon again
**********************************************
script i found on official ofp forum's
;Guided missile script v1.1
;by SEFE
_Target = _this Select 0
_MissileType = _this Select 1
_MissilePos = _this Select 2
_MissileDir = _this Select 3
_MissileElev = _this Select 4
_LockAngle = _this Select 5
_SAM = _this Select 6
_Internal = _this Select 7
SetAccTime 1
_LockedOn = TRUE
;Create missile
_Missile = _MissileType CamCreate [_MissilePos Select 0, _MissilePos Select 1, 1000]
_Missile SetDir _MissileDir
;Create tracking object (needed to calculate the missile's barometric altitude - also used in terrain following mode) - GetPos returns the altitude AGL but SetPos expects the barometric altitude
_Tracker = "PipeBomb" CamCreate [_MissilePos Select 0, _MissilePos Select 1, 0]
~0.2
;Calculate initial missile altitude
_InitialMisAlt = (_MissilePos Select 2)
_Tracker SetPos [_MissilePos Select 0, _MissilePos Select 1, 0]
_MissileAlt = _InitialMisAlt - ((GetPos _Tracker) Select 2)
;Set initial missile position
_Missile SetPos [_MissilePos Select 0, _MissilePos Select 1, _MissileAlt]
;Get initial target altitude
_TargetPos = GetPos _Target
_Tracker SetPos [_TargetPos Select 0, _TargetPos Select 1, 0]
_TargetAlt = (_TargetPos Select 2) - ((GetPos _Tracker) Select 2)
;Get the missile's initial distance to target
_DistanceToTarget = _Missile Distance _Target
_DeltaTargDist = 0
;Init the missile's lock angle
_LockAngle = _LockAngle / 2
;Init the missile's vertical angle
? _MissileElev > 70 : _MissileElev = 70
? _MissileElev < -70 : _MissileElev = -70
;View through missile camera
? _Internal : _Missile CameraEffect["INTERNAL", "BACK"]
#CalculateTrajectory
;Get the positions and altitudes of the target and the missile
_MissilePos = GetPos _Missile
_TargetPos = GetPos _Target
_Tracker SetPos [_MissilePos Select 0, _MissilePos Select 1, 0]
_MissileAlt = (_MissilePos Select 2) - ((GetPos _Tracker) Select 2)
_Tracker SetPos [_TargetPos Select 0, _TargetPos Select 1, 0]
_OldTargetAlt = _TargetAlt
_TargetAlt = (_TargetPos Select 2) - ((GetPos _Tracker) Select 2)
;Get the missile speed
_MissileSpeed = Speed _Missile
;Get the missile's direction
_MissileDir = GetDir _Missile
;Get the missile's distance to the target
;_OldDistanceToTarget = _DistanceToTarget
;_DistanceToTarget = _Missile Distance _Target
;_DeltaTargDist = _DistanceToTarget - _OldDistanceToTarget
;Get the missile's horizontal angle to the target (using trigonometry)
_DeltaX = (_TargetPos Select 0) - (_MissilePos Select 0)
_DeltaY = (_TargetPos Select 1) - (_MissilePos Select 1)
? (_DeltaY == 0) && (_DeltaX >= 0) : _TargetAngle = 90
? (_DeltaY == 0) && (_DeltaX < 0) : _TargetAngle = 270
? _DeltaY > 0 : _TargetAngle = ATan (_DeltaX / _DeltaY)
? _DeltaY < 0 : _TargetAngle = ATan (_DeltaX / _DeltaY) + 180
? _TargetAngle < 0 : _TargetAngle = _TargetAngle + 360
;If it is an AA missile, we have to guide it to the interception point, not to the target itself (using even more trigonometry)
? not _SAM : Goto "NoDeflectionShooting"
;Calculate the deflection angle and add it to the target angle
? _MissileSpeed != 0 : _TargetAngle = _TargetAngle + ASin ((Sin ((GetDir _Target) - _TargetAngle)) * (Speed _Target) / _MissileSpeed)
#NoDeflectionShooting
;Get the horizontal angle between the missile's direction and the target
_RelTargetAngle = _TargetAngle - _MissileDir
? _RelTargetAngle > 180 : _RelTargetAngle = _RelTargetAngle - 360
? _RelTargetAngle < -180 : _RelTargetAngle = 360 - _RelTargetAngle
;Calculate the missiles horizontal angle change
_HorzDelta = _RelTargetAngle
? (_HorzDelta > 4) && _SAM : _HorzDelta = 4
? (_HorzDelta < -4) && _SAM : _HorzDelta = -4
? (_HorzDelta > 2) && not _SAM : _HorzDelta = 2
? (_HorzDelta < -2) && not _SAM : _HorzDelta = -2
;Check if the missile has lost it's horizontal lock
? (Abs _RelTargetAngle) > _LockAngle : _HorzDelta = 0; _LockedOn = FALSE
;Calculate the missile's new direction
_NewMissileDir = (GetDir _Missile) + _HorzDelta
;Roughly calculate the missile's horizontal position in the next cycle (needed to evade obstacles on the ground)
_MissileVector = _DeltaTargDist
? _MissileVector > _DistanceToTarget : _MissileVector = _DistanceToTarget
_NextMissileX = (_MissilePos Select 0) + (Sin _NewMissileDir) * _MissileVector
_NextMissileY = (_MissilePos Select 1) + (Cos _NewMissileDir) * _MissileVector
;Calculate the ground elevation at the missile's next horizontal position
_Tracker SetPos [_NextMissileX, _NextMissileY, 0]
_NextGroundElev = -((GetPos _Tracker) Select 2)
;Define vertical flight path (guess... using trigonometry)
;The flight path is calculated differently for AA and AG missiles
? not _SAM : Goto "CalcAGMissile"
;Get the missile's vertical flight angle to the target
_DeltaZ = (_TargetAlt - _MissileAlt) + 3
;An AA missile will try to reach the target altitude as quickly as possible
? (_DistanceToTarget == 0) && (_DeltaZ >= 0) : _ClimbAngle = 90
? (_DistanceToTarget == 0) && (_DeltaZ < 0) : _ClimbAngle = -90
? _DistanceToTarget != 0 : _ClimbAngle = ATan (_DeltaZ / _DistanceToTarget)
? (_DeltaZ > 40) : _ClimbAngle = 30
? (_DeltaZ > 60) : _ClimbAngle = 45
? (_DeltaZ > 80) : _ClimbAngle = 60
? (_DeltaZ < -40) : _ClimbAngle = -30
? (_DeltaZ < -60) : _ClimbAngle = -45
? (_DeltaZ < -80) : _ClimbAngle = -60
;Calculate vertical deflection
? _DeltaTargDist != 0 : _ClimbAngle = _ClimbAngle - (ATan ((_OldTargetAlt - _TargetAlt) / _DeltaTargDist))
;Avoid obstacles on the ground
_MinAltitude = 8
? _DistanceToTarget < 150 : _MinAltitude = 0
? (_TargetPos Select 2) < _MinAltitude : _MinAltitude = (_TargetPos Select 2)
_MinElev = -70
? _MissileVector != 0: _MinElev = ATan((_MinAltitude + _NextGroundElev - _MissileAlt) / _MissileVector)
? _ClimbAngle < _MinElev : _ClimbAngle = _MinElev
Goto "CalcVertAngle"
#CalcAGMissile
;An AG missile will follow the terrain until it's near the target
? _DistanceToTarget < ((_MissilePos Select 2) *
: Goto "FinalSequence"
_DeltaZ = _InitialMisAlt - (_MissilePos Select 2)
;An AG missile will try to keep it's initial height
? (_MissileVector == 0) && (_DeltaZ >= 0) : _ClimbAngle = 90
? (_MissileVector == 0) && (_DeltaZ < 0) : _ClimbAngle = -90
? _MissileVector != 0 : _ClimbAngle = ATan (_DeltaZ / _MissileVector)
? (_DeltaZ > 40) : _ClimbAngle = 30
? (_DeltaZ < -40) : _ClimbAngle = -30
;Follow terrain elevations
? _MinElev = -70
? _MissileVector != 0 : _MinElev = ATan((_InitialMisAlt + _NextGroundElev - _MissileAlt) / _MissileVector)
? _ClimbAngle < _MinElev : _ClimbAngle = _MinElev
Goto "CalcVertAngle"
#FinalSequence
_DeltaZ = (_TargetAlt - _MissileAlt) + 1
? (_DistanceToTarget == 0) && (_DeltaZ >= 0) : _ClimbAngle = 90
? (_DistanceToTarget == 0) && (_DeltaZ < 0) : _ClimbAngle = -90
? _DistanceToTarget != 0 : _ClimbAngle = ATan (_DeltaZ / _DistanceToTarget)
#CalcVertAngle
;Get the vertical angle between the missile's direction and it's vertical flight path
_RelTargetElevation = _ClimbAngle - _MissileElev
? _RelTargetElevation > 180 : _RelTargetElevation = _RelTargetElevation - 360
? _RelTargetElevation < -180 : _RelTargeElevation = 360 - _RelTargetElevation
;Calculate the missiles vertical angle change
_VertDelta = _RelTargetElevation
? _VertDelta > 4 && _SAM : _VertDelta = 4
? _VertDelta < -4 && _SAM : _VertDelta = -4
? _VertDelta > 1 && not _SAM : _VertDelta = 6
? _VertDelta < -1 && not _SAM : _VertDelta = -6
;Check if the missile has lost it's vertical lock
? (Abs _RelTargetElevation) > _LockAngle : _VertDelta = 0; _LockedOn = FALSE
;Calculate the missile's new vertical direction
_MissileElev = _MissileElev + _VertDelta
? _MissileElev > 70 : _MissileElev = 70
? _MissileElev < -70 : _MissileElev = -70
;Apply all changes to the missile's trajectory
;Change the missile's horizontal direction
_Missile SetDir _NewMissileDir
;Change the missile's altitude
_OldDistanceToTarget = _DistanceToTarget
~0.005
_MissilePos = GetPos _Missile
_DistanceToTarget = _Missile Distance _Target
_DeltaTargDist = Abs(_DistanceToTarget - _OldDistanceToTarget)
_MissileAlt = _MissileAlt + (Tan(_MissileElev) * _DeltaTargDist)
;Set the missile's new position
_Missile SetPos [_MissilePos Select 0, _MissilePos Select 1, _MissileAlt]
;Loop to next scan cycle
? (Speed _Missile > 0) : Goto "CalculateTrajectory"
;Reset cam mode
? _Internal : _Missile CameraEffect["TERMINATE", "BACK"]
;Destroy missile
CamDestroy _TrackingMissile
CamDestroy _Missile
Exit
**********************************************
;D