Home   Help Search Login Register  

Author Topic: Custom Random Loadouts  (Read 864 times)

0 Members and 1 Guest are viewing this topic.

Homefry31464

  • Guest
Custom Random Loadouts
« on: 30 May 2004, 23:48:54 »
I was trying to determine a way to have a script run that would randomize which guns a unit starts with.  The script would just need ammo and gun class names.  Here's how it would work...

1.  The mission maker determines which guns the units could have.
2.  The script is run on a unit (from the init field).  
3.  The script clears the units current loadout.
4.  A random variable determines what gun and ammo the unit recieves.
5.  The gun and ammo is assigned to the unit.
6.  The script exits.

I envision the script could be used when the player is not the squad leader, or it could be used to randomize what weapons the AI is equipped with (using a trigger.)

What does everyone think?
« Last Edit: 30 May 2004, 23:49:44 by Homefry »

PsyWarrior

  • Guest
Re:Custom Random Loadouts
« Reply #1 on: 31 May 2004, 00:27:40 »
Greets, Homefry,

Feasable. You could generate a random number based on the number of elements in an array, round it off, and then select whatever number results from the array.

You would need two arrays: one for Primary weapon, and one for secondary. Maybe a third for Handgun?

Here's some scripting ideas
The user inputs unit to exec for, and the two (or three) arrays.

;******************************
; RandomWeapons.sqs
;******************************
; PsyWarrior@spiers.tv
;******************************

_unit = _this select 0
_primaryArray = _this select 1
_secondaryArray = _this select 2

;Weapons are removed:
removeAllWeapons _unit

;Generate random number based on no of elements in array.
_n = 0
_n = count _primaryArray
_random1 = random _n

;Add the weapon
_primaryWeap = _primaryArray select _n
_unit addWeapon _primaryWeap

;STOP
At this point you would have to add the ammo for the weapon. One way to do this is to create another array, with the ammo names in the same place as the weapon in the weapons array ( :P)
EG: primaryArray [m16, weap1,..., weapn]
primaryAmmoArray [m16, weap1Mag,..., weapnMag]

We'll assume that's _this select 3
;Start

_primaryAmmoArray = _this select 3
_ammo = _primaryAmmoArray select _n
_unit addmagazine _ammo
;repeat for 4 times

;Just remembered that this has to be before the weapon is added. Sorry.

;exactly the same applies for the secondary weapons, if you want them.

exit
;STOP

Yes, it's a mess. But it's also a starting point... :P

I may refine this a bit when I've had some sleep. As you can see, it is entirely possible.

The only disadvantage is that the mission editor would have to pass 4 great arrays of all the weapons and magazines with the script. Alternatively, you could set the arrays up elsewhere, (init.sqs?), and then simply use
_unit = _this select 0

with primaryArray, secondaryArray etc. all defined elsewhere, and used as global variables.

Of course, due to some glaring error that I have not yet noticed, the above may not work at all ::)

-Supr. Cmdr. PsyWarrior
-Psychic Productions


Homefry31464

  • Guest
Re:Custom Random Loadouts
« Reply #2 on: 31 May 2004, 00:33:26 »
Thanks a bundle, I'll have to try it out when I get home.  Maybe you could also define the  arrays in the script?  I was thinking more along these lines, but you can tell me if this is a good idea or not...

What I need is a way to have an array of primary weapons, and have an easy way to determine which ammo corresponds with the weapon.  I'm not entirely sure how this would be done, any suggestions?

PsyWarrior

  • Guest
Re:Custom Random Loadouts
« Reply #3 on: 31 May 2004, 17:10:38 »
What I need is a way to have an array of primary weapons, and have an easy way to determine which ammo corresponds with the weapon.  I'm not entirely sure how this would be done, any suggestions?

The only way I can think of is detailed above, having a ammo array which has the ammo in the same place as the weapons array ( :P)
Example:
primaryWeapon select 1 is an M4
primaryAmmo select 1 is an M4mag

So you would call (after creating a random number):
_mag = _primaryAmmo select _n
_unit addmagazine _mag
_unit addmagazine _mag
_unit addmagazine _mag
_unit addmagazine _mag

_weap1 = _primaryWeapon select _n
_unit addWeapon _weap1

And then generate a new random number based on the number of elements in the secondaryWeapon or secondaryAmmo array.

Only way I can think of to find which ammo a weapon uses at the moment...

Yes, you could easily define the arrays in the script. It would be easier, in fact, than defining them in the exec line, or in init.sqs

-PsyWarrior
-PSYPROD

Homefry31464

  • Guest
Re:Custom Random Loadouts
« Reply #4 on: 31 May 2004, 18:14:00 »
Thanks a lot, this really helps.