TheBombDoctor 10 Posted May 11, 2016 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
joostsidy 685 Posted May 12, 2016 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
Grumpy Old Man 3547 Posted May 12, 2016 AI should holster sidearms in safe behaviour. Cheers Share this post Link to post Share on other sites
joostsidy 685 Posted May 12, 2016 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
TheBombDoctor 10 Posted May 12, 2016 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
sarogahtyp 1109 Posted May 12, 2016 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
mrcurry 511 Posted May 12, 2016 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. 1 Share this post Link to post Share on other sites
joostsidy 685 Posted May 12, 2016 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
soolie 189 Posted May 12, 2016 There is also this player action ["WeaponOnBack", player]; Share this post Link to post Share on other sites
TheBombDoctor 10 Posted May 13, 2016 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
Guest Posted January 23, 2019 (edited) 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 January 23, 2019 by Guest Share this post Link to post Share on other sites
joostsidy 685 Posted January 25, 2019 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. ;-) 1 Share this post Link to post Share on other sites
lsk323941 11 Posted May 2, 2019 Hello friend, how do you do AI puts the rifle on his back without it disappearing? Share this post Link to post Share on other sites
joostsidy 685 Posted May 2, 2019 7 hours ago, lsk323941 said: Hello friend, how do you do AI puts the rifle on his back without it disappearing? Hi Friend! turn off your mods. 🙂 In default Arma the rifle should not disappear. Share this post Link to post Share on other sites
ICE_PIC_JAPAN 7 Posted April 17, 2021 hello guyz! I used the following script. this removeWeapon (primaryWeapon this); null = [this] spawn {_unit = (_this select 0); sleep 1; _unit action ['SwitchWeapon', _unit, _unit, 100];}; yes, i could make units and player forced to holster weapons. but my mp5 disappeared and select handgun disappeared from menu on the top left. I could see my hand gun when i open inventory, but still couldnt use it. and units couldnt take handguns from holster even if they encountered enemies. plz tell me how to take handguns from holsters again after holster weapons. ps. can i do this not only 1 units but also for group? Share this post Link to post Share on other sites