Home   Help Search Login Register  

Author Topic: making AI sqauds rearm?  (Read 1431 times)

0 Members and 1 Guest are viewing this topic.

Offline ONoSixIsDown

  • Members
  • *
making AI sqauds rearm?
« on: 25 Nov 2005, 14:47:49 »
i'm looking for a way to make AI groups rearm.  I looked in the FAQ an found this.
Quote
WEAPONS / EXPLOSIONS: How to make a AI unti rearm (Beginner)

Submitted by: SFG
Credits: Tigershark

Make them reload.
--------------------------------------------------------------------------------
 


Put a few ammocrates somewhere (make them type2 crates since they allready have mines in stock) and let your minelayer walk to this (put a movewaypoint on top of a type2 ammocrate so the two are linked).
Give the waypoint a timeout of 3 or 4 seconds or so for effect.


Then in the waypoints activationfield set :


aP action["REARM"]


Where aP is the name of the minelaying player.


Ok, now youre half way.
Then add a trigger to the direct vicinity of the ammobox (very small radius, 5+5 should be enough) and in this trigger (activation "your minelayerplayers side", type switch)
put in activationfield: aP addmagazine "mine" (times 3)


then give your unit a move and cycle waypoint back to where you want him to lay mines et voila.


(if you put everything on repeat and make sure that the ammocrates get supplied with fresh mines..-their stock is limited-)
you could have yourself a soldier that mines a road so dense not even an ant could get past it.
 

 

--------------------------------------------------------------------------------
Submitted on: May 14, 2002, 00:00

I get how this works but not sure how to apply it to whole groups. would group1 action["REARM"] work?
« Last Edit: 25 Nov 2005, 14:53:14 by OhNoSixIsDown »
CRIMSON REIGN COMMING..... eventually :/

Offline Pilot

  • Contributing Member
  • **
Re:making AI sqauds rearm?
« Reply #1 on: 25 Nov 2005, 14:58:33 »
No, action only works for units.  Try this:

{_x action ["REARM]} foreach units group1

-Pilot

Offline ONoSixIsDown

  • Members
  • *
Re:making AI sqauds rearm?
« Reply #2 on: 25 Nov 2005, 15:29:01 »
i get an error message saying "Invalid number in expression" :-\
CRIMSON REIGN COMMING..... eventually :/

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:making AI sqauds rearm?
« Reply #3 on: 25 Nov 2005, 16:04:58 »
Try:

{_x action ["REARM"]} foreach units group1


There was a missing " .

However, the group will rearm without moving to the crates.
What I mean is, the ammo crates could be on the other side of the island, but the group will rearm without moving to the crate first......it's magic.    ;D

You might want to get them to move to the crate first, then issue the rearm action.


Planck
I know a little about a lot, and a lot about a little.

eko

  • Guest
Re:making AI sqauds rearm?
« Reply #4 on: 25 Nov 2005, 16:25:00 »
well if you want them to rearm only when next to the crate then just put the script in a trigger next to it

Offline ONoSixIsDown

  • Members
  • *
Re:making AI sqauds rearm?
« Reply #5 on: 25 Nov 2005, 22:46:11 »
well what i want to happen is for AI squads to pick up more ammo when they run low.  I noticed that lots of loons wont use ammo crates unless ordered by the player.  Even when their skill level is nice and high  

any ways around this?
CRIMSON REIGN COMMING..... eventually :/

LoTekK

  • Guest
Re:making AI sqauds rearm?
« Reply #6 on: 26 Nov 2005, 11:51:55 »
well what i want to happen is for AI squads to pick up more ammo when they run low.  I noticed that lots of loons wont use ammo crates unless ordered by the player.  Even when their skill level is nice and high  

any ways around this?
My first thought would be a slowly looping script that periodically checks your guys' ammo levels and sends them to the nearest ammo crate if they're below a certain threshold. However, upon further investigation, this may be a little more long-winded than I initially thought, unless I'm going about it the wrong way.

Since there doesn't appear to be a simple way to get how much ammo a unit has (aside from how many rounds in his current magazine), some loops and counters seem to be in order.

A little braindead to be writing up code, so I'll just outline. Basically, since magazines returns all magazines in a given unit's inventory, I figure you can use that to get an idea of what their ammo status is like. The array returned will list magazines in order (primary, secondary, pistols, hand grenades), so you just have to run a counter to find out how many of each type the unit has.

Of course, this approach has its limitations. You'll likely have to tailor the script to different types of units or weapons, since the threshold would be lower for a machinegunner that starts off with 3 hi cap magazines than a unit with 6 30-round magazines. This tailoring could get unwieldly.

The only completely reliable return (without doing a lot of checking against known values) would be the primary weapon, since the rest get reshuffled if a unit doesn't have a particular weapon type. So someone with a LAW Launcher and hand grenades would return ["M16","M16","Lawlauncher","Lawlauncher","handgrenade","handgrenade"], for example, while a rifleman would return ["M16","M16","handgrenade","handgrenade"]. It gets even more unwieldly when a unit has more than one primary (say, flares, or 40mm grenades).

Magazines also appears to return the last empty magazine the unit has. So if you fire off all the magazines in your pistol, it will still return one pistol mag, unless you drop the weapon (picking it up again won't add the magazine, either).

Agh. My head hurts. I'll leave my ramblings at that for now. :p

Offline ONoSixIsDown

  • Members
  • *
Re:making AI sqauds rearm?
« Reply #7 on: 27 Nov 2005, 04:08:00 »
well i've decided to make this simpler, i'm going to try to write a script like the one you mentioned that will only apply to law/rpg soldiers.  problem is that im a complete noob when it comes to scripting.  i'm going to browse the tutes and see if i cant figure it out.


CRIMSON REIGN COMMING..... eventually :/

LoTekK

  • Guest
Re:making AI sqauds rearm?
« Reply #8 on: 27 Nov 2005, 10:39:25 »
Ah, well that should be a whole lot simpler. :) Since you're only looking for a couple types of ammo, you can use countType. So let's look at your LAW soldiers for example:

Code: [Select]
"lawLauncher" countType magazines LAWguy1
will return the number of magazines of type "lawLauncher" currently held by LAWguy1 (see my previous post and note that this will return "1" even if he's fired his last LAW). If you have all your LAW soldiers assigned to an array, you can also use forEach to go through all of them. Keep this on a slow loop.

Alternatively, you can assign a "fired" eventHandler to each of your LAW/RPG guys that will decrement a counter. Though I personally reckon the above method seems a little cleaner.

Offline ONoSixIsDown

  • Members
  • *
Re:making AI sqauds rearm?
« Reply #9 on: 27 Nov 2005, 17:55:37 »
ok, i get what your saying.  i understand
"lawLauncher" countType magazines LAWguy1 but what is needed after that to make them rearm when the countType returns "1"?

also, is there a way to assign them all to an array without having them all in the same group?
CRIMSON REIGN COMMING..... eventually :/

LoTekK

  • Guest
Re:making AI sqauds rearm?
« Reply #10 on: 27 Nov 2005, 21:06:03 »
If you have only one ammobox in the area, stick a gamelogic (let's name it "ammocrate" in this example) on the ammobox's position, and give the loon(s) in question a doMove order, and when he's within a certain distance, have him rearm. If you want a never-ending supply of LAWs, we'll just add the requisite magazines to the loon. This example is going to include zero error-checking in terms of how many LAWs to grab (because I'm rather braindead right now :p), but shouldn't throw up any ugly error messages. So:

Code: [Select]
if ("lawlauncher" countType magazines lawguy > 1) then goto "end"
lawGuy doMove getPos ammocrate

;make sure the loon is close to the ammocrate
;this is so it "looks" right
@lawguy distance ammocrate < 1

;replace "animation" with the a suitable animation
lawguy switchmove animation

;add 3 LAW magazines to loon
;no error checking here, just add however many
;if loon is full up, he just won't get all, but no error message
lawguy addmagazine "LAWLauncher"
lawguy addmagazine "LAWLauncher"
lawguy addmagazine "LAWLauncher"
#end

Now, I can't recall if forEach allows code blocks, but if it does you should be able to stick the entire block into a forEach statement.

As for sticking all the LAW guys in an array, my guess would be to make use of countType again. At the beginning of the mission:

Code: [Select]
"if (""lawlauncher"" countType _x > 0) then {lawguys = lawguys + _x}" forEach units side west
should do the trick. Though this is untested. I'm not entirely certain that I can assign an array like that. If need be, I can test this tomorrow.

[disclaimer] I'm quite braindead right now, so there may be really stupid errors [/disclaimer]

Offline ONoSixIsDown

  • Members
  • *
Re:making AI sqauds rearm?
« Reply #11 on: 27 Nov 2005, 23:44:52 »
that just may do it... i'll give it a try later tonight and try it.  you really cleared that mess up for me(hopefully:P).   that'll make the mission i'm having beta tested  a bit easier(not much but the loons will be somewhat more helpfull against the wave of armor)  but yeah, if it doesnt work, i'm sure i can out whats wrong with it now that i see how to script it.  
CRIMSON REIGN COMMING..... eventually :/

LoTekK

  • Guest
Re:making AI sqauds rearm?
« Reply #12 on: 28 Nov 2005, 05:24:57 »
Told ya there'd be stupid errors. :-X

Okay, array assignment. Before you can add to an array, you have to explicitly create one. So:
Code: [Select]
laws = units grpNullcreates an empty array for you to play around with.

Next up. ForEach certainly does not allow code blocks in your scripts (which I find exceedingly odd since semicolon-delineated command blocks work just fine in the mission editor). So you can use a couple of different ways to manage the array of lawguys.
Code: [Select]
;make a copy of the array
_lawgroupcopy = +_lawgroup

#start
_lawguy = _lawgroupcopy select 0

<... your code ...>

_lawgroupcopy = _lawgroupcopy - _lawguy
goto "start"

Next error. CountType only works for vehicles. Or anything defined under cfgVehicles. Which LAWLauncher does not fall under. So, I fumbled together some clumsy scripting that works, but is admittedly messy:
Code: [Select]
_mags = count magazines _lawguy
_nolaws = count ((magazines _lawguy) - ["LAWLauncher"])
_laws = _mags - _nolaws
That'll return how many LAWs the loon is in posession of.

Offline ONoSixIsDown

  • Members
  • *
Re:making AI sqauds rearm?
« Reply #13 on: 28 Nov 2005, 17:49:05 »
thanks alot... i admit was going slightly crazy trying to get it right.  i think one of my problems was that i was trying those codes on ver: 1.75.  well now i got 1.96 and its working.  it seems alittle buggy(one law soldier ran to the crate and started break dancing)  :P but it's doing what i wanted it to do.
CRIMSON REIGN COMMING..... eventually :/