Home   Help Search Login Register  

Author Topic: Prevent 'I'm an AI, and will launch all my 4 laws at a truck' script  (Read 3392 times)

0 Members and 1 Guest are viewing this topic.

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Here is a set of scripts that might help.  They are untested, so there may be some bugs, but the general idea should work.

First, in the init feild of your player unit put: this addaction ["Hold AT Fire", "holdATfire.sqs"]

Then put these two script in your mission folder (one holds AT/AA fire, the other resume AT/AA fire). The unit's other weapons will be undisturbed.  It works by temporarilly removing your AT/AA units AT and/or AT magazine but stores those in an array.  When you see some tanks or aircraft that you want them to attack, you can use the action Commence AT Fire (which is added to your player after you select Hold AT fire). The AT/AA magazines stored in the array along with the unit they belong to are then given back to the AT/AA units and they will then use their AT/AA weapons.

*** 28/08/06 I messed up on this script. If a unit has a weapon removed (_u removeWeapon _w), it does not automatically cause the associated magazines to be removed. The script below is corrected to account for my previous blunder. ***

Hold AT Fire Script
Code: [Select]
;holdATfire.sqs by Raptorsaurus

_lead = _this select 0
_doer = _this select 1
_id = _this select 2

? _lead != _doer : exit

_lead removeAction _id

ATpool = []

;these are standard BIS AT and AA magazine names, addon AT & AA magazine names can be added to this list
;the strings in this list are CASE SENSATIVE.
_ATs = ["LAWLauncher", "CarlGustavLauncher", "AALauncher", "RPGLauncher", "AT4Launcher", "9K32Launcher"]

;make array of units in players group, but do not include player (since he can control when he uses his AT/AA weapons)
_units = (units group _lead) - [player]

;find all the units that have AT/AA weapons, remove their AT/AA magazines, but store in an array to add them back when desired
_cnt = 0
#loop
_u = _units select _cnt
_allmags = magazines _u
;if the unit has _AT mags, then remove his AT magazines and add the magazines to the array _ATmags
_ATmags = []
{if (_x in _ATs) then {_u removeMagzine _x; _ATmags = _ATmags + [_x]}} forEach _allmags
;now if the unit had AT magazines put unit and his list of AT or AA magazines in the ATpool (this is an array of arrays)
? count _ATmags > 0 : ATpool = ATpool + [[_u, _ATmags]]
_cnt = _cnt + 1
~ .01
? _cnt < count _units : goto "loop"

_lead addAction ["Commence AT Fire", "commenceATfire.sqs"]
exit

Commence AT Fire Script
Code: [Select]
;commenceATfire.sqs by Raptorsaurus

_lead = _this select 0
_doer = _this select 1
_id = _this select 2

? _lead != _doer : exit

_lead removeAction _id

;make array of units in players group, but do not include player (since he can control when he uses his AT/AA weapons)
_units = (units group _lead) - [player]

;give AT or AA magazines back to units that had them removed

_cnt = 0
#loop
_u = (ATpool select _cnt) select 0
_ATmags = (ATpool select _cnt) select 1
_w = secondaryWeapon _u
;remove his weapon temporarilly so that he will not have to reload it when the magazines are added
_u removeWeapon _w
{_u addMagazine _x} forEach _ATmags
;give his weapon back (it will now be loaded)
_u addWeapon _w
_cnt = _cnt + 1
~ .01
? _cnt < count ATpool : goto "loop"

_lead addAction ["Hold AT Fire", "holdATfire.sqs"]
exit
« Last Edit: 28 Aug 2006, 23:59:59 by Raptorsaurus »