Home   Help Search Login Register  

Author Topic: Shell Getpos  (Read 1243 times)

0 Members and 2 Guests are viewing this topic.

Offline Arctic

  • Members
  • *
  • In Utero
Shell Getpos
« on: 09 Sep 2002, 23:49:05 »
 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:
Code: [Select]
;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"



Code: [Select]
;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.

Gameer_77

  • Guest
Re:Shell Getpos
« Reply #1 on: 09 Sep 2002, 23:53:30 »
It should be @MortScat == True or @MortScat

 8)PEACE

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:Shell Getpos
« Reply #2 on: 10 Sep 2002, 00:39:28 »
hmmm... I recognize some of this.

no offense, but you've got a ton of bugs in this script.
?(Killed1 = True)
should be
?killed1

mortleader countenemy list mortararea
this is a numeric value.  you should assign a variable to it or do something.
list creates an array of units, not a numeric value

so ?_initial < 1
should be changed to
?count _initial < 1

likewise, attackees is an area of the units in mortar area.
so
it'll have to be
_attackees select 0 sidechat "..."

_targets is an undefined variable, and again _attackees is an array
so
_targets = _targets select _attackees
just won't work.
similarly, the getpos stuff down there won't work, because it's not clear what you want to target.

_Firingdirection, _RangeError and _DeflectionError are used to calculate dispersion.
_FiringDirection is the compass direction the off-map tube is supposed to be pointing (Gun-Target Line).
_RangeError is the number of meters along the firing direction that the shell will miss by
_DeflectionError is the number of meters across the firing direction.

So if I plug in a target at [10,10] and give it a firing direction of 0 (due N), a range error of 1 and a deflection error of -1, the shell will drop at [11,9]

_shell setpos getpos _target won't work the first time (beccause variable shell is undefined. In subsequent iterations (when it drops the second and so on shells), it will move the shell directly on the target, eliminating all the fancy shell-falling and shell-hitting-rooftops stuff.
Dinger/Cfit

Offline Arctic

  • Members
  • *
  • In Utero
Re:Shell Getpos
« Reply #3 on: 10 Sep 2002, 00:48:30 »
hmmm... I recognize some of this.

Yeah, I used your Xerror and Yerror command lines because I thought it would help make the rounds more "random".

Thx. I'll try and knock those blocks into place.