Jump to content

Recommended Posts

3 hours ago, black_hawk_mw2_87 said:

Hello, community!

If I am right, I can put this code inside AI's init field, while he's asleep (caused by the script) and when I go to him, I will be given the option (by scrolling up/down the mouse) to wake him up... 🙂

 

I can say it works like a charme, i have just changed the "(_target distance _this) < 3" to "(_target distance _this) < 2"

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On ‎8‎/‎22‎/‎2019 at 2:36 PM, beno_83au said:

@black_hawk_mw2_87 Give it a go, it should work just fine.

It actually works pretty well. I have done some testing and I really like this option. I use the interact action that is given to me to wake the AIs and it all works perfectly. But how about if that is a task? I have been ordered to go to the barracks and wake up my comrades. How would I complete such a task using this option at the same time? Would it be a script that checks for this current addAction or if it is complete? Would you help me with that? 🙂

Share this post


Link to post
Share on other sites
56 minutes ago, black_hawk_mw2_87 said:

It actually works pretty well. I have done some testing and I really like this option. I use the interact action that is given to me to wake the AIs and it all works perfectly. But how about if that is a task? I have been ordered to go to the barracks and wake up my comrades. How would I complete such a task using this option at the same time? Would it be a script that checks for this current addAction or if it is complete? Would you help me with that? 🙂

@GEORGE FLOROS GR, what would you say about this? 🙂

  • Like 1

Share this post


Link to post
Share on other sites

@black_hawk_mw2_87 How are you creating the tasks? If it's through the editor modules then it can be done easily but I prefer a scripted approach. You can use BIS_fnc_taskCreate to create the task then inside the addAction's code use BIS_fnc_taskSetState to compete the task when the action is used.

 

Example:

this addAction [
	"<t color='#88B985' shadow='2'>Wake Up</t>",
	{
		params ["_target","_caller","_actionID","_arguments"];
		nul = [_target,"Auto",true] spawn MIL_fnc_WakeUp;
		_target removeAction _actionID;
		["task_1","SUCCEEDED",true] call BIS_fnc_taskSetState;
	},
	nil,
	6,
	true,
	true,
	"",
	"(_target distance _this) < 3"
];

 

  • Like 1

Share this post


Link to post
Share on other sites
16 minutes ago, beno_83au said:

@black_hawk_mw2_87 How are you creating the tasks? If it's through the editor modules then it can be done easily but I prefer a scripted approach. You can use BIS_fnc_taskCreate to create the task then inside the addAction's code use BIS_fnc_taskSetState to compete the task when the action is used. 

@beno_83au, thank you for your response. I use the editor modules to create tasks. How would I compete one when I use the addAction script? 🙂 And how about the second way? Would you input a simple task example inside the script so I can rework its description,  according to my mission needs? 🙂

Share this post


Link to post
Share on other sites
6 minutes ago, black_hawk_mw2_87 said:

@beno_83au, thank you for your response. I use the editor modules to create tasks. How would I compete one when I use the addAction script? 🙂 And how about the second way? Would you input a simple task example inside the script so I can rework its description,  according to my mission needs? 🙂

You got lucky, I'm just loading ArmA up now so i can have a look at the modules. But I edited my response and added an example so check that out for now.

  • Like 1

Share this post


Link to post
Share on other sites
5 minutes ago, beno_83au said:

You got lucky, I'm just loading ArmA up now so i can have a look at the modules. But I edited my response and added an example so check that out for now.

Thanks for the answer, dude! 🙂 I will be happy to expect an example of this extension of the script, if you have time to create a working one. It will be useful to all users of the code, who'd like to have another good option to use it with. Thank you in advance. 🙂

  • Like 1

Share this post


Link to post
Share on other sites

@black_hawk_mw2_87 To use the modules, just place the "Create Task" module, then name it using the "Task ID" field (e.g. task_1), as well as editing any of the other fields to name, describe and adjust the task's options to suit your needs. Then, using this code that I posted above, the task will be completed once you use the action:

this addAction [
	"<t color='#88B985' shadow='2'>Wake Up</t>",
	{
		params ["_target","_caller","_actionID","_arguments"];
		nul = [_target,"Auto",true] spawn MIL_fnc_WakeUp;
		_target removeAction _actionID;
		["task_1","SUCCEEDED",true] call BIS_fnc_taskSetState;	//task_1 -> Task ID from the Create Task module
	},
	nil,
	6,
	true,
	true,
	"",
	"(_target distance _this) < 3"
];

If you're not sure about all the options in the create task module just fiddle and experiment with them, most of the options have tooltips to help out too. But I also just realised you probably need this to work for a group of units that you're waking up? So are you waking them up one-by-one or are you just wanting to wake all of them up in one go?

 

I'll look at adding an option to add an action for waking up units as part of the script too. Not a bad idea, cheers. 👍

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, beno_83au said:

@black_hawk_mw2_87 To use the modules, just place the "Create Task" module, then name it using the "Task ID" field (e.g. task_1), as well as editing any of the other fields to name, describe and adjust the task's options to suit your needs. Then, using this code that I posted above, the task will be completed once you use the action:


this addAction [
	"<t color='#88B985' shadow='2'>Wake Up</t>",
	{
		params ["_target","_caller","_actionID","_arguments"];
		nul = [_target,"Auto",true] spawn MIL_fnc_WakeUp;
		_target removeAction _actionID;
		["task_1","SUCCEEDED",true] call BIS_fnc_taskSetState;	//task_1 -> Task ID from the Create Task module
	},
	nil,
	6,
	true,
	true,
	"",
	"(_target distance _this) < 3"
];

If you're not sure about all the options in the create task module just fiddle and experiment with them, most of the options have tooltips to help out too. But I also just realised you probably need this to work for a group of units that you're waking up? So are you waking them up one-by-one or are you just wanting to wake all of them up in one go?

 

I'll look at adding an option to add an action for waking up units as part of the script too. Not a bad idea, cheers. 👍

Cheers, mate. We actually have 2 opportunities here - a script for all of the AI units at once, when it is checked that all of them are awake or one by one. I have tested this script with the addAction option last night and I was able to wake them up one after another. They were not in a group, separated from each other. And I suppose this would be the better option. Imagine they are a whole squad sleeping in the barracks and you come in the middle of the night to warn them for an incoming threat. According to the script, every single one of the AIs has been named: unit1, unit2, unit3. In my case, it is 3 of them. Good luck and thank you for the answers. 🙂

Share this post


Link to post
Share on other sites

I have tried the option above, but the AIs are not asleep anymore and when I put the addAction script in the init fields, there is an error in the expression. The normal script works, but the new one, setting a task state, won't... Although I have manually created a task with Task ID: task_1.

Share this post


Link to post
Share on other sites
44 minutes ago, black_hawk_mw2_87 said:

I have tried the option above, but the AIs are not asleep anymore and when I put the addAction script in the init fields, there is an error in the expression. The normal script works, but the new one, setting a task state, won't... Although I have manually created a task with Task ID: task_1.

 

The error from the init field would be caused by the commented out text, so remove "//task_1 -> Task ID from the Create Task module" from the code.

  • Like 1

Share this post


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

@black_hawk_mw2_87 To use the modules, just place the "Create Task" module, then name it using the "Task ID" field (e.g. task_1), as well as editing any of the other fields to name, describe and adjust the task's options to suit your needs. Then, using this code that I posted above, the task will be completed once you use the action:


this addAction [
	"<t color='#88B985' shadow='2'>Wake Up</t>",
	{
		params ["_target","_caller","_actionID","_arguments"];
		nul = [_target,"Auto",true] spawn MIL_fnc_WakeUp;
		_target removeAction _actionID;
		["task_1","SUCCEEDED",true] call BIS_fnc_taskSetState;	//task_1 -> Task ID from the Create Task module
	},
	nil,
	6,
	true,
	true,
	"",
	"(_target distance _this) < 3"
];

If you're not sure about all the options in the create task module just fiddle and experiment with them, most of the options have tooltips to help out too. But I also just realised you probably need this to work for a group of units that you're waking up? So are you waking them up one-by-one or are you just wanting to wake all of them up in one go?

 

I'll look at adding an option to add an action for waking up units as part of the script too. Not a bad idea, cheers. 👍

HaHa why did i not think of asking you Beno, to make it work with a Task.

I have made a trigger over the bed and when the unit is out off the trigger the task module makes it completed, but i can see if you put it inside the AddAction it is more simple. 

I think i will try this in my mission.

Thanks black_hawk_mw2_87 for asking the question 

Thanks Beno for answering 

  • Like 2

Share this post


Link to post
Share on other sites

Hello, everyone. Let me share a tricky way to make it work. Imagine you need to enter the military barracks and wake up everyone in order to warm them up. Place 3 soldiers and 3 sleeping mats underneath them. The script, in this case, works for 3 AIs. The one, who is on the opposite site, far from you when you enter the building, is the one to complete the task. Put all needed folders the way it has to be done and it is said in the manual. Use "unit1", "unit2" and "unit3" for the AIs. Create a task with Task ID: task_1. Use a condition of your choice, for example: true and X second delay in order to activate the task after X seconds when the mission starts. Put this code inside both unit1 and unit2 (in the init field):

this addAction [
	"<t color='#88B985' shadow='2'>Wake Up</t>",
	{
		params ["_target","_caller","_actionID","_arguments"];
		nul = [_target,"Auto",true] spawn MIL_fnc_WakeUp;
		_target removeAction _actionID;
	},
	nil,
	6,
	true,
	true,
	"",
	"(_target distance _this) < 3"
];

Then, in the init field of unit3:

this addAction [ 
 "<t color='#88B985' shadow='2'>Wake Up</t>", 
 { 
  params ["_target","_caller","_actionID","_arguments"]; 
  nul = [_target,"Auto",true] spawn MIL_fnc_WakeUp; 
  _target removeAction _actionID; 
  ["task_1","SUCCEEDED",true] call BIS_fnc_taskSetState; }, 
 nil, 
 6, 
 true, 
 true, 
 "", 
 "(_target distance _this) < 3" 
];

So, when you start the mission, the problem with the not sleeping Ai, will not occure. Like it happened several times while I was testing the scenario. They will be all asleep like drunk. Once the last AI is awake, the task will be completed! Voila! 🙂 And CHEERS! 🙂 You can always use your imagination and place the third unit in an isolated room somewhere around to make the player find him after the others. Good luck with your mission making, folks! 🙂

Share this post


Link to post
Share on other sites

@black_hawk_mw2_87 Now that I'm not as worn out/tired, there is a more fool-proof way for you to have the task completed. In your init.sqf (or even in any object's init field in the editor) put:

nul = [] spawn {
	private _units = [unit1,unit2,unit3];
	MIL_asleep = count _units;
	waitUntil {MIL_asleep == 0};
 	["task_1","SUCCEEDED",true] call BIS_fnc_taskSetState;
};

 

Then, each unit's init just needs the action added to it:

this addAction [
	"<t color='#88B985' shadow='2'>Wake Up</t>",
	{
		params ["_target","_caller","_actionID","_arguments"];
		nul = [_target,"Auto",true] spawn MIL_fnc_WakeUp;
		_target removeAction _actionID;
		MIL_asleep = MIL_asleep - 1;
	},
	nil,
	6,
	true,
	true,
	"",
	"(_target distance _this) < 3"
];

 

This way, each unit being woken up will reduce MIL_asleep by 1, and when it reaches 0 the task will be completed. Feel free to add/remove units from _units in the first code box to change the amount of units needing to be woken up.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
On 8/27/2019 at 8:15 AM, beno_83au said:

@black_hawk_mw2_87 Now that I'm not as worn out/tired, there is a more fool-proof way for you to have the task completed. In your init.sqf (or even in any object's init field in the editor) put:


nul = [] spawn {
	private _units = [unit1,unit2,unit3];
	MIL_asleep = count _units;
	waitUntil {MIL_asleep == 0};
 	["task_1","SUCCEEDED",true] call BIS_fnc_taskSetState;
};

 

Then, each unit's init just needs the action added to it:


this addAction [
	"<t color='#88B985' shadow='2'>Wake Up</t>",
	{
		params ["_target","_caller","_actionID","_arguments"];
		nul = [_target,"Auto",true] spawn MIL_fnc_WakeUp;
		_target removeAction _actionID;
		MIL_asleep = MIL_asleep - 1;
	},
	nil,
	6,
	true,
	true,
	"",
	"(_target distance _this) < 3"
];

 

This way, each unit being woken up will reduce MIL_asleep by 1, and when it reaches 0 the task will be completed. Feel free to add/remove units from _units in the first code box to change the amount of units needing to be woken up.

I will test it this way as well when I am home. 🙂 So, you are saying, that I can add more AIs to the list inside the script's description and when I wake up enough of them (or all of them) it should do the trick for me as well?

Share this post


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

So, you are saying, that I can add more AIs to the list inside the script's description

Yep. It counts and saves how many are in the list and then each time the action is used it subtracts 1 from the count. When the count hits 0, the task is completed.

 

1 hour ago, black_hawk_mw2_87 said:

when I wake up enough of them (or all of them) it should do the trick for me as well?

Yeah, once you've woken up all of them.

  • Like 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

×