Jump to content
NebelNexus

How do I add\remove gear to\from all OPFOR units placed by Zeus or by script?

Recommended Posts

I'm working on a mission set in Chernarus where CDF battles ChDKZ, and I'd like to have every Chedaki guy wearing a balaclava.  By having the initServer.sqf run

 

{if (side _x == East) then {_x addGoggles (selectRandom ["rhs_balaclava", "rhs_balaclava1_olive"]}} forEach (allUnits);

every editor-placed OPFOR unit has their nice balaclava without problems. However, since the mission will be played in multiplayer, a player managing Zeus will be adding more OPFOR units as needed. The code above, however, doesn't work for them, nor does it work for any OPFOR spawned via script, as expected. I've subsequently tried with something like

 

while {true} do {

{If ((side _x == East) and !((goggles _x) isEqualTo [""rhs_balaclava", "rhs_balaclava1_olive"])) Then {_x addGoggles (selectRandom [""rhs_balaclava", "rhs_balaclava1_olive"])}} forEach (allUnits);

 };

This seems to work even with OPFORs spawned via script. Balaclavas, however, appear to be "flashing" on the soldiers' heads: I assume this is happening because they are constantly being added to them, and I also suspect this would kill the overall performance in a real multiplayer game. I understand there's no real purpose on this one but aesthetics, however I would really love to know how to do it best, because with minor changes a script of this kind could be used to remove or add NVGs to AIs and such.

Thanks in advice for your replies!

Share this post


Link to post
Share on other sites

Oh man what you are doing!!

Basically loops like while is an finality. We use it if we have no other possibility and only for catch some event.

If you want to change something on new spawned unit by zeus you need use curatorObjectPlaced eventhandler

Share this post


Link to post
Share on other sites

Specific for glasses, headwear in editor:

You can check the bug. Try without Zeus:

Try in SP, then MP preview:

In vanilla map, place a squad group, all units playable.
With edit loadout, modify the player's inventory, everything you want, and add glasses (facewear), tactical shades, balaclavas or else.

Now, in SP preview, what ever character you play, the modified facewear is not displayed (no glasses on it). If you switch, the result concerns only the modified unit. So not "player related".

In MP preview, it's different, (both hosted and client):
add the respawn "switch on side team" (switch on group team is not fine, see feedback)
Each time you switch on a unit, this unit loose his glasses if any (medic,grenadier...).
Here it's related to player(s).

 

 

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

Specific for glasses, headwear in editor:

You can check the bug. Try without Zeus:

In SP then MP preview:

In vanilla map, place a squad group, all units playable.
With edit loadout, modify the player's inventory, everything you want, and add glasses (facewear), tactical shades, balaclavas or else.

Now, in SP preview, what ever character you play, the modified facewear is not displayed (no glasses on it). If you switch, the result concerns only the modified unit. So not "player related".

In MP preview, it's different, (both hosted and client):
add the respawn "switch on side team" (switch on group team is not fine, see feedback)
Each time you switch on a unit, this unit loose his glasses if any (medic,grenadier...).
Here it's related to player(s).

 

 

Maybe I've misunderstood something, but I don't think I'll have to mess with players and player-related event handlers, because Chedakis aren't meant to be playable in the mission, they're just the AIs. CDF is the playable faction, and I don't need anything special for them. 

1 hour ago, davidoss said:

Oh man what you are doing!!

Basically loops like while is an finality. We use it if we have no other possibility and only for catch some event.

If you want to change something on new spawned unit by zeus you need use curatorObjectPlaced eventhandler

Yup, I did something quite bad, but it was a last ditch attempt just to see how things behaved. They worked, kind of, but since I knew it was like dropping a nuke to kill a mosquito, I thought I'd ask.

1 hour ago, Mr H. said:

If it's just for units placed by zeus use the curatorObjectPlaced event handler:
https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#CuratorObjectPlaced

Thanks to both for bringing that one event handler to my attention. I had double checked  the Biki list but still missed it, probably because  I was looking for "Zeus", but it's referred to as "Curator"  when it comes to scripts.

 

Could you guys help me to set it up? I know how to have it run code,  but I'm unsure as to where I should put it to make it work.

Share this post


Link to post
Share on other sites

1.

add in description.ext:

class CfgUnitTemplates
{
	class balaclavaReplace
	{
		facewearList[] =
		{
			"rhs_balaclava",
			"rhs_balaclava1_olive"
		};
	};
};

2.In init.sqf

if (hasInterface) then {
	private _zeus = (allMissionObjects "ModuleCurator_F") select 0;

	_zeus addEventHandler ["CuratorObjectPlaced", {
		params ["_curator", "_entity"];
		
		if (_entity isKindOf "Man" && {(side (group _entity)) isEqualTo EAST}) then {
			[_entity,  "balaclavaReplace"] call BIS_fnc_unitHeadgear;
		};
		
	}];
};

 

Share this post


Link to post
Share on other sites
47 minutes ago, NebelNexus said:

Maybe I've misunderstood something, but I don't think I'll have to mess with players and player-related event handlers, because Chedakis aren't meant to be playable in the mission, they're just the AIs. CDF is the playable faction, and I don't need anything special for them.

 

I didn't speak about EH or else. I just gave you a very basic "way to reproduce" this bug related to glasses/facewear. So, imho, whatever you attempt, all glasses are bugged, depending on played unit and/or customized loadout. Not saying all AIs lost their glasses, just saying that occurs 100% with mentioned conditions for vanilla test.

Share this post


Link to post
Share on other sites
1 hour ago, davidoss said:

1.

add in description.ext:


class CfgUnitTemplates
{
	class balaclavaReplace
	{
		facewearList[] =
		{
			"rhs_balaclava",
			"rhs_balaclava1_olive"
		};
	};
};

2.In init.sqf


if (hasInterface) then {
	private _zeus = (allMissionObjects "ModuleCurator_F") select 0;

	_zeus addEventHandler ["CuratorObjectPlaced", {
		params ["_curator", "_entity"];
		
		if (_entity isKindOf "Man" && {(side (group _entity)) isEqualTo EAST}) then {
			[_entity,  "balaclavaReplace"] call BIS_fnc_unitHeadgear;
		};
		
	}];
};

 

Thanks a bunch! It seems to work like a charm. Just a quick question so I can improve my understanding of the whole: you have to run the EH-related bit of the code on the normal init.sqf because units placed by a Zeus are local while he's doing his thing?

1 hour ago, pierremgi said:

 

I didn't speak about EH or else. I just gave you a very basic "way to reproduce" this bug related to glasses/facewear. So, imho, whatever you attempt, all glasses are bugged, depending on played unit and/or customized loadout. Not saying all AIs lost their glasses, just saying that occurs 100% with mentioned conditions for vanilla test.

I see, in a couple days I'll be able to test all of it in real multiplayer scenario and see how it goes.

Share this post


Link to post
Share on other sites

local to the curator who ever this will become.

It will be executed only where curator is local (on the computer of who is in control of it). All curator event handlers are local and have a global effect.

You can also place the event handler inside init field of zeus module without defining module, like this:

this addEventHandler ["CuratorObjectPlaced", {
		params ["_curator", "_entity"];
		
		if (_entity isKindOf "Man" && {(side (group _entity)) isEqualTo EAST}) then {
			[_entity,  "balaclavaReplace"] call BIS_fnc_unitHeadgear;
		};
		
	}];

I just use init.sqf to keep explanation short .-)

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

×