Results 1 to 4 of 4

Thread: Custom loadout, help with my code

  1. #1

    Custom loadout, help with my code

    I am trying to do a nice custom loadout script.
    But I can't get it to work right.

    This is what I have right now:

    fnc_gear.sqf
    Code:
    private ["_unit","_strLoadout"];
    _unit = _this select 0;
    _strLoadout = _this select 1;
    
    removeAllWeapons _unit;
    removeBackpack _unit;
    clearMagazineCargo unitBackpack _unit;
    _unit addWeapon "Binocular_Vector";
    _unit addWeapon "NVGoggles";
    
    
    switch (_strLoadout) do {
      case "START" : {
        	_unit addBackpack "US_Backpack_AmmoMG_EP1";
    	clearMagazineCargo unitBackpack _unit;
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "ACE_Battery_Rangefinder";
    	_unit addweapon "M249_m145_EP1";
    	_unit selectWeapon "M249_m145_EP1";
    	(unitBackpack _unit) addMagazineCargo ["100Rnd_556x45_BetaCMag",5];
      };
      case "MG" : {
        	_unit addBackpack "US_Backpack_AmmoMG_EP1";
    	clearMagazineCargo unitBackpack _unit;
    	 addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "100Rnd_556x45_BetaCMag";
    	_unit addMagazine "ACE_Battery_Rangefinder";
    	_unit addweapon "M249_m145_EP1";
    	_unit selectWeapon "M249_m145_EP1";
    	(unitBackpack _unit) addMagazineCargo ["100Rnd_556x45_BetaCMag",5];
      };
      case "STINGER" : {
        	_unit addweapon "ACE_BackPack_ACR_TT";
    	clearMagazineCargo unitBackpack _unit;
    	_unit addweapon "Stinger";
    	_unit addMagazine "Stinger";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "ACE_Battery_Rangefinder";
    	_unit addweapon "ACE_SCAR_H_STD_Spect";
    	_unit selectWeapon "ACE_SCAR_H_STD_Spect";
    	(unitBackpack _unit) addMagazineCargo ["20Rnd_762x51_B_SCAR",5];
    	(unitBackpack _unit) addMagazineCargo ["Stinger",1];
      };
      case "JAVELIN" : {
        	_unit addBackpack "US_Backpack_AT_EP1";
    	clearMagazineCargo unitBackpack _unit;
    	_unit addweapon "ACE_Javelin_Direct";
    	_unit addMagazine "ACE_Javelin_Direct";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "20Rnd_762x51_B_SCAR";
    	_unit addMagazine "ACE_Battery_Rangefinder";
    	_unit addweapon "ACE_SCAR_H_STD_Spect";
    	_unit selectWeapon "ACE_SCAR_H_STD_Spect";
    	(unitBackpack _unit) addMagazineCargo ["20Rnd_762x51_B_SCAR",5];
    	(unitBackpack _unit) addMagazineCargo ["ACE_Javelin_Direct",1];
      };
      case "SNIPER" : {
        	_unit addBackpack "US_Backpack_EP1";
    	clearMagazineCargo unitBackpack _unit;
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";
    	_unit addMagazine "ACE_Battery_Rangefinder";
    	_unit addweapon "ACE_AS50";
    	_unit selectWeapon "ACE_AS50";
    	(unitBackpack _unit) addMagazineCargo ["20Rnd_762x51_B_SCAR",5];
      };
    };
    Now, how do I call it from the players initfield?

    I have try this, but I can't get it to work
    Code:
    _strLoadout = [this, "START"] execVM "scripts\fnc_gear.sqf";

    Thanks

    ---------- Post added at 03:11 PM ---------- Previous post was at 01:22 PM ----------

    Found this and it works

    Player initfield:
    Code:
    hNil = [this, "START"] call compile preprocessFile "scripts\fnc_gear.sqf";
    fnc_gear.sqf:
    Code:
    if (!isServer) exitWith {};
    _unit = _this select 0;
    _strLoadout = _this select 1;
    
    removeAllWeapons _unit;
    removeBackpack _unit;
    
    switch (_strLoadout) do
    {   
    	case "MG":
    	{
    		if (local _unit) then
    		{
    			{_unit addBackpack "US_Backpack_AmmoMG_EP1";} forEach [1];
    			clearMagazineCargo unitBackpack _unit;
    			{_unit addMagazine "100Rnd_556x45_BetaCMag";} forEach [1,2,3,4];
          		_unit addWeapon "M249_m145_EP1";
    			(unitBackpack _unit) addMagazineCargo ["100Rnd_556x45_BetaCMag",5];
    		};
    	};
       
    	case "START":
    	{
    			{_unit addBackpack "US_Backpack_AmmoMG_EP1";} forEach [1];
    			clearMagazineCargo unitBackpack _unit;
    			{_unit addMagazine "100Rnd_556x45_BetaCMag";} forEach [1,2,3,4];
          		_unit addWeapon "M249_m145_EP1";
    			(unitBackpack _unit) addMagazineCargo ["100Rnd_556x45_BetaCMag",5];
    	};
    
    	case "STINGER":
    	{
    			{_unit addBackpack "US_Backpack_AmmoMG_EP1";} forEach [1];
    			clearMagazineCargo unitBackpack _unit;
    			{_unit addMagazine "20Rnd_762x51_B_SCAR";} forEach [1,2,3,4,5];
          		_unit addWeapon "Stinger";
          		_unit addWeapon "ACE_SCAR_H_STD_Spect";
    			(unitBackpack _unit) addMagazineCargo ["20Rnd_762x51_B_SCAR",5];
    			(unitBackpack _unit) addMagazineCargo ["Stinger",1];
    	};
    	
    	case "JAVELIN":
    	{
    			{_unit addBackpack "US_Backpack_AmmoMG_EP1";} forEach [1];
    			clearMagazineCargo unitBackpack _unit;
    			{_unit addMagazine "20Rnd_762x51_B_SCAR";} forEach [1,2,3,4,5];
    			{_unit addMagazine "ACE_Javelin_Direct";} forEach [1];
          		_unit addWeapon "ACE_Javelin_Direct";
          		_unit addWeapon "ACE_SCAR_H_STD_Spect";
    			(unitBackpack _unit) addMagazineCargo ["ACE_Javelin_Direct",1];
    			(unitBackpack _unit) addMagazineCargo ["20Rnd_762x51_B_SCAR",5];
    	};
    	
    	case "SNIPER":
    	{
    			{_unit addBackpack "US_Backpack_AmmoMG_EP1";} forEach [1];
    			clearMagazineCargo unitBackpack _unit;
    			{_unit addMagazine "ACE_5Rnd_127x99_B_TAC50";} forEach [1,2,3,4,5,6,7,8,9,10,11];
          		_unit addWeapon "ACE_AS50";
    			(unitBackpack _unit) addMagazineCargo ["ACE_5Rnd_127x99_B_TAC50",10];
    	};
    	
    	case "SMAW":
    	{
    			{_unit addBackpack "US_Backpack_AmmoMG_EP1";} forEach [1];
    			clearMagazineCargo unitBackpack _unit;
    			{_unit addMagazine "20Rnd_762x51_B_SCAR";} forEach [1,2,3,4,5];
    			{_unit addMagazine "SMAW_HEAA";} forEach [1,2];
          		_unit addWeapon "SMAW";
          		_unit addWeapon "ACE_SCAR_H_STD_Spect";
    			(unitBackpack _unit) addMagazineCargo ["20Rnd_762x51_B_SCAR",5];
    			(unitBackpack _unit) addMagazineCargo ["SMAW_HEAA",1];
    	};
    };
    
    if (!(_unit hasWeapon "itemGPS")) then
    {
    	_unit addWeapon "itemGPS";
    };
    _unit addWeapon "Binocular_Vector";
    _unit addWeapon "NVGoggles";
    _unit addMagazine "ACE_Battery_Rangefinder";
    _primaryWeapon = primaryWeapon _unit;
    _unit selectweapon _primaryWeapon;
    // Fix for weapons with grenade launcher
    _muzzles = getArray(configFile>>"cfgWeapons" >> _primaryWeapon >> "muzzles");
    _unit selectWeapon (_muzzles select 0);

  2. #2
    Watching this thread as I am interested in this myself also. Do you know how to make it so the player can choose loadouts for the balance of an AI squad so he can control all the weapons brought with the squad.?

  3. #3
    Sorry, I don't know
    Last edited by splatsh; Jan 12 2011 at 20:24.

  4. #4
    Quote Originally Posted by Breeze View Post
    Watching this thread as I am interested in this myself also. Do you know how to make it so the player can choose loadouts for the balance of an AI squad so he can control all the weapons brought with the squad.?
    you have to do it statically for every unit

    im sure there is a script out there that does it, but if not, this is generally speaking, what you would want to do (pseudo):

    create a function that takes in unit names as a parameter
    scriptName["unit1", "unit2",..."unitN-1", "unitN"]
    Code:
    first, remove all weapons and magazines, etc for the unit you are evaluating
    evaluate based on which unit you are using (i.e. iterate through, and if unit
         is unitNumber which is a multiple of say, 4, then give it this loadout)
    have a switch table which says if unitNumber is equal to unitNumber -
         (iterationCount * numberOfSwitchTableElements)
    then, give it the weapons you want.
    thats literally all you need. if you want it based on certain other criteria, for example what enemy units are in the area, you will have to create rules for that. what i have provided is very simple, saying that you will pass in a list of units, and it will iterate through giving unit1 weaponsA, unit2 weaponsB, unit3 weaponsC, unit4 weaponsA, etc etc, assuming that you only have 3 weapons in the switch table.

    EDIT: the script above does it already lol, so all you need is to pass in an array of units, and iterate over them instead of passing in what weapon class you want
    Last edited by GDICommand; Jan 13 2011 at 02:45.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •