Home   Help Search Login Register  

Author Topic: UA AI Arty Script  (Read 1777 times)

0 Members and 1 Guest are viewing this topic.

Offline snafu

  • Members
  • *
UA AI Arty Script
« on: 09 Nov 2018, 19:05:16 »
Hello, all

I'm trying to use the following script for UA 1.11, but I'm getting 'Error unknown operator bool' when the AI tries to call fire.

Code: [Select]
;----------------------------------------------------------
; Easy AI Unified Artillery
;
; By General Barron
; aw_barron@hotmail.com
; 8/11/04   v1.0
;----------------------------------------------------------
;
; NOTE: THIS SCRIPT REQUIRES THE CHAIN OF COMMAND'S UNIFIED ARTILLERY ADDON
;
; This script lets the specified AI call for artillery fire automatically.
;The AI will try to call arty whenever enemies are detected. They will
;only call a strike if no friendlies are within 75 meters of the target.
;
; To adjust how many rounds are fired per strike, as well as the radio
;chatter used, go to the bottom of this script.
;
; Note that this is a simple script, and the AI won't do things like adjust
;their aimpoints. I suggest you use the "zero bias error" gamelogic with this
;script, or else the arty strikes won't be very accurate. I also suggest you
;set the skill of the artillery units to 100%.
;
;      TO USE THE SCRIPT:
;
;Place a CoC Obelisk for whichever side(s) will be using the artillery.
;
;Place the following files in your mission directory:
;   ai_arty_ua.sqs
;   findUnits.sqf
;   knownUnits.sqf
;
;Place these lines in your init.sqs:
;   knownUnits = preprocessFile "knownUnits.sqf"
;   findUnits = preprocessFile "findUnits.sqf"
;
;Place this line in the init field of each AI artillery spotter:
;   [this, "enemy array name", "friendly array name", arty group name] exec "ai_arty_ua.sqs"
;
;"enemy/friendly array name" - the name of the arrays that will be considered
;   friendly/enemy to this observer. NOTE: This is the variable name IN QUOTES.
;   Note that you could also put civilians in the friendly array, to prevent AI from
;   causing civilian casulties.
;   I suggest that you DO NOT add your artillery units to the enemy array. Doing so could cause the AI to call
;   artillery down on the opposing side's artillery, without actually seeing where it is.
;   For info on why it must be in quotes, check here: http://www.ofpec.com/editors/comref.php?letter=3#Array%20assignment
;
;arty group name - group that is in the artillery guns. MAKE SURE TO PLACE THIS GROUP BEFORE
;    PLACING OTHER UNITS. Otherwise, the group might not "exist" yet before the script is executed.
;
;EXAMPLE: Place a trigger, activation: west present. On activation: west_units = thislist
;   Place another trigger, activation: east present. On activation: east_units = thislist
;   Place a howitzer, and put this in his init field: west_arty = group this
;   Place a west soldier, and put this in his init field:
;      [this, "east_units", "west_units", west_arty] exec "ai_arty_ua.sqs"
;
;----------------------------------------------------------

_observer = _this select 0
_enemies = _this select 1
_friends = _this select 2
_arty = _this select 3

;wait for UA to initialize
~60
_Artyposture = ((leader _arty) call CoCfIFFindAsset) + "p"

#Loop
~15
;loop until enemy detected or unit is killed
? !(alive _observer) : exit
? ("Land" countType ([_observer, call _enemies, false] call knownUnits)) > 0 : goto "Next"
goto "Loop"

#Next
;go back if arty is unavailable
? (Call _ArtyPosture) > 0 : goto "Loop"
_knownEnemies = [_observer, call _enemies, true] call knownUnits
_i = 0
_max = count _knownEnemies

;loop until a target is found with no friendlies nearby
#FindTarget
     _target = _knownEnemies select _i
;    The number below (after _target) is the distance around the target that must be clear of friendlies to call the strike
;    EG: 75 means no strike can be called on that target if any friends are within 75 meters of the target.
;    This number should be increased if the arty you are using covers a larger strike area (such as MLRS)
     ?  count ([_target, 150, call _friends, false] call findUnits) == 0 AND "Land" countType [_target] == 1 : goto "CallStrike"
     _i = _i + 1
     ? _i < _max : goto "FindTarget"

;if no safe targets, wait, then go back to beginning
~60
goto "Loop"


;----------------------------------------------------------
; EDITABLE PORTION OF SCRIPT BELOW
;----------------------------------------------------------

#CallStrike

;Replace this with the text of your choosing.
;I suggest you use this function to display the actual grid coords of the strike:
; http://www.ofpec.com/editors/funcref.php?filter_func=11
_observer sidechat format ["Requesting artillery support at grid %1.", [getpos _target] call GridCoord]
_observer sidechat "Requesting artillery support!"

;The number after [getpos _target] is how many rounds each unit will fire for the strike.
;EG: Putting a '5' here will make each arty unit fire 5 rounds each time the AI calls for fire.
;Check your UA documentation for a description of the other parameters.
[_arty, [getpos _target], 3, 0, 0, 0, true] Call CoCfIFCallFire

~60
goto "Loop"
;----------------------------------------------------------

The specific error: 'scalar  |# |bool array string 0xfcffffefo': Error unknown operator bool

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: UA AI Arty Script
« Reply #1 on: 10 Nov 2018, 08:42:04 »
The oh so informative OFP error messages...  :scratch:

That can literally be anything in the script so all you can do is after each variable assignment etc. to check what it actually is :dunno:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline snafu

  • Members
  • *
Re: UA AI Arty Script
« Reply #2 on: 10 Nov 2018, 10:17:38 »
Thanks, I'll have a look this afternoon.  :good:

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: UA AI Arty Script
« Reply #3 on: 10 Nov 2018, 10:30:19 »
It can be just a typo somewhere.
BI wiki says this
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline SoldierEPilot

  • Members
  • *
Re: UA AI Arty Script
« Reply #4 on: 17 Nov 2018, 10:33:29 »
Hi!

At first, check out if you use array names rather then arrays, i.e.
Code: [Select]
Enemies = (units e1) + (units e2)"Enemies" is a proper argument for GB's script, but not Enemies!

Two ways to detect undefined vars in any script

Simple:
Code: [Select]
; place after variable assigment
hint format["%1", _var]; exit

You can also check out several vars at once:
Code: [Select]
hint format["%1", [_var, _var2, _var3]]; exit
Safe method (never crashes OFP on big arrays):
Place this line at the start of the script
Code: [Select]
is_nil = "private{_nil};_nil=true;(_this select 0)call{_nil=false};_nil"
; place after variable assigment
Code: [Select]
?[_var] call is_nil: hint "undefined variable"; exit

Offline snafu

  • Members
  • *
Re: UA AI Arty Script
« Reply #5 on: 19 Nov 2018, 21:58:01 »
The issue was that the UA artillery has to be placed first before anything else.

Thank you guys for your help.  :good: