I know most of my scripting questions have to do with the question, but my old topics were lost when the forums switched. So, I decided to put this topic here, where I think most people would see it.
-----------------------
My question has to do with getting that darn shell to hit the designated target! In my script, I am trying to create a mortar attack (totally AI controlled). I have two scripts for this one big script to go. One is the actual targetting and firing; the other has to do with sending over a support group if the enemy gets too close to the Mortar platoon.
Here are my two scripts:
;MortarAI
;Init.sqs
;this script will activate the mortar attack on the selected target ;type.
_MortarArea = _this select 0
_MortLeader = _this select 1
_MortarGrp = _this select 2
_GrpWrpPnt = _this select 3
_MortSpot1 = _this select 4
_Rounds = 50
#Monitor
;Monitors trig area for target units
?(Killed1 = true): exit
MortLeader countEnemy list MortarArea
_Initial = list MortarArea
?(_Initial < 1): goto "Monitor"
_Attackees = list MortarArea
_Attackees sidechat "We're under attack! Medium mortar fire coming from the woods! Repeat: We are under attack!"
goto "Target"
#Target
?(_Rounds < 1): goto "Limbo"
?(_MortsScat = true): exit
_Targets = _Targets select _Attackees
_Target = getpos _Targets select 0
_tX = getpos _Targets select 1
_tY = getpos _Targets select 2
_firingdirection = _firingdirections select _Target
_RangeError = 2/5
_Xerror = ((_DeflectionError * sin(_firingdirection+90)) + (_RangeError * sin(_firingdirection)))
_Yerror = ((_DeflectionError * cos(_firingdirection+90)) + (_RangeError * cos(_firingdirection)))
~0.58
_Shell setpos getpos _Target
_Shell = "Mortar" CamCreate [((tX + ( Random 0.5))- Xerror), ((tY + (Random 0.5))- Yerror), 50]
_rounds = _rounds - 1
goto "EnemyDistChck"
#EnemyDistChck
_MortLeader distance _Attackees
?(_mortLeader distance _attackees <= 25): MortsScat = True; goto "GrpCall"
?(_mortLeader distance _attackees >= 25 && !50): goto "Target"
?(_mortLeader distance _attackees >= 50): goto "monitor"
#Limbo
;Makes a rearming delay. Allows some units to reassemble without being attacked for a limited time.
~(Random 60)+260
_Rounds = 50
goto "Monitor"
#GrpCall
@MortScat = True
~1.2
_CoverSmoke getpos MortLeader
_CoverSmoke = CamCreate "SmokeShell" [((Random 1.5) + 3), ((Random 1.5) + 3), 0.5]
~0.5
_CoverSmoke = CamCreate "SmokeShell" [((Random 1.5) + 3), ((Random 1.5) + 3), 0.5]
[GrpX, MortLeader, MortSpot1] exec "GrpX.sqs"
?(Killed1 = True): exit
?(Killed1 = False): goto "Reassemble"
#Reassemble
_GrpX setpos getpos _MortSpot1
_Rounds = 50
goto "Monitor"
;GrpX.sqs
;This script makes GrpX (can be any group number-- change the name of ;this script so that you can use multiple groups) appear at the Mortar ;launch site when the enemy gets too close.
_GrpX = _this select 0
_MortLeader = _this select 1
_mortSpot1 = _this select 2
#Retreat
_GrpX setpos getpos _MortLeader
group GrpX == group MortLeader
GRPX setbehaviour "Stealth"
GRPX setCombatMode "White"
GRPX setUnitpos "Down"
GrpX allowfleeing 0.9
goto "Check1"
#Check1
MortGroup = group GrpX
GrpXGroupCount = Count Units Group GrpX
?((Count Units MortGroup) <= .1 * GrpXGroupCount): Killed1 = True; exit
?((Count Units MortGroup) >= .1 * GrpXCount): goto "return"
#Return
GrpX setbehaviour "combat"
GrpX setCombatMode "RED"
GrpX setUnitPos "up"
GrpX doMove getpos mortSpot1
exit
The only error I get is that the MortScat variable isn't activated. It was activated when the enemy got too close to the mortar platoon, but it was creating an error message in the conditional command line, so I removed it.
------------
Can someone help me figure out how to get the mortar shell to hit the selected _Atackees unit? I tried making the mortar shell be somewhat innacurate by adding the (Random 0.5) into both its x and y coords.
Also, could someone check the smokeshell lines too? I think they might get the same problem later.
--------------------
Thx. I know I am getting repetetive with my questions, but I am just stupid. So, I'm going to save the correct answer onto my hardrive.
Plus, this question might help others who always ask about arty scripts.