Jump to content
Sign in to follow this  
deltagamer

Restrict weapon fire if optic is not present?

Recommended Posts

Hi there,

I'm looking for some help with my current problem as I don't really have the knowledge on to deal with it. I recently got into weapon modding and so far I've had a lot of good progress with it however there is one thing I can't get right. I was hoping someone could help me out and show me how I could make my weapon only usable/fireable when there is an optic attached to it. This is currently for the FGM-148 Javelin with the optic being a CLU that can be attached to the weapon via the inventory like a traditional vanilla optic. If I could get some quick help with my situation that would be great as I'm hoping to achieve a weapon system similar to how Ace had it back in A2.

Thanks for any help.

Images of detachable optic

VmRODll.jpg

1ku2ytu.jpg

Share this post


Link to post
Share on other sites

Nothing to do with config, any weapon can be fired with or without an optic on as it currently stands in ARMA 3.

Seems more like you'd want to create a script along the lines of "If X is not present, do not allow weapon to fire. If X is present, Fire."

I know NOTHING about scripting though but I'd like to think that's the best line of possibility.

Share this post


Link to post
Share on other sites
I know NOTHING about scripting though but I'd like to think that's the best line of possibility.

This should be along the right line:

(findDisplay 46) displayAddEventHandler 
[
"KeyDown",
{
	_handled = false;

	if (currentWeapon player isEqualTo "Jav_Classname") then
	{
		if ((_this select 1) in (actionKeys "Fire") && {!("Jav_Optics_Classname" in (weaponAccessories player))}) then
		{
			hintSilent "You cannot fire without an optic.";
			_handled = true;
		};
	};
	_handled;
}
];

Every time the player goes to fire his weapon, if it's the javelin, it will check to see if the optic is present, if it's not, it will hint saying so and then do nothing.

Along the lines of a mod I believe all you would need to accomplish this is to add a postInit function that is ensured to run locally on the client, but mods/addons are not my line of work.

Share this post


Link to post
Share on other sites

Brilliant thanks for the response, I just need to find out how to test it now.

I tried this in my config to get it running however no luck so far. Would anyone be able to recommend how I get it to initiate when the player holds the weapon?

	class EventHandlers: DefaultEventhandlers
	{
	    init = "currentWeapon player execVM ""\3CB_JAVELIN\data\script\isCLUattached.sqf"";";
	};

---------- Post added at 00:42 ---------- Previous post was at 00:29 ----------

I don't think my above code will work, maybe I might need to go about doing it via CfgFunctions. Again I'm not too sure on how to do this so any help would be great.

Share this post


Link to post
Share on other sites

Yea I was thinking CfgFunctions initially:

class CfgFunctions
{
   class checkJavOptic {postInit = 1;};
};

Share this post


Link to post
Share on other sites

I had a look at how Cfgfunctions worked and I managed to get it working.

Here's my code,

Function

class CfgFunctions
{
class UK3CB
{
	tag="UK3CB"; // Custom tag name
	class checkJavOptic
	{
		file="3CB_JAVELIN\data\script"; // function will be loaded from this folder.
		class isCLUattached {}; // [currentWeapon player] call UK3CB_fnc_isCLUattached;
	};
};	
};

initiator

	onload = "['onLoad', currentWeapon Player] call UK3CB_fnc_isCLUattached;";

Now my only problem is I think there is an error with your initial script you gave me, I've managed to get the script loading in game however I'm getting this error message

Error

JU9QMlO.png

Here's the code that is giving me problems with it.

(findDisplay 46) displayAddEventHandler 
[
   "KeyDown",
   {
       _handled = false;

       if (currentWeapon player isEqualTo "UK3CB_Launcher_Loaded") then
       {
           if ((_this select 1) in (actionKeys "Fire") && {!("UK3CB_Javelin_CLU" in (weaponAccessories player))}) then
           {
               hintSilent "You cannot fire without an optic.";
               _handled = true;
           };
       };
       _handled;
   }
];  

Share this post


Link to post
Share on other sites
It's the syntax for weaponAccessories. It should be UNIT weaponAccessories WEAPON

https://community.bistudio.com/wiki/weaponAccessories

so something like:

if ((_this select 1) in (actionKeys "Fire") && {!("UK3CB_Javelin_CLU" in (player weaponAccessories (currentWeapon player)))}) then...

Thanks Das, kinda just mindstreamed that yesterday instead of checking usage :p.

Share this post


Link to post
Share on other sites

Thanks for all the help, I should be able to expand on this information to get what I was looking for :D

Share this post


Link to post
Share on other sites

Mh, modeling the javelin is a tough issue. Modelling the CLU as an optic means you can't use it without carrying a launch tube assembly. (In real-life, the CLU is apparently used as a recon tool because of it's high-power magnification and thermals + light weight construction).

However, modelling it as an optic allows you to easily deal with spent tubes: You just make the tube a "disposable" (@AGM feature) launcher, and then you can take of the CLU and drop the "empty tube" (fake launcher that can't reload) onto the ground.

That way the second guy in the javelin team (Who carries a LTA but not CLU) can simply grab a javelin without CLU and it's very simple to use.

Modelling the CLU as a weapon is closer to how it works in real-life. With the CLU as weapon, you can use it for recon + you don't have to worry about people using the LTA without a CLU attached.

Problems with this approach: The second guy wouldn't be able to carry the LTA (now a "magazine" type item) in his launcher slot, at least not without some creative workarounds. Also, the 'spent' LTA's tube would just vanish once you shoot. Not ideal either.

I'm sure there's a really elegant way to implement it to get the best of both worlds but I can't see it xD

EDIT: I wonder if something in the engine prevents one from making a single class both a binocular and an optic. AllowedSlots should make it possible to at least put an optic into the inventories bino slot.

If we could somehow Frankenstein together a CfgWeapons class that is both a binocular and an optic, that would probably provide the needed features. However I'm not sure if you can trick the engine into interpreting the same model/config one as a binocular and once as an optic.

PS: Hi there! Came across this thread randomly and then realized it was yours :)

Edited by ImperialAlex

Share this post


Link to post
Share on other sites

Yeah I really feel that the CLU as an optic would be a better approach, it looks nicer and works a bit better. I did consider the second option but as you said it causes some more problems with the weapon. I can remember there was an issue with agms medical supplies going into the binocular slot sometimes so I would guess it would be possible to have it as an optic and binocular. I already configured it to be usable as an binocular however its just figuring out how to make it work (seperate from the optic). It might be possible to do something like ace 2 but a little different. Maybe I could have a script that checks if the CLU is in the inventory of a player and if so then it adds an action called 'Use as binocular' which would replace the class name with a binocular item and then it can be used as a binocular and then replace the action with 'Use as optic' which will do the opposite. If you want we can speak about it later as its a feature I would like to see on the javelin.

Share this post


Link to post
Share on other sites
Maybe I could have a script that checks if the CLU is in the inventory of a player and if so then it adds an action called 'Use as binocular' which would replace the class name with a binocular item and then it can be used as a binocular and then replace the action with 'Use as optic' which will do the opposite. If you want we can speak about it later as its a feature I would like to see on the javelin.

Yeah, that's always an option, but if we can somehow trick the engine into using an optic as a binocular that'd be a much smoother and cooler experience.

Share this post


Link to post
Share on other sites

You could do another display EH to override the button press for "binoculars" if the CLU is the currently equiped whatever (that way it's not an action). Then just have the optic overlay come on, maybe you could play the action/animation of putting up binos to your eyes.

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
Sign in to follow this  

×