PDA

View Full Version : CLY Holster



Celery
Feb 25 2011, 21:55
It seems that a script like this could be useful for some people so here is a simple sidearm holstering script that I made for an SP mission. The script remembers the sidearm's classname and leaves the magazines intact. In theory it should work in team switching and respawn missions.

You can add a hidden sidearm at start with this setVariable ["CLY_holsteredgun","gunclassname",false]

cly_holster.sqs

;CLY Holster written by Celery
;Enables a player to holster and unholster his sidearm.
;
;Execute in the init script with [] exec "cly_holster"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

?isDedicated:exit

#start
@<hidden> player
?count _this>0:goto "holster"
_unit=player

?isNil {_unit getVariable "CLY_holsteredgun"}:_unit setVariable ["CLY_holsteredgun","",true]
_holster=_unit addAction ["Holster sidearm","cly_holster.sqs",nil,2.5,false,true,"","_this==_target and getNumber (configFile/'CfgWeapons'/(currentWeapon _this)/'type')==2 and _this getVariable 'CLY_holsteredgun'==''"]
_unholster=_unit addAction ["Unholster sidearm","cly_holster.sqs",nil,2.5,false,true,"","_this==_target and {getNumber (configFile/'CfgWeapons'/_x/'type')==2} count weapons _this==0 and _this getVariable 'CLY_holsteredgun'!=''"]

@<hidden>!alive _unit or _unit!=player
{_unit removeAction _x} forEach [_holster,_unholster]
?!alive _unit and _unit getVariable "CLY_holsteredgun"!="":_unit addWeapon _unit getVariable "CLY_holsteredgun";_unit setVariable ["CLY_holsteredgun",nil,true]
goto "start"

#holster
_unit=_this select 0
?isNil {_unit getVariable "CLY_holsteredgun"}:exit
?_unit getVariable "CLY_holsteredgun"!="":goto "unholster"

_gun=currentWeapon player
_type=getNumber (configFile/"CfgWeapons"/(currentWeapon player)/"type")
?_type!=2:exit

_unit setVariable ["CLY_holsteredgun",_gun,true]
_unit removeWeapon _gun
_unit addWeapon _gun
~0.5
_unit removeWeapon _gun
exit

#unholster
_gun=_unit getVariable "CLY_holsteredgun"
_unit addWeapon _gun
_unit selectWeapon _gun
_unit setVariable ["CLY_holsteredgun","",true]
exit

A known issue is that unholstering automatically loads the sidearm with the fullest magazine, but it's an engine limitation with no reasonable workaround.

ffur2007slx2_5
Feb 26 2011, 06:09
Good, I'll take a try. lol.

[DirTyDeeDs]-Ziggy-
Feb 26 2011, 06:32
thanks for sharing :x:

stephen271276
Feb 26 2011, 14:50
Cant seem to get it to work?
Keeps saying "CLY_holsteredgun" not found? when I try to holster it?
sample mission maybe?

Celery
Feb 26 2011, 15:41
Script improved by preventing multiple actions upon team switch and making actions exclusive to their owners.


Cant seem to get it to work?
Keeps saying "CLY_holsteredgun" not found? when I try to holster it?
sample mission maybe?
I couldn't reproduce such an error. You only need cly_holster.sqs in the mission folder and [] exec "cly_holster.sqs" in init.sqs/sqf.

stephen271276
Feb 26 2011, 16:00
got it working I was using it as an sqf file

SigintArmA
Feb 26 2011, 18:58
Ooo very useful :D Thanks man ^^

F2k Sel
Feb 26 2011, 19:37
Works fine, The gun did vanish a little to soon so I just increased the the delay a to ~1.5 and it looks fine now.


_unit setVariable ["CLY_holsteredgun",_gun,true]
_unit removeWeapon _gun
_unit addWeapon _gun
~1.5
_unit removeWeapon _gun
exit

Undeceived
Aug 8 2011, 22:56
Thanks for this, Celery! :) Useful as always! :)

Undeceived
Sep 1 2011, 23:44
Hi Celery, I have a bug to report.

When you have the pistol holstered and then go to an ammobox and mess around with other weapons (e.g. take a rifle), all pistol magazines will disappear.
This can be "deadly" as you somewhere down the road need the pistol but there are no mags left.

Is this possible to fix?
Would be great.

Btw. the script is well used in the campaign, I'm making atm. :)

Celery
Sep 2 2011, 09:14
Unfortunately that's a feature within the engine where all magazines in your gear that don't have a weapon present will change owners in the next gear transaction.

Undeceived
Nov 14 2011, 09:11
Too sad. :)
Because even though I always try to remember the pistol mags, I often forget to check them. :)

Anyway, a great script, I'm using it quite a lot in my new project.


EDIT: Oh, and another question that came up:

How can I make the gun being holstered scriptwise, so that I can make it hidden at the beginning of the mission?

Celery
Nov 14 2011, 09:57
How can I make the gun being holstered scriptwise, so that I can make it hidden at the beginning of the mission?

this setVariable ["CLY_holsteredgun","gunclassname"]

Undeceived
Nov 14 2011, 17:47
Hm, doesn't work... I tried to put this in the init.sqf, like:

player setVariable ["CLY_holsteredgun","M9"];

The holster script was launched 3 second before. The only thing that happens is that the action to holster the weapon disappears. But the pistol doesn't hide.



Can you also teach me how to do it when I don't know which sidearm the player will have (because I want to make a weapon selection in the briefing). Thanks a lot, man!

Celery
Nov 14 2011, 17:56
Hm, doesn't work... I tried to put this in the init.sqf, like:

player setVariable ["CLY_holsteredgun","M9"];

The holster script was launched 3 second before. The only thing that happens is that the action to holster the weapon disappears. But the pistol doesn't hide.
The unit isn't supposed to have that weapon in his gear if you mean it to be already hidden. If you want to choose your pistol first, get the classname of the handgun 0.1 seconds after mission start, set it as the holsteredgun variable and delete the gun it from the player.

Undeceived
Nov 14 2011, 21:41
Ah, ok, I got it.
Thanks, it works.