Home   Help Search Login Register  

Author Topic: Random Loadouts  (Read 2751 times)

0 Members and 1 Guest are viewing this topic.

Homefry31464

  • Guest
Random Loadouts
« on: 11 Jun 2004, 19:10:19 »
I worked on a script, based off code PsyWarrior posted in a different thread.  Unfortunetly, I can't quite get it to work.  I get the error:
"_man _this select 0 |#|" Error select: Type Object, expected Array (or something to that extent.)

Code: [Select]
;Random Loadouts.... Originally by PsyWarrior
;Edited by Homefry
;To Use: unitname exec "randomweapons.sqs"

_man = _this select 0

;Weapons are removed:
removeAllWeapons _man

;Determine what side the unit is on
?side _man == west : goto "westweapons"
?side _man == east : goto "eastweapons"
?side _man == resistance : goto "resistanceweapons"
?side _man == civilian : goto "civilianweapons"

#westweapons
_primaryArray = ["m16", "M60", "M4", "G36A", "FAL", "Steyr", "HKG3"]
_BulletArray = ["m16", "M60", "M4", "G36AMag", "FALMag", "SteyrMag", "HKG3Mag"]
goto "randomize"

#eastweapons
_primaryArray = ["AK47", "AK74", "AK74SU", "PK"]
_BulletArray = ["AK47", "AK74", "AK74", "PK"]
goto "randomize"

#resistanceweapons
_primaryArray = ["AK47", "AK47CZ", "HuntingRifle", "PK", "FAL"]
_BulletArray  = ["AK47", "AK47", "HuntingRifleMag", "PK", "FALMag"]
goto "randomize"

#civilianweapons
_primaryArray = ["Beretta", "CZ75", "Glock", "Ingram", "Revolver", "Skorpion", "Tokarev"]
_BulletArray = ["BerettaMag", "CZ75Mag", "GlockMag", "IngramMag", "RevolverMag", "SkorpionMag", "TokarevMag"]
goto "randomize"


;Generate random number based on number of elements in array.
#randomize
_n = 0
_n = count _primaryArray
_random1 = random _n
goto "loopstart"



#loopstart
_a = _a + 1
_ammo = _BulletArray select _n
_man addmagazine _ammo
?_a == 4 : goto "addpriweapon"
goto "loopstart"


;Add the weapon
#addpriweapon
_primaryWeap = _primaryArray select _n
_man addWeapon _primaryWeap

exit
« Last Edit: 12 Jun 2004, 01:20:59 by Homefry »

Offline Nemesis6

  • Members
  • *
Re:Random Loadouts
« Reply #1 on: 11 Jun 2004, 20:07:47 »
_man = _this select 0|#|' - If you don't know, the script should be executed as such - [this] exec "randomweapons.sqs"

re-upload a fixed version of the mission.

The seperate script - My weapons are removed and I don't recieve a new one. I suspect _n to be the the troublemaker... the script gets to addpriweapon, but it doesn't seem to have anything to give.
« Last Edit: 11 Jun 2004, 20:36:57 by Nemesis6 »
I am actually flying into a star... this is incredible!

Homefry31464

  • Guest
Re:Random Loadouts
« Reply #2 on: 11 Jun 2004, 23:58:09 »
Thanks for your help, it works now.  :cheers:

Code: [Select]
;Random Loadouts.... Originally by PsyWarrior
;Edited by Homefry
;To Use: [unitname] exec "randomweapons.sqs"

_man = _this select 0

;Weapons are removed:
removeAllWeapons _man

;Determine what side the unit is on
?side _man == west : goto "westweapons"
?side _man == east : goto "eastweapons"
?side _man == resistance : goto "resistanceweapons"
?side _man == civilian : goto "civilianweapons"

#westweapons
_primaryArray = ["m16", "M60", "M4", "G36A", "FAL", "Steyr", "HKG3"]
_BulletArray = ["m16", "M60", "M4", "G36AMag", "FALMag", "SteyrMag", "HKG3Mag"]
goto "randomize"

#eastweapons
_primaryArray = ["AK47", "AK74", "AK74SU", "PK"]
_BulletArray = ["AK47", "AK74", "AK74", "PK"]
goto "randomize"

#resistanceweapons
_primaryArray = ["AK47", "AK47CZ", "HuntingRifle", "PK", "FAL"]
_BulletArray  = ["AK47", "AK47", "HuntingRifleMag", "PK", "FALMag"]
goto "randomize"

#civilianweapons
_primaryArray = ["Beretta", "CZ75", "Glock", "Ingram", "Revolver", "Skorpion", "Tokarev"]
_BulletArray = ["BerettaMag", "CZ75Mag", "GlockMag", "IngramMag", "RevolverMag", "SkorpionMag", "TokarevMag"]
goto "randomize"


;Generate random number based on number of elements in array.
#randomize
_n = 0
_n = count _primaryArray
_random1 = random _n + 1
goto "loopstart"



#loopstart
_ammo = _BulletArray select _random1
_man addmagazine _ammo
_man addmagazine _ammo
_man addmagazine _ammo
_man addmagazine _ammo

_primaryWeap = _primaryArray select _random1
_man addWeapon _primaryWeap


exit

I still don't know if the +1 at the end of _random1 = random _n + 1 is needed, but I'm in a rush and I can't test extensively.  But it did work, it gave the soldier a FAL and a G36 when I tested it.
« Last Edit: 13 Jun 2004, 22:19:00 by Homefry »

Offline Nemesis6

  • Members
  • *
Re:Random Loadouts
« Reply #3 on: 12 Jun 2004, 12:36:07 »
Yep, it does indeed seem to work now. But I spotted an error once, and another time, the guy didn't recieve a weapon. Just minor errors.



By the way, I made my own script while waiting for you to fix it... :P
I am actually flying into a star... this is incredible!

Homefry31464

  • Guest
Re:Random Loadouts
« Reply #4 on: 12 Jun 2004, 14:53:30 »
If he didn't recieve a weapon, I think that means that the line:


_random1 = random _n + 1


Can do without the + 1 at the end.  I'm not at a computer with Flashpoint now, but I think that should solve your problem.

Homefry31464

  • Guest
Re:Random Loadouts
« Reply #5 on: 13 Jun 2004, 21:58:14 »
Alright, I've had the time to test and update this baby.  I've included a way to have user made guns integrated relatively easy.  Now all I have left to do is figure out a way to add LAW's and the like.  

To use:  [unitname, "ModName"] exec "randomweapons.sqs" (Default ModName is "Default")

Code: [Select]
;Random Loadouts.... Originally by PsyWarrior
;Edited by Homefry
;To Use: [unitname, "modname"] exec "randomweapons.sqs"
;use [unitname, "Default"] exec "randomweapons.sqs" to use BIS Weapons only

_man = _this select 0
_mod = _this select 1


;Weapons are removed:
removeAllWeapons _man

;Determine what side the unit is on
?side _man == west : goto "westweapons"
?side _man == east : goto "eastweapons"
?side _man == resistance : goto "resistanceweapons"
?side _man == civilian : goto "civilianweapons"

;Add West Weapons:
#westweapons
;Format for Adding in Addon Weapons:
;?_mod == "MODNAME" : _primaryArray = ["GUN_CLASS_NAME_ONE", "GUN_CLASS_NAME_TWO", "ETC..."]
;?_mod == "MODNAME" : _BulletArray = ["MAG_CLASS_NAME_ONE", "GUN_CLASS_NAME_TOW", "ETC..."]
?_mod == "BAS" : _primaryArray = ["BAS_JM4ACOG", "BAS_JM4ACOGS", "BAS_JM4MKACOG", "BAS_JM4REFLEX", "BAS_JM4REFLEXS", "BAS_JM4ReflexM203", "BAS_JM4ReflexSM203", "BAS_JM4MKReflex", "BAS_JM4EOTech", "BAS_JM4EOTechS", "BAS_JM4EOTechM203", "BAS_JM4EOTechSM203", "BAS_JM4Aimpoint", "BAS_JM4AimpointS", "BAS_JM4AimpointM203", "BAS_JM4AimpointSM203", "BAS_JM14AIMPOINT", "BAS_JM14DMR", "BAS_JM24SWS", "BAS_JSR25", "BAS_JSR25S", "BAS_JMP5SDAimpoint", "BAS_JM249", "BAS_JM249SPW", "BAS_JM249SPWSD", "BAS_JM240B"]
?_mod == "BAS" : _BulletArray = ["JAM_W556_30mag", "JAM_W556_30SDmag", "JAM_W556_30mag", "JAM_W556_30mag", "JAM_W556_30SDmag", "JAM_W556_30mag", "JAM_W556_30mag", "JAM_W556_30mag", "JAM_W556_30mag", "JAM_W556_30SDmag", "JAM_W556_30mag", "JAM_W556_30mag", "JAM_W556_30mag", "JAM_W556_30SDmag", "JAM_W556_30mag", "JAM_W556_30SDmag", "JAM_W762_20mag", "JAM_W762_20mag", "JAM_W762_5mag", "JAM_W762Sniper_20Mag", "JAM_W762Sniper_20SDMag", "JAM_MP5SBASDmag", "JAM_W556M_200mag", "JAM_W556M_200mag", "JAM_W556M_200SDmag", "JAM_W762M_100mag"]
?_mod == "BAS" : goto "randomize"
 
?_mod == "MARPAT" : _primaryArray = ["C8XM16acog", "C8XM16cco", "C8XM16reflex", "C8XM16M203", "C8XM16M203acog", "C8XM16M203reflex", "C8XM16M203cco", "C8XM249", "C8XM249m145", "C8XM249PARA", "C8XM249PARAcco", "C8XM4", "C8XM4acog", "C8XM4reflex", "C8XM4cco", "C8XM4M203", "C8XM4M203cco", "C8XM4M203acog", "C8XM4M203reflex", "C8XM4_sd", "C8XM4acog_sd", "C8XM4reflex_sd", "C8XM4cco_sd", "C8XM4M203_sd", "C8XM4M203cco_sd", "C8XM4M203acog_sd", "C8XM4reflex_sd", "C8XM1014", "C8XM1014cco"]
?_mod == "MARPAT" : _BulletArray = ["c8xm16mag", "c8xm16mag", "c8xm16mag", "c8xm16mag", "c8xm16mag", "c8xm16mag", "c8xm16mag", "c8xm16mag", "c8xm249mag", "c8xm249mag", "c8xm249mag", "c8xm249mag", "c8xm4mag", "c8xm4mag", "c8xm4mag", "c8xm4mag", "c8xm4mag", "c8xm4mag", "c8xm4mag", "c8xm4mag", "c8xm4sdmag", "c8xm4sdmag","c8xm4sdmag","c8xm4sdmag","c8xm4sdmag","c8xm4sdmag","c8xm4sdmag","c8xm4sdmag", "c8xm1014mag", "c8xm1014mag"]
?_mod == "MARPAT" : goto "randomize"

_primaryArray = ["m16", "M60", "M4", "G36A", "FAL", "Steyr", "HKG3"]
_BulletArray = ["m16", "M60", "M4", "G36AMag", "FALMag", "SteyrMag", "HKG3Mag"]
goto "randomize"

#eastweapons
?_mod == "MARPAT" : _primaryArray = ["C8XAK74M", "C8XAK74Mcobra", "C8XAK74M1p29", "C8XAK74MGP25", "C8XAK74MGP25cobra", "C8XAK74MGP251p29", "C8XAK74M_SD", "C8XAK74Mcobra_SD", "C8XAK74M1p29_SD", "C8XAK74MGP25_SD", "C8XAK74MGP25cobra_SD", "C8XAK74MGP251p29_SD", "C8XRPK74M", "C8XRPK74M1p29", "C8XAKS74U", "C8XAKS74Ucobra", "C8XAKS74U_sd", "C8XAKS74Ucobra_sd", "C8XAKS74UBS1", "C8XAKS74UBS1cobra"]
?_mod == "MARPAT" : _BulletArray = ["c8xak74mag", "c8xak74mag", "c8xak74mag", "c8xak74mag", "c8xak74mag", "c8xak74mag", "c8xak74sdmag", "c8xak74sdmag", "c8xak74sdmag", "c8xak74sdmag", "c8xak74sdmag", "c8xak74sdmag", "c8xrpk74mag", "c8xrpk74mag", "c8xaks74umag", "c8xaks74umag", "c8xaks74usdmag", "c8xaks74usdmag", "c8xaks74usdmag", "c8xaks74usdmag"]
?_mod == "MARPAT" : goto "randomize"

_primaryArray = ["AK47", "AK74", "AK74SU", "PK"]
_BulletArray = ["AK47", "AK74", "AK74", "PK"]
goto "randomize"

#resistanceweapons
_primaryArray = ["AK47", "AK47CZ", "HuntingRifle", "PK", "FAL"]
_BulletArray  = ["AK47", "AK47", "HuntingRifleMag", "PK", "FALMag"]
goto "randomize"

#civilianweapons
_primaryArray = ["Beretta", "CZ75", "Glock", "Ingram", "Revolver", "Skorpion", "Tokarev"]
_BulletArray = ["BerettaMag", "CZ75Mag", "GlockMag", "IngramMag", "RevolverMag", "SkorpionMag", "TokarevMag"]
goto "randomize"


;Generate random number based on number of elements in array.
#randomize
_random1 = 0
_n = 0
_n = count _primaryArray
_random1 = random _n
_random1 = _random1 - 1
?_random1 == 0 : goto "randomize"
?_random1 > _n : goto "randomize"
?_random1 < 0 : goto "randomize"
_ammo = _BulletArray select _random1
_primaryWeap = _primaryArray select _random1
_a = 0
goto "specialweapons"


;Weapons with speconday weapons go here:
;In this case, weapon's with M203's or similar were given two rounds
#specialweapons
?_a == 2: goto "loopstart"
?_mod == "BAS" && _primaryWeap == "BAS_JM4ReflexM203" : _man addMagazine "JAM_M433grenade"
?_mod == "BAS" && _primaryWeap == "BAS_JM4ReflexSM203" : _man addMagazine "JAM_M433grenade"
?_mod == "BAS" && _primaryWeap == "BAS_JM4EOTechM203" : _man addMagazine "JAM_M433grenade"
?_mod == "BAS" && _primaryWeap == "BAS_JM4EOTechSM203" : _man addMagazine "JAM_M433grenade"
?_mod == "BAS" && _primaryWeap == "BAS_JM4AimpointM203" : _man addMagazine "JAM_M433grenade"
?_mod == "BAS" && _primaryWeap == "BAS_JM4AimpointSM203" : _man addMagazine "JAM_M433grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM16M203" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM16M203acog" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM4M203reflex" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM4M203_sd" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM4M203acog_sd" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM4M203reflex_sd" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM4M203cco_sd" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM16M203reflex" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM16M203cco" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM4M203" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM4M203cco" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XM4M203acog" : _man addMagazine "c8xm203grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XAK74MGP25" : _man addMagazine "c8xgp25grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XAK74MGP25cobra" : _man addMagazine "c8xgp25grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XAK74MGP251p29" : _man addMagazine "c8xgp25grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XAK74MGP25_SD" : _man addMagazine "c8xgp25grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XAK74MGP25cobra_SD" : _man addMagazine "c8xgp25grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XAK74MGP251p29_SD" : _man addMagazine "c8xgp25grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XAKS74UBS1" : _man addmagazine "C8XBS1grenade"
?_mod == "MARPAT" && _primaryWeap == "C8XAKS74UBScobra" : _man addmagazine "C8XBS1grenade"
_a = _a + 1
goto "specialweapons"

#loopstart
;Give the unit his weapon and ammo
_man addmagazine _ammo
_man addmagazine _ammo
_man addmagazine _ammo
_man addmagazine _ammo
_man addWeapon _primaryWeap
~3
_b = _man hasWeapon _primaryWeap
?_b = 0 : goto "randomize"

exit

I've also included support for the BAS Delta/Rangers (v1.55) and the MARPAT Marines/RNI.  ModName="BAS" or "MARPAT".
« Last Edit: 13 Jun 2004, 22:20:07 by Homefry »

Homefry31464

  • Guest
Re:Random Loadouts
« Reply #6 on: 13 Jun 2004, 22:23:50 »
All error's should be fixed.  ;)

Script here:

andersgrim

  • Guest
Re:Random Loadouts
« Reply #7 on: 14 Jun 2004, 14:52:21 »
What about just dividing the script into different sets..
Then just randomise which set to use..

I find this way a lot simpler, but it might miss something though :-)

Code: [Select]
;   Example:

_u = _this select 0
_a = random(2)
?_a > 1: goto "M16LAW"
?_a > 2: goto "M60"

#M16LAW
   _u addMagazine M16
   _u addWeapon M16
goto "exit"

#M60
   _u addMagazine M60
   _u addWeapon M60
goto "exit"

#exit
exit

Homefry31464

  • Guest
Re:Random Loadouts
« Reply #8 on: 14 Jun 2004, 19:42:51 »
The only problem with that is you have to do a separate set for each weapon, and that mean's a lot of typing when you add in a lot of weapons.  But yes, for a small amount of weapons your method would be more practical.  

Offline Nemesis6

  • Members
  • *
Re:Random Loadouts
« Reply #9 on: 14 Jun 2004, 20:09:41 »
The side part(west, east, whatever) is from Homefry's script.

To brag - the weapons array is both realistic(hence the missing G36 in the array), and random.

Credits given, here it is -
« Last Edit: 14 Jun 2004, 20:11:08 by Nemesis6 »
I am actually flying into a star... this is incredible!

Homefry31464

  • Guest
Re:Random Loadouts
« Reply #10 on: 14 Jun 2004, 20:17:11 »
Good to see, I guess there are more ways to do things.  Good job Nemesis.