Jump to content
Sign in to follow this  
Cold Evil

Classname decide what equipment to use when mission start for spawning units

Recommended Posts

Hi!

I'm trying to make the classname to decide what kind of equipment a soldier is carrying when spawned in to the game without using the init line. Cause it does not exist because they spawn in.

What I've done so far is experimenting with the INIT.SQF file but that might be the wrong one. But this is what I've done so far. Anyone know how?

if(isClass _unit == "O_Soldier_F") then
{
removeallweapons _unit;
removeheadgear _unit;
removevest _unit;
removebackpack _unit;
removeUniform _unit;
_unit unassignItem "NVGoggles";
_unit removeItem "NVGoggles";
};

Share this post


Link to post
Share on other sites

Class name and condition look correct, and assuming the rest also, just try typeOf in the condition instead of isClass (which serves to check config returns).

// make sure you keep track of the spawned unit for the variable "_unit" to work

if(typeOf _unit == "O_Soldier_F") then
{
removeallweapons _unit;
removeheadgear _unit;
removevest _unit;
removebackpack _unit;
removeUniform _unit;
_unit unassignItem "NVGoggles";
_unit removeItem "NVGoggles";
};

Share this post


Link to post
Share on other sites

It does not seam to work. The soldier have all hes gear on him.

_unit = _this select 0;

if(typeOf _unit == "O_Soldier_F") then
{
removeallweapons _unit;
removeheadgear _unit;
removevest _unit;
removebackpack _unit;
removeUniform _unit;
_unit unassignItem "NVGoggles";
_unit removeItem "NVGoggles";
};

Share this post


Link to post
Share on other sites

Doing something similar myself to switch over to massi's weapons.

I created a large trigger set to activate OFPOR Present, named it opforTrig and executed the following script from the init.sqf (You need a small delay for the trigger to initialize).

sleep 1;

{
removeAllWeapons _x;
removeHeadGear _x;

  if (typeOf _x == "O_Soldier_F") then
  {
     _x addMagazines ["30Rnd_mas_545x39_T_mag",10];
     _x addMagazines ["handGrenade",3];
     _x addWeapon "arifle_mas_ak_74m";
  };

  if (typeOf _x == "O_Soldier_AR_F") then
  {
     _x addMagazines ["100Rnd_mas_762x54_mag",6];
     _x addWeapon "LMG_mas_pkm_F";
  };

  if (typeOf _x == "O_Soldier_GL_F") then
  {
     _x addMagazines ["30Rnd_mas_762x39_T_mag",5];
     _x addMagazines ["1Rnd_HE_Grenade_shell",4];
     _x addWeapon "arifle_mas_akms_gl";
  };


} foreach list opforTrig;

Share this post


Link to post
Share on other sites

Put this in your init.sqf file:

// Wait until player has initialised
waitUntil {!isNull player};
waitUntil {player == player};

// Remove equipment
if(typeOf player == "O_Soldier_F") then {
removeallweapons player;
removeheadgear player;
removevest player;
removebackpack player;
removeUniform player;
player unassignItem "NVGoggles";
player removeItem "NVGoggles";
};

Notice how this is using player and not _unit. Since you have not defined what _unit is, the script will return an error and exit. However, player is a global variable that is pre-defined by Arma.

If you want to do the same but not for a player (i.e. AI), you could use a forEach loop. I'm assuming you want to run this script once to remove gear from all units (of a certain type). To do so you could put this in your init.sqf:

{
if(typeOf _x == "O_Soldier_F") then {
	removeallweapons _x;
	removeheadgear _x;
	removevest _x;
	removebackpack _x;
	removeUniform _x;
	_x unassignItem "NVGoggles";
	_x removeItem "NVGoggles";
};
} forEach allUnits;

_x is a substitute for each unit in allUnits. In other words, the loop will go through each unit one at a time (_x) and remove their gear.

Edited by JamieG

Share this post


Link to post
Share on other sites

init.sqf processing is automatic, you just need to have the file in the main mission folder.

(also try adding parenthesis in the condition)

_unit = _this select 0; // carefull with the scope of this

if((typeOf _unit) == "O_Soldier_F") then // notice the (typeOf _unit) making sure _unit == "O_Soldier_F" is not being tested before
{
removeallweapons _unit;
removeheadgear _unit;
removevest _unit;
removebackpack _unit;
removeUniform _unit;
_unit unassignItem "NVGoggles";
_unit removeItem "NVGoggles";
};

but your isse may be the:

_unit = _this select 0; // this should be empty at point in time, unless you did something else beyond what you have shown

Just name the unit in the 2D Editor with something like "AI1" and use that instead in the init.sqf

_unit = AI1;
//... rest of the code

Edit: ninja'ed and by an even more direct way

Share this post


Link to post
Share on other sites

_x is a substitute for each unit in allUnits. In other words, the loop will go through each unit one at a time (_x) and remove their gear.

Ahhh, this saves the need for a trigger. Nice one :rthumb:

Share this post


Link to post
Share on other sites

Is there a way to do something like this to make units spawned with a site/base module all have a lower skill rating rather than the max skill they spawn with?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×