Home   Help Search Login Register  

Author Topic: Management of groups in scripts  (Read 1249 times)

0 Members and 1 Guest are viewing this topic.

Fenix83

  • Guest
Management of groups in scripts
« on: 21 Oct 2003, 14:14:22 »
I'd like, in a script, to create a variable that regroup many differents units and use only one of these units according to a condition and use the rest for another task.

It'd be somethin like that

-----------------------------------
_groups = [west1 OR west2 OR west3]
ask which of these units are out of ammo
then make the unit that has been found to go to look for more ammo

make the rest to go at _Xpos
exit
-----------------------------------

I hope I was clear and accurate in my description

Thanks for your attention

Komuna

  • Guest
Re:Management of groups in scripts
« Reply #1 on: 22 Oct 2003, 14:35:06 »
then make the unit that has been found to go to look for more ammo

The major problem is that you can't make a unit to look for ammo... I don't know if there's any action which compels a unit to get ammo at a certain AmmoCrate/AmmoBearingVehicle. Lets wait for the reply of an action expert, then.

Once I had the idea of making a ammo bearer for MG and AT specialists. Adding ammo through the command "this addMagazineCargo ["MAGDESIGNATION",_Amount]" (of course, you should make an addon to make this unit able to carry mags: transportMaxMagazines=<amount>.), would, indeed, add magazines to the unit as if it was an ammocrate. However, when MGN's ran out of ammo, they didn't call or move to this ammo bearer.

The only way you can make it work is using dead units. Regardless of the unit side, an empty mg compels its gunner to get ammo at a deadbody - if it has the same mag type. Nevertheless, notice that this tweak doesn't work for secondarySlot weapons - LAWLauncher, e.g. - and this theorical ammoCrate would be able to carry only a limited amount of mags: 10*256slot (10 M16 or 5 M60 mags, e.g.). In this way, you could create your own invisible already-dead-unit for carrying mags and use a script to place it at the position of your virtual ammo bearer. It would work.

Otherwise, you can also make a script which makes the no-mags unit to move to the nearest ammoCrate, which would have the dead-ammo-bearer beside it, and take the mags.



Now, the scanning script is very simple:

Code: [Select]
{IF (!(someAmmo _x)) THEN {_x exec "MyReloadingScript.sqs"}} foreach (units (group1+group2+group3...))


~2

Note: the syntax might be wrong at "(units (group1+group2+group3))" as I don't know if you can sum group (just testing that). If it doesn't work (I belive it does) use (units group1 + units group2 + units group3 ... )


Besides, the condition 'someAmmo' (although it exists) may not return the wanted boolean. If you encounter difficulties with it, just:

IF ((_x ammo (magazines _x select 0)) == 0) THEN {...}



Then, the "MyReloadingScript.sqs" would be called and ran foreach units that ran out of ammo. Its settings would depend on the reloading method you want (search ammo or just addmagazine). Therefore, we await your answer for further scripting. ;)
« Last Edit: 22 Oct 2003, 14:37:28 by Komuna »

Fenix83

  • Guest
Re:Management of groups in scripts
« Reply #2 on: 22 Oct 2003, 16:02:13 »
The major problem is that you can't make a unit to look for ammo... I don't know if there's any action which compels a unit to get ammo at a certain AmmoCrate/AmmoBearingVehicle. Lets wait for the reply of an action expert, then.

Once I had the idea of making a ammo bearer for MG and AT specialists. Adding ammo through the command "this addMagazineCargo ["MAGDESIGNATION",_Amount]" (of course, you should make an addon to make this unit able to carry mags: transportMaxMagazines=<amount>.), would, indeed, add magazines to the unit as if it was an ammocrate. However, when MGN's ran out of ammo, they didn't call or move to this ammo bearer.

The only way you can make it work is using dead units. Regardless of the unit side, an empty mg compels its gunner to get ammo at a deadbody - if it has the same mag type. Nevertheless, notice that this tweak doesn't work for secondarySlot weapons - LAWLauncher, e.g. - and this theorical ammoCrate would be able to carry only a limited amount of mags: 10*256slot (10 M16 or 5 M60 mags, e.g.). In this way, you could create your own invisible already-dead-unit for carrying mags and use a script to place it at the position of your virtual ammo bearer. It would work.

Otherwise, you can also make a script which makes the no-mags unit to move to the nearest ammoCrate, which would have the dead-ammo-bearer beside it, and take the mags.



Now, the scanning script is very simple:

Code: [Select]
{IF (!(someAmmo _x)) THEN {_x exec "MyReloadingScript.sqs"}} foreach (units (group1+group2+group3...))


~2

Note: the syntax might be wrong at "(units (group1+group2+group3))" as I don't know if you can sum group (just testing that). If it doesn't work (I belive it does) use (units group1 + units group2 + units group3 ... )


Besides, the condition 'someAmmo' (although it exists) may not return the wanted boolean. If you encounter difficulties with it, just:

IF ((_x ammo (magazines _x select 0)) == 0) THEN {...}


Then, the "MyReloadingScript.sqs" would be called and ran foreach units that ran out of ammo. Its settings would depend on the reloading method you want (search ammo or just addmagazine). Therefore, we await your answer for further scripting. ;)

First, I'd like to thank you for answering me !

Now, my worries was mostly about the detection stuff. I wanted to use a single array containing unit1, unit2, unit3, etc. and test each unit in it to know which one need ammo then, ONLY the unit that need some more ammo would execute the instruction or an external script.

For the ammo supplying, I'll use a kind of simulation. I'll place some crate on the map and name it. With the getPos command they will head to the closest crate and if it still not destroyed by the enemy (command : "damage unit" that return 0 to 1) and if the unit that need to be supllied is close enough, the script will check what kind of stuff they carry and supply the right ammo

EDIT :

I usually don't use the "IF, ELSE, THEN" combo but I can't wait to learn more about it !

Is that script could work ?

Init line : [[west1, west2, west3], 30] exec "MyReloadingScript.sqs"

Code: [Select]
_westGroups = _this select 0
_ammoAK = _this select 1

IF ((_x ammo ("ak47" _x select 0)) <= _ammoAK) THEN {_unitOutofAmmo = _x}} foreach (units _WestGroups))

_unitoutofammo commandMove [getpos SupplyStore]

exit
« Last Edit: 22 Oct 2003, 18:08:53 by Fenix83 »

Komuna

  • Guest
Re:Management of groups in scripts
« Reply #3 on: 23 Oct 2003, 13:33:29 »
Hmm... I don't think so... You have some syntax errors.

Notice that 'ammo' counts how many slots are left.
Your commandMove syntax is wrong - should be _unit commandMove (getpos SuplyStore). Besides, it won't force the unit to resuply.


In my opinion, my script is much more effective.
You should have two script: the checker and the suplier:

The checker

Arguments: ListOfUnits

E.g. (units group1 + units group2) exec "CheckAmmo.sqs"

Code: [Select]

_List = _this

#Check

{IF (!(someAmmo _x)) THEN {_x exec "Suplier.sqs"}} foreach _List

~2

? ("alive _x" count _List > 0): Goto "check"
exit



The Suplier

Arguments: unitToBeSuplied

E.g. _x exec "Suplier.sqs"

Code: [Select]
_this doMove (position AmmoStore)

@unitReady _this

_this playmove "PutDown"

_this addMagazine (magazines _this select 0)
_this addMagazine (magazines _this select 0)
_this addMagazine (magazines _this select 0)
_this addMagazine (magazines _this select 0)
_this addMagazine (magazines _this select 0)
« Last Edit: 23 Oct 2003, 13:34:03 by Komuna »