OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: ryankaplan on 02 Jan 2006, 21:54:14
-
this is a pain in the ass when commanding ai.
all 5 of your law soldiers seem to waste 15 rockets on a truck with one soldier in it, which they miss, when you're required to fight 10 bmps in some distant enemy base.
Hold fire sort of works, but then they don't shoot rifles neither.
I'd like a script which makes ai not shoot their at AT weapons at less armoured targets. Even better, a few options in your action menu like
*Engage All*
*Engage APCs+Tanks*
*Engage air only*
*Engage none*
This script would be great, and am sure would be used in many missions, including all of mine.
-
im not sure if this would be possible but if it is i dont think it would be all that great
The way i would do it is run a script which checks for trucks and other things depending on those actions you want if you want them not to engage a truck from the script find all the trucks and cars etc and setcaptive them true (this will also mean soldiers wont fire at it but law soldiers will leave it a lone) then you run a little loop checking for a variable to be true which would be something like (engagetruck = true) then once active the truck will be setcaptive false now people will fire at the truck
It would work but may not be that great nor realistic but that way would work
And engage AIR wouldnt work unless you have AA soldiers in the squad but if you dont they wont even try to fire at it even if you tell it too using dotarget and do fire commands
Anyway thats how i would do it there maybe a better and easier way to do it
-
is there any way of detecting what an ai is targeting?
also, i know law soldiers won't engage air, i was thinking it would at least prevent AA soldiers from shooting M1A1s.
-
nope sorry i asked not too long ago if you could find out what a soldier is targetting and sadly nope no way
You can find out if a AA or AT soldier is targetting a tank/aircraft using the target Event handler not sure how it works never used it and i didnt look at it for long so im not sure if it would work in this situation
I think its realistic for an AA soldier to blast and abrams, i know i would in real life but depends how desperate the group is if theyrve got pleanty of laws then nope keep it for air but if theres no one with a law why not ;D
-
using a fired event handler,
check what weapon the unit fired,
if its a secondary weapon and the AT weapon in question is the secondary weapon,
remove the secondary weapon magazines for say 30 seconds, then give the unit them back, that way, it slows the refire rate down
You could also use the knowsabout command and tie that in with a class of vehicle. removing AT weapons from units in an array
-
I would try something along the lines of what Terox was suggesting.
1) Remove AT/AA ammo from units by way of their init line.
2) Make a trigger with side present and either a) group the trigger to the APC/Aircaft or b) use the vehicle class to activate the trigger
3) Add the appropriate ammo back the the units when either an APC or aircraft enters the trigger area. You could even add some reveal/dotarget/dofire commands to get your units to target the correct enemy units.
4) For engage all, just make a trigger activated by a radio command to return the AT/AA ammo to all/some units.
Posting from work so you are on your own as for the actual command codes/details.
Wadmann
-
if you wanted to go more extreme, you could create a new LAW addon, by just editing the config as the BIS one, there you would be able to keep it from being fired at trucks.
or option 2.
you could put all the trucks in the mission in an array and then use the DirToObj function in the ed depot to find out if the law soldiers are facing a truck(they would face the truck to aim there laws at it) , and if they are the remove their law rockets, and give them back once they are not pointed at the truck.
DirToObj
http://www.ofpec.com/editors/funcref.php?letter=D#DirToObj
-
you can also use the distance command i think its the exact same as the function not sure what the difference iis too me they both do the same thing
-
i think its the exact same as the function not sure what the difference iis too me they both do the same thing
not really, distance returns the distance between 2 objects and DirToObj returns what direction(0-360) "unit A" needs to be facing to be looking at "unit B"
distance will not work here, unless the tanks and the trucks were on different sides of the map
-
ooops sorry misread i thought it was a distance function sorry ignore my other post
But function may also come in handy though to check how far the truck is if its out of range theres no need to remove the Law soldiers laws but if its closer then you may need to remove them
-
you could put all the trucks in the mission in an array and then use the DirToObj function in the ed depot to find out if the law soldiers are facing a truck(they would face the truck to aim there laws at it) , and if they are the remove their law rockets, and give them back once they are not pointed at the truck.
I wouldn't do that as they would probably select the AT launcher, now the rockets are removed and they are pretty useless against infantry unless they switch back to primary fast enough by themselves.
-
right. i've just had a wee play with the knowsabout command. it seems loons will always fire first at the enemy they know the most about. threat assessment appears to go on too, as well as depending on which direction the loon happens to be facing, when it comes to the loon deciding what to shoot at.
(thinking while typing here...) it follows then that if you have an array of all the enemy units on the map, then go through that array checking the corresponding knowsabout level for each of your law loons, keeping the highest knowsabout level in a variable, you then know what the law loon is likely to be targetting.
stopping the law loon from firing at it is another matter entirely. removing the ammo is the only way i can think of which won't involve disabling the loon altogether. but then, how much ammo do you return to the loon when it's not a truck? you'd need to keep a record of each law loon's ammo count. that coupled with constantly checking arrays would slow the game down to a crawl i suspect.
the golden rule of flashpoint editing i have found, is when in doubt, cheat. setcaptive all of your enemy trucks from the beginning. they'll never be targetted, but then you skip over the law-wasting problem.
-
wouldn't do that as they would probably select the AT launcher, now the rockets are removed and they are pretty useless against infantry unless they switch back to primary fast enough by themselves.
you would only be removing the law rockets, not the M16 mags. And Ai dont fire there laws at infantry anyways in the first place. And even if they did fire them at infantry, the script would only remove them if they are pointing at trucks, then give them back as soon as they are not pointing at the trucks.
@Bedges
Your method is good, but then they wouldnt even fire their M16's at the trucks.
I think the easiest method would be the new law addon, it would take about 5 minutes to do and the file would be tiny to include in the zip with the mission.
-
why would they fire their m16's at a truck anyway?
-
Because the game designers programed them to.
and im sure the starter of this topic still would want the units to fire at the truck.
-
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
;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
;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