Home   Help Search Login Register  

Author Topic: rearming units in the field, with no set loadout  (Read 1548 times)

0 Members and 1 Guest are viewing this topic.

Offline Dajan

  • Members
  • *
rearming units in the field, with no set loadout
« on: 12 Aug 2008, 15:57:07 »
Basically, I'm trying to create a mission where I have a small group of GIs roving the map on H&K duty. By surviving to a checkpoint (set as a trigger) I want to be able to save (that's easy) and fill their inventory with the relavent weapon for their rifle.

Now, I know - I could just run a script the add 10 mags to them - piece of cake. But! What if they have changed gun since starting? Say from an AK to an M4? The mags aren't compatible.

So.. Is it possible to have a script read a GI's inventory, determine what mag their rifle needs and give them a specific number extra?

Sorry if I'm insulting anyones intelligence with all the preamble, but I want it to be clear what I'm trying to do so that it's easier for anyone to help.

<EDIT> Damn, all that and I still missed something! I only want the bonus mags added if the total held for the weapon is less thas 5 (<5)
« Last Edit: 12 Aug 2008, 16:10:27 by Dajan »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: rearming units in the field, with no set loadout
« Reply #1 on: 12 Aug 2008, 17:40:59 »
Well, you could always just put an ammo crate, filled to bursting with all the ammo types they could use, at the checkpoint. Alternatively, remove all their weapons and ammo and re-equip them from scratch. Either option really makes life a lot simpler all around. You also don't need to worry about one player having 10 mags with one bullet in each, for example, who wouldn't get rearmed. Or a player that has dropped their primary weapon at the moment when they get to the trigger (don't worry, someone will try that). Or someone that has stacks of grenades and ammo for another weapon, so that when you give them extra ammo for their rifle, they are overloaded...

Anyway, here are a couple of snippets that should get you on your way:
Code: [Select]
// Array of magazine classes that the player's "rifle" weapon can use. The first in the list could be assumed to be the default.
_primaryMagazineClasses = getArray (configFile >> "CfgWeapons" >> (primaryWeapon player) >> "magazines");

// How many magazines player currently has for the primary weapon.
_currentNumPrimaryMags = ({ _x in _primaryMagazineClasses } count (magazines player));
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: rearming units in the field, with no set loadout
« Reply #2 on: 12 Aug 2008, 19:57:33 »
I think the preamble does help figure out what you're looking for. :)   :good:

Do you have a pretty good idea beforehand which weapons might be available?  Perhaps build an array of weapons you'd provide mags for, then check to see if the primary weapon is in that list?

Also, are all the units to get new mags going to be players, or will some be AI?
Sic semper tyrannosauro.

Offline Dajan

  • Members
  • *
Re: rearming units in the field, with no set loadout
« Reply #3 on: 13 Aug 2008, 15:51:57 »
@Spooner - Thanks for the hints. I'm trying to do it with scripts to avoid having ammocrates lying about - I know they're more realistice, but gearring everyone up takes such a long time!

@Trexian - I'm working with weapons from several of the more common mod-packs, each unit on the 'team' starting with a unique weapon for individualitiy and balances sake more than anything. Units would be mostly AI, maybe 1-3 players out of the 9 on a team.

I was afraid arrays would come into this somewhere! I'm not exactly a coding genius - I've just started to get the hang of writing executable scripts, mostly self taught from other people's work. So I have absolutely no idea how to go about creating arrays or how to script for them!

Get the feeling I may be biting off more than I can chew here  :confused:

Offline Trexian

  • Members
  • *
Re: rearming units in the field, with no set loadout
« Reply #4 on: 14 Aug 2008, 16:56:24 »
I'm still pretty much a n00b at this stuff, too. :)

To make an array is pretty easy.  Let's say you want a variable _wpnArray to have a list of weapons that you're willing to give a guy mags for.

First, you'll need to know the class name of the weapons (check comref, weapons, ArmA). ;)  I think the way you'd do it in the script is.

Code: [Select]
_wpnArray = ["M4", "AK74", "M240", "PK"];

Your variable _wpnArray will have 4 elements:
_wpnArray select 0 = M4
_wpnArray select 1 = AK74

And so on.

You can use the primaryWeapon command to get the primary weapon for each unit in the trigger.  Then, compare the two (I know I've seen that script snippet somewhere around here) and if the primaryWeapon is in the array, add the correct magazine.

Actually, now that I think of it, you may only need a switch/case conditional.  (Sorry for the stream of consciousness posting....)

Something like this logic:
- foreach unit in the trigger list, get the primaryWeapon (code might be _reloadWpn = primaryWeapon _x)
- switch _reloadWpn, then case "M4" then add 5 mags for the M4, case AK74, add 5 mags for the AK, and so on

You could maybe even check to see how many mags remaining for the weapon _x has, and add an amount to get the person up to 10.
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: rearming units in the field, with no set loadout
« Reply #5 on: 14 Aug 2008, 19:08:55 »
I've already told you how to work out the magazines you need based on knowing the weapon type. You don't need any switching at all (just pick the first from the list of compatible magazines). Again, read my earlier comments about half-empty magazines and overloading equipment.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: rearming units in the field, with no set loadout
« Reply #6 on: 14 Aug 2008, 20:14:44 »
Pssst - Dajan - when in doubt, do it Spooner's way. ;)   :-[
Sic semper tyrannosauro.

Offline Dajan

  • Members
  • *
Re: rearming units in the field, with no set loadout
« Reply #7 on: 14 Aug 2008, 22:21:40 »
Point taken  ;)
Thanks again, I'll have a fiddle around and see what I can come up with!