Jump to content
Sign in to follow this  
RC Ironside

Script Help - Enemies Ignore Players Based on Uniform

Recommended Posts

I would like to create a "Trojan" mission where players must infiltrate an enemy encampment and retrieve a captive. I would like to script a way for the enemies to ignore (or assume friendly) the players if they are wearing certain garb. I would like to avoid using careless or setCaptive unless there is a way to trigger it off in the event they remove their uniforms or act in hostility. Thank you in advance.

Share this post


Link to post
Share on other sites

Thank you for the suggestions JShock. I've seen most of those and the closest one to my needs is the espionage script but unfortunately it's not MP compatible, which I guess I should have mentioned. Maizarak, there's nothing wrong with setCaptive except that the enemy won't respond if they're shot by someone with setCaptive and I'd like to make it particular to the uniform specifically. Ideally, I'd like to have the players setCaptive until they either aggress the enemies or remove the uniform.

Share this post


Link to post
Share on other sites

Define "aggressing", I figure shooting would be one way, I have an idea, just need more info.

Share this post


Link to post
Share on other sites

To keep it easy, shooting, damaging or killing would best define my intent.

Share this post


Link to post
Share on other sites

Ok try out the following, if the player fires a weapon that isn't apart of the approved list, then the setCaptive will be turned false, it will also check every time the player closes his/her inventory (assuming you will be picking the uniform off the ground or off a body) to see if the assigned uniform is the correct type of uniform, if it is, the player will be "invisible" to the enemy, if it's not, then the player won't be "invisible" to the enemy.

Make a file name initPlayerLocal.sqf and paste the following in it:

glb_approvedFiredItems = ["someClassname","someClassname2","someClassname3"];//stuff like chem lights, smoke, etc.

player addEventHandler
[
"Fired",
{
	if !((_this select 4) in glb_approvedFiredItems) then
	{
		(_this select 0) setCaptive false;
	};
}
];

player addEventHandler
[
"InventoryClosed",
{
	if (uniform (_this select 0) isEqualTo "UniformClassnameHere") then
	{
		(_this select 0) setCaptive true;
	}
	else
	{
		(_this select 0) setCaptive false;
	};
}
];

Fill out the "glb_approvedFiredItems" will the classnames of things as example, this is because the "Fired" EH will pick up on any thrown items as well, such as grenades, smoke, and chemlights.

And for the other things such as damaging/killing enemies, are all the enemies pre-spawned (as in placed via the editor) or are they spawned in via script?

If the "InventoryClosed" EH doesn't seem to be handling it the proper way replace it with the following:

[
"checkUniform",
"onEachFrame",
{
	if !(uniform (_this select 0) isEqualTo "UniformClassnameHere") then
	{
		(_this select 0) setCaptive false;
	}
	else
	{
		(_this select 0) setCaptive true;
	};
},
[player]
] call BIS_fnc_addStackedEventHandler;

Obviously replace "UniformClassnameHere" with the classname of whatever uniform.

*Note all is untested.

Edited by JShock

Share this post


Link to post
Share on other sites

Enemies will be editor placed. Thank you very much for this, I will be trying it out here shortly.

Share this post


Link to post
Share on other sites

Ok, I'm assuming that the "enemy" side is EAST, you can change that in the following if otherwise.

Create another file named, initServer.sqf and place the following:

waitUntil {time > 0};

{
if (side _x isEqualTo EAST) then
{
	_x addEventHandler
	[
		"HandleDamage",
		{
			if (isPlayer (_this select 3)) then
			{
				(_this select 3) setCaptive false;
			};
		}
	];
}
} forEach allUnits;

Share this post


Link to post
Share on other sites

The uniform portion has worked amazingly, thank you so much. The weapon, however doesn't seem to be working. No matter what weapon I fire around them, whether it's on the list or not, causes setCaptive to switch to false and they attack. Here is the example I'm using for testing with a CSAT rifleman, playing as a NATO rifleman:

glb_approvedFiredItems = ["arifle_Katiba_F"];//stuff like chem lights, smoke, etc.

player addEventHandler
[
   "Fired",
   {
       if !((_this select 4) in glb_approvedFiredItems) then
       {
           (_this select 0) setCaptive false;
       };
   }
];

player addEventHandler
[
   "InventoryClosed",
   {
       if (uniform (_this select 0) isEqualTo "U_O_CombatUniform_ocamo") then
       {
           (_this select 0) setCaptive true;
       }
       else
       {
           (_this select 0) setCaptive false;
       };
   }
]; 

Share this post


Link to post
Share on other sites

Sorry I was thinking of a thread from a few months back try:

player addEventHandler
[
"Fired",
{
	if !((_this select 1) in glb_approvedFiredItems) then
	{
		(_this select 0) setCaptive false;
	};
}
];

Share this post


Link to post
Share on other sites

This worked perfectly. Thank you very much for your help, it is much appreciated.

Share this post


Link to post
Share on other sites

Again, thank you for this fantastic script. I do have one question though. Would it be possible to add a parameter to this that bases the enemy detection of the player via distance? For example, setCaptive would be applied to the player wearing the allowed uniform as long as they stay 25m or more from an enemy. This would be to simulate the player getting too close and an enemy getting a good look at the player and realizing that he is in fact hostile? Thanks in advance.

Share this post


Link to post
Share on other sites

Try the following, the reason for the getVariable in the while loop condition is so there is a way for you to end the loop completely if you would like (would just need to re-execute the script on the player again to start the loop):

_radius = 25;//radius around the player to look for enemies
_side = EAST;//side of the units that are the "enemies"

while {player getVariable ["nearEnemyLoopCondition",true]} do
{
{
	if (_x knowsAbout player > 3 && {side _x isEqualTo _side} && {side player isEqualTo CIVILIAN}) exitWith
	{
		player setCaptive false;
	};
} count nearestObjects [player,["Man"],_radius];
sleep 5;
};

Share this post


Link to post
Share on other sites

Thanks. Last question before I give this a shot. Because my scripting powers are weak and subpar, or else I wouldn't be here, where do I put this? Haha.

Share this post


Link to post
Share on other sites

Make a .sqf file and put this in it, name the file something like "nearEnemyCheck.sqf", then in the initPlayerLocal.sqf that I had you create earlier put the following in it:

0 = [] execVM "nearEnemyCheck.sqf";

  • Thanks 1

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  

×