Jump to content
TheBombDoctor

How to force AI to holster weapons?

Recommended Posts

Hello everyone! I have a bit of a dilemma that I tried to resolve myself, but have not been successful. I have created an AI to be an indoor guard, armed with just a pistol. My issue is I want his pistol holstered. He won't be a member of a group so I am not concerned with his squad leader giving him orders to draw it.

 

I have just copy and pasted his loadout into his init at this point. No sqf made yet. 

 

I referenced these links but have not found my answer.

 

https://forums.bistudio.com/topic/169677-weapon-on-back-script-for-arma-3/

 

https://forums.bistudio.com/topic/183316-keep-pistol-in-holster-when-unit-does-not-have-a-primary-weapon/

 

I have this in his init field right now, immediately following the last line of his loadout.

this action ["SwitchWeapon", this, this, -1];

He just stands there with his stupid AI smug face and points his pistol at me.

 

Do I have the syntax right? I'd like to have this resolved as soon as I can. 

 

Thank you all for your time.

Share this post


Link to post
Share on other sites

I think the (muzzle selection) -1 is wrong, maybe it should be 0 or left out. Some of the examples used the number 100.  I got it working, but I'm not a my home computer to check right now. Can check it later in the day.

Share this post


Link to post
Share on other sites

SAFE behaviour is not a required condition. When I need an NPC healing medic, I just plop down a medic in the editor and attach some code for holstering weapons and action for healing and that's it. The units behaviour is then the default AWARE.

Share this post


Link to post
Share on other sites

I think the (muzzle selection) -1 is wrong, maybe it should be 0 or left out. Some of the examples used the number 100.  I got it working, but I'm not a my home computer to check right now. Can check it later in the day.

 

I omitted the number completely and got an error expecting 4 args and only receiving 3.

 

I added a zero, and nothing changed. Here is the entire init:

this setBehaviour "Safe"; comment "Remove existing items"; 
removeAllWeapons this; 
removeAllItems this; 
removeAllAssignedItems this; 
removeUniform this; 
removeVest this; 
removeBackpack this; 
removeHeadgear this; 
removeGoggles this; 
 
comment "Add containers"; 
this forceAddUniform "CUP_U_O_RUS_EMR_1"; 
this addItemToUniform "FirstAidKit"; 
for "_i" from 1 to 2 do {this addItemToUniform "16Rnd_9x21_Mag";}; 
this addVest "V_Rangemaster_belt"; 
this addItemToVest "FirstAidKit"; 
for "_i" from 1 to 4 do {this addItemToVest "16Rnd_9x21_Mag";}; 
for "_i" from 1 to 2 do {this addItemToVest "Chemlight_red";}; 
this addItemToVest "SmokeShellRed"; 
this addHeadgear "H_Cap_oli"; 
 
comment "Add weapons"; 
this addWeapon "hgun_Rook40_F"; 
 
comment "Add items"; 
this linkItem "ItemMap"; 
this linkItem "ItemCompass"; 
this linkItem "ItemWatch"; 
this linkItem "ItemRadio"; 

this action ["SwitchWeapon", this, this, 0];

I have already tried "Safe" as you can see above, and that effected nothing. Thanks though.

Share this post


Link to post
Share on other sites

I omitted the number completely and got an error expecting 4 args and only receiving 3.

 

did u try nil as argument?

Share this post


Link to post
Share on other sites

A wild guess but can it be that the code runs too early to take effect? Try wrapping the action code in a spawn with a slight delay.

  • Like 1

Share this post


Link to post
Share on other sites

Just tested:

 

- plop a unit down in the editor

- add this to init:

 

this removeWeapon (primaryWeapon this); null = [this] spawn {_unit = (_this select 0); sleep 1; _unit action ['SwitchWeapon', _unit, _unit, 100];};

Share this post


Link to post
Share on other sites

There is also this 

 

player action ["WeaponOnBack", player];

Share this post


Link to post
Share on other sites

Just tested:

 

- plop a unit down in the editor

- add this to init:

 

this removeWeapon (primaryWeapon this); null = [this] spawn {_unit = (_this select 0); sleep 1; _unit action ['SwitchWeapon', _unit, _unit, 100];};

 That did the trick. Thanks man! You're a god.

Share this post


Link to post
Share on other sites

Don't want to needlessly necro a thread, but since this is still relevant.. Joostsidy, would you like to explain that piece of code there for me? It worked, but I'd like to understand what I'm doing rather than just copy paste.

Edited by Lauri Hirn

Share this post


Link to post
Share on other sites
On 1/23/2019 at 6:31 PM, Lauri Hirn said:

Don't want to needlessly necro a thread, but since this is still relevant.. Joostsidy, would you like to explain that piece of code there for me? It worked, but I'd like to understand what I'm doing rather than just copy paste.

 

Sure, here is the same thing, broken down and explained a little:
 

this removeWeapon (primaryWeapon this); 

null = [this] spawn 					
{
	_unit = (_this select 0); 			
	sleep 1;							
	_unit action ['SwitchWeapon', _unit, _unit, 100]; 
};													  

// this (the player in this case) remove rifle, the unit will automatically draw pistol
// create (spawn) a little script on the fly, no name (handle) is necessary so it's called 'null' (nothing): no handle is created 
// the first (and only) parameter 'this' (the player) is assigned to the variable '_unit'
// wait a second to give the game a chance to do rifle removement and pistol drawing
// _unit do switchweapon action by yourself on yourself on weapon ('muzzle') nr. 100 which does not exist which results in holstering current weapon

// the game only understands that 'this' is the player because the code is run from the player's init

More info on: switchweapon

 

If you think the switchweapon action is weird and hard to understand, it's not you, it's supposed to be this way. ;-)

 

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

×