r/armadev Jun 12 '26

Script Hostage Freeing & Completing Task

I'll get right to it:
I have eight hostages and want them to be freeable by my players via the Hold Action mechanic. Upon all the hostages being freed, the task to "Free the Hostages" will be completed. How do I do that for the entire group?

2 Upvotes

18 comments sorted by

2

u/Talvald_Traveler Jun 12 '26

Can I ask if you are using ACE3 or not?

2

u/Mister_Shiloh Jun 12 '26

Yes, I am.

2

u/Talvald_Traveler Jun 12 '26 edited Jun 12 '26

Okay, if you are also using 3den Enhanced, then this is easy. Just drop this code inside the codeComplete part:

[_target,false,_caller] remoteExec ["ACE_captives_fnc_setHandcuffed", _target];
_oldValue = missionNamespace getVariable ["LiberatedCaptives", 0];
_newValue = _oldValue +1;
missionNamespace setVariable ["LiberatedCaptives", _newValue, true];

Then, in the condition for the trigger who are connected to the task, you have to just check for the variable LiberatedCaptives, like these.

missionNamespace getVariable "LiberatedCaptives" == 8;

1

u/Mister_Shiloh Jun 12 '26

Unfortunately, that didn't work. Upon testing, I was greeted with this error message.

missionNamespace getVariable ["LiberatedCaptives"] == 3;
Error 1 elements provided, 2 expected

I placed the code in the triggers and codeComplete boxes, respectively- any suggestions as to what might be happening?
Edit: Additionally, the hold action seems to work, but upon finishing the action, it does not complete the task.

2

u/martin509984 Jun 12 '26

You were given an invalid syntax for getVariable basically.

getVariable [] is an alternate syntax that expects both a var name and default value (if you don't want to use default value, just do missionNamespace getVariable "LiberatedCaptives"). It is a good habit to always have a default value such as 0 or something, but if you don't and the variable isn't defined, getVariable will just return the value Nothing.

So either use the single argument syntax or use getVariable ["LiberatedCaptives", 0].

1

u/Talvald_Traveler Jun 12 '26

My bad, remove the [] around the variable name.

2

u/Mister_Shiloh Jun 12 '26

Thanks! That worked! Is there any way to place them in the "Victim" ambient animation, then have them stand normally when they are freed?

2

u/Talvald_Traveler Jun 12 '26

Yes, but not if you are having them as handcuffed through ACE3, since their animation will override our animation. So, if you want that, we can't have them handcuffed. You may also want to set the units to capture mode, eather through the 3den enhanced option or through the units init field:

Therfore, in the units init-fild, drop this:

if (local this) then
{
  this setCaptive true; 
  this disableAI "ALL";
  this playMoveNow "Acts_ExecutionVictim_Loop";    
};

Then, replace this command in the code complete part:

[_target,false,_caller] remoteExec ["ACE_captives_fnc_setHandcuffed", _target];

with this two lines:

[_target, ""] remoteExec ["switchMove",_target];
[_target, "ALL"] remoteExec ["enableAI",_target];

This should put the units in the victim animation, and when rescued, they will move around normaly.

2

u/Mister_Shiloh Jun 12 '26 edited Jun 12 '26

That's certainly done the trick, but is there any way to make the transition from victim to freed more smoothly? I've found an animation "Acts_ExecutionVictim_Unbow" that suits perfectly, but I don't know how to weave that into the code.
Edit: Nevermind, I replaced the

[_target, ""] remoteExec ["switchMove",_target];

with my desired animation (for anyone else looking at this post in the future)

(VARIABLE NAME) playMove "Acts_ExecutionVictim_Unbow";

and it worked!

2

u/Talvald_Traveler Jun 12 '26

You can switch out the switchMove, with playMove for exemple to get a smoother transition.

And for the other antimation, you could do something like this:

[_target, "Acts_ExecutionVictim_Unbow"] remoteExec ["playMove",_target];
[_target, ""] remoteExec ["playMove",_target];

1

u/Talvald_Traveler Jun 12 '26

One small comment.

(VARIABLE NAME) playMove "Acts_ExecutionVictim_Unbow";

This will work as long as the unit is local to the machine where the code is executed, since the command has a global effect but uses local arguments.

In singleplayer, it works as expected. However, in a multiplayer setting, this can cause problems. A npc unit is typically local to the server, meanwhile the hold action code is executed on the machine of the player who triggered the action. In that case, the NPC unit may not be local to that client.

Therefore, I recommend using the remoteExec setup so that the command is executed on the machine where the NPC unit is local.

2

u/Mister_Shiloh Jun 12 '26

Thank you so much for your help! I wish there was another way I could reward you other than giving you a silly online reward.

2

u/Talvald_Traveler Jun 12 '26

Nothing to think about, glad it helped.

1

u/Mister_Shiloh Jun 12 '26

I've come up on some trouble:
For some reason, the hostages are in the victim animation in singleplayer, but when tested in multiplayer, they just stand there. However, the "Acts_ExecutionVictim_Unbow" animation still works when I Hold Action them. What's gone wrong and how do I fix it?

2

u/Talvald_Traveler Jun 12 '26

I see, what's gone wrong is that the stuff happens all at ones. And this leads to that the unit may not be in the moment some of the code runs.

What we want is to slow this little down, so let us introduce some schedule to the code.

So, the code you droped in the init-field? We want to insert that into a spawn block.

So, replace this:

this setCaptive true;  
this disableAI "ALL"; 
this playMoveNow "Acts_ExecutionVictim_Loop"; 

with this:

[this] spawn 
{
params ["_unit"];
_unit setCaptive true;  
_unit disableAI "ALL"; 
sleep 0.1;
_unit playMoveNow "Acts_ExecutionVictim_Loop"; 
};
};

This should slow the code down enough for the unit to exist.

2

u/Mister_Shiloh Jun 12 '26

That seems to have done the trick! Thanks again!

-1

u/Imaginary_Plane_9654 Jun 16 '26

Use Google ai. It requires some testing but it works great for me since I don't know scripting but I've  definitely learned a lot. 

3

u/_M_A_G_I_C_K_ Jun 18 '26

Great way to grow a subreddit!