Jump to content
Grim5667

AddAction to every enemy that spawns.

Recommended Posts

Hey I have looked for a script that adds an action to the OPFOR unit everytime one of them spawns but could not find one. Would someone be willing to help to create one? I am new to scripting btw.

Share this post


Link to post
Share on other sites

How are you spawning your OPFOR guys in?  Via scripts, in the editor, in zeus, ...?

  • Like 1

Share this post


Link to post
Share on other sites
On 26/08/2018 at 4:27 PM, stanhope said:

How are you spawning your OPFOR guys in?  Via scripts, in the editor, in zeus, ...?

Ok i believe they are spawned in through script. All OPFOR will be spawned in at once. Maybe there a way to place down a invis marker that can grab the nearest units?

Share this post


Link to post
Share on other sites

If OPFOR are spawned throughout the mission and you can't directly create the addAction on them. You can add the action to the player and have some conditions there. If you can create addAction when they are spawning after createUnit then:

object addAction [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, radius, unconscious, selection, memoryPoint]

https://community.bistudio.com/wiki/addAction

What exactly do you want the action to do? You didn't say and not guessing so just customise it yourself. If you get stuck, just ask. All arguments are explained on the Wiki, see link above. Future tip: Please descriptive as possible when making post/thread. The first reply was @stanhope who was asking a basic question which should of been mentioned really in the first place. You don't have to show anything fancy or code. Plain words can go a long way. It just makes it easier for us people trying to help.

Share this post


Link to post
Share on other sites

0 = [] spawn {

  while {true} do {
{ _x addAction ["bla bla", {code},etc]; _x setVariable ["actionAdded",true] } forEach allUnits select {isNil {_x getVariable "actionAdded"} && side _x == EAST  }; // as you said east are enemies.

sleep 3

}};

 

Share this post


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

If OPFOR are spawned throughout the mission and you can't directly create the addAction on them. You can add the action to the player and have some conditions there. If you can create addAction when they are spawning after createUnit then:


object addAction [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, radius, unconscious, selection, memoryPoint]

https://community.bistudio.com/wiki/addAction

What exactly do you want the action to do? You didn't say and not guessing so just customise it yourself. If you get stuck, just ask. All arguments are explained on the Wiki, see link above. Future tip: Please descriptive as possible when making post/thread. The first reply was @stanhope who was asking a basic question which should of been mentioned really in the first place. You don't have to show anything fancy or code. Plain words can go a long way. It just makes it easier for us people trying to help.

Ahh ok will be more descriptive next time. The script is to "search" the OPFOR units for possibly intel and it can return with No Intel found or Intel found. 

 

1 hour ago, pierremgi said:

0 = [] spawn {

  while {true} do {
{ _x addAction ["bla bla", {code},etc]; _x setVariable ["actionAdded",true] } forEach allUnits select {isNil {_x getVariable "actionAdded"} && side _x == EAST  }; // as you said east are enemies.

sleep 3

}};

 

Ok ty will check if this works.
 

Edit: After a couple minutes with the code it works but it constantly shows the Search which i dont want and it would just stack up and if you did removeAllActions Player; It would still stack up on the enemies so I put it removeAllActions allUnits; . Which did work but would always show a search and would also show search twice when looking at the OPFOR unit.

Share this post


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

0 = [] spawn {

  while {true} do {
{ _x addAction ["bla bla", {code},etc]; _x setVariable ["actionAdded",true] } forEach allUnits select {isNil {_x getVariable "actionAdded"} && side _x == EAST  }; // as you said east are enemies.

sleep 3

}};

 

I do not recommend this approach. If you really need something like this, add the action the player.

  • Like 1

Share this post


Link to post
Share on other sites
20 minutes ago, HazJ said:

I do not recommend this approach. If you really need something like this, add the action the player.

Not mine. I just answered to the title. No clue what is for.

Share this post


Link to post
Share on other sites

standard method for this sort of thing is to add the action to the player object, and use the condition to hide/show it (such as when aiming at an enemy)

 

heres an example

 

my_condition = {
	private _return = false;
	_cursortarget = cursortarget;
	if (!isnull _cursortarget) then {
		if (_cursortarget iskindof 'camanbase') then {
			if ((side (group _cursortarget)) in (playerside call bis_fnc_enemysides)) then {
				if ((tolower (lifestate _cursortarget)) in ['healthy','injured']) then {
					_return = true;
				};
			};
		};
	};
	_return;
};
player addAction ['Enemy!',{hint (format ["Enemy! %1",diag_ticktime]);},nil,0,true,true,'','call my_condition',-1,false,'',''];
player addEventHandler [
	'Respawn',
	{
		player addAction ['Enemy!',{hint (format ["Enemy! %1",diag_ticktime]);},nil,0,true,true,'','call my_condition',-1,false,'',''];
	}
];

 

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites
13 hours ago, fn_Quiksilver said:

standard method for this sort of thing is to add the action to the player object, and use the condition to hide/show it (such as when aiming at an enemy)

 

heres an example

 


my_condition = {
	private _return = false;
	_cursortarget = cursortarget;
	if (!isnull _cursortarget) then {
		if (_cursortarget iskindof 'camanbase') then {
			if ((side (group _cursortarget)) in (playerside call bis_fnc_enemysides)) then {
				if ((tolower (lifestate _cursortarget)) in ['healthy','injured']) then {
					_return = true;
				};
			};
		};
	};
	_return;
};
player addAction ['Enemy!',{hint (format ["Enemy! %1",diag_ticktime]);},nil,0,true,true,'','call my_condition',-1,false,'',''];
player addEventHandler [
	'Respawn',
	{
		player addAction ['Enemy!',{hint (format ["Enemy! %1",diag_ticktime]);},nil,0,true,true,'','call my_condition',-1,false,'',''];
	}
];

 

Ahh thank you so much. This is just what I wanted.

  • Like 3

Share this post


Link to post
Share on other sites
On 28/08/2018 at 7:22 AM, fn_Quiksilver said:

standard method for this sort of thing is to add the action to the player object, and use the condition to hide/show it (such as when aiming at an enemy)

 

heres an example

 


my_condition = {
	private _return = false;
	_cursortarget = cursortarget;
	if (!isnull _cursortarget) then {
		if (_cursortarget iskindof 'camanbase') then {
			if ((side (group _cursortarget)) in (playerside call bis_fnc_enemysides)) then {
				if ((tolower (lifestate _cursortarget)) in ['healthy','injured']) then {
					_return = true;
				};
			};
		};
	};
	_return;
};
player addAction ['Enemy!',{hint (format ["Enemy! %1",diag_ticktime]);},nil,0,true,true,'','call my_condition',-1,false,'',''];
player addEventHandler [
	'Respawn',
	{
		player addAction ['Enemy!',{hint (format ["Enemy! %1",diag_ticktime]);},nil,0,true,true,'','call my_condition',-1,false,'',''];
	}
];

 

Hey is there a way to have the action show up on AAF too? 

Share this post


Link to post
Share on other sites

Shift AAF as enemy (in editor / attributes/general/misc)...

or change the condition: (side (group _cursortarget)) in (playerside call bis_fnc_enemysides)

for something else: (side _cursortarget != playerSide) ... but change the addAction title/hint: "not our side"

 

Share this post


Link to post
Share on other sites
11 hours ago, pierremgi said:

Shift AAF as enemy (in editor / attributes/general/misc)...

or change the condition: (side (group _cursortarget)) in (playerside call bis_fnc_enemysides)

for something else: (side _cursortarget != playerSide) ... but change the addAction title/hint: "not our side"

 

That wouldnt work because that means the action would show on the civs

Share this post


Link to post
Share on other sites

 

1 hour ago, Grim5667 said:

That wouldnt work because that means the action would show on the civs

add a condition.

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

×