Jump to content
Kleine Bea

Disable Firing key? (safeZone)

Recommended Posts

Hey i would like to make an savezone and the last part what i need is a line whch disable weapon firing or something to prevent ppl shooting in the are

 

I testet this cod

blockedkeys = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1 in [17,30,31,32])) then { true }"];

 

But i cant finde the key number for Action key or firning(left mous button)

 

someone know how to do that or know the key cod ?

 

Share this post


Link to post
Share on other sites

Not possible as such I don't think. You can use addAction with key which overrides the Fire click. @fn_Quiksilver did it in his Apex I&A mission. The files are on GitHub so maybe you can take a look at how he did it.

https://github.com/auQuiksilver/Apex-Framework

The action would show though. You could try to use inGameUISetEventHandler to hide it somehow.

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

Share this post


Link to post
Share on other sites

Something like: (credit goes to @fn_Quiksilver)

weaponSafety = player addAction ["Weapon safety on", {hintSilent "HELL NO";}, [], 0, false, false, "DefaultAction", ""];

// you can remove it when out of safezone like so
player removeAction weaponSafety;

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

The addAction-way has nothing to do with the problem at hand.

I'd rather attach a FiredMan-EventHandler to the player to delete the projectile. https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#FiredMan

That way players still can shoot, but nothing will come out of the barrel. You can check if the player is in a certain area within the EVH for it to have effect, or remove it, if the player leaves an area.

Share this post


Link to post
Share on other sites
45 minutes ago, Belbo said:

The addAction-way has nothing to do with the problem at hand.

I'd rather attach a FiredMan-EventHandler to the player to delete the projectile. https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#FiredMan

That way players still can shoot, but nothing will come out of the barrel. You can check if the player is in a certain area within the EVH for it to have effect, or remove it, if the player leaves an area.

 

Isn't it better to prevent the player from actually firing instead of deleting every fired projectile, since it was also the original request?

Probably a more aesthetic solution rather than having players running around the base firing on full-auto without hurting anyone.

 

@Kleine Bea:

 

If you plan on having your base attacked it could be useful to handle the enforcement of the safezone via a global variable, so into the initPlayerLocal.sqf inside your mission root put this:

TAG_fnc_safeZoneActive = true;

 

To actually enforce the safeZone this could be a simple solution:

player addAction ["", {true}, [], 0, false, false, "DefaultAction", "_this distance2d safezone < 25 AND _this isEqualTo _target AND TAG_fnc_safeZoneActive"];

No need to remove the addaction, weapon lock is handled via distance to an object called "safezone" and with the global variable added above, to allow the base getting attacked/defended.

You could replace safezone with another object in the center of your safezone or with a marker position and adjust the distance of 25 according to your preferences.

 

However it's still possible to place satchels, so you'd need another EH to prevent players from using throwables/placeables:

player addeventhandler ["Fired",{ 
 
    params ["_shooter","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile","_gunner"]; 
    _dispName = getText (configfile >> "CfgMagazines" >> _magazine >> "displayName"); 
    _distanceCheck = _shooter distance2d safezone < 150; 
 
    if ((toUpper _weapon isEqualTo "PUT" OR toUpper _weapon isEqualTo "THROW") AND _distanceCheck AND TAG_fnc_safeZoneActive) then { 
 
        deletevehicle _projectile; 
        _shooter addMagazine _magazine; 
        hint format ["You're not allowed to use %1 in a no fire zone!",_dispName]}; 
 
 
}];

Simply put both the above snippets into initPlayerLocal.sqf and you're set.

You can then enforce the safeZone from anywhere inside the mission using:

missionNamespace setVariable ["TAG_fnc_safeZoneActive",true,true];//enables safeZone
missionNamespace setVariable ["TAG_fnc_safeZoneActive",false,true];//disables safeZone

 

Cheers

Share this post


Link to post
Share on other sites
4 minutes ago, Grumpy Old Man said:

 

Isn't it better to prevent the player from actually firing instead of deleting every fired projectile, since it was also the original request?

Probably a more aesthetic solution rather than having players running around the base firing on full-auto without hurting anyone.

 

@Kleine Bea:

 

If you plan on having your base attacked it could be useful to handle the enforcement of the safezone via a global variable, so into the initPlayerLocal.sqf inside your mission root put this:


TAG_fnc_safeZoneActive = true;

 

To actually enforce the safeZone this could be a simple solution:


player addAction ["", {true}, [], 0, false, false, "DefaultAction", "_this distance2d safezone < 25 AND _this isEqualTo _target AND TAG_fnc_safeZoneActive"];

No need to remove the addaction, weapon lock is handled via distance to an object called "safezone" and with the global variable added above, to allow the base getting attacked/defended.

You could replace safezone with another object in the center of your safezone or with a marker position and adjust the distance of 25 according to your preferences.

 

However it's still possible to place satchels, so you'd need another EH to prevent players from using throwables/placeables:


player addeventhandler ["Fired",{ 
 
    params ["_shooter","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile","_gunner"]; 
    _dispName = getText (configfile >> "CfgMagazines" >> _magazine >> "displayName"); 
    _distanceCheck = _shooter distance2d safezone < 150; 
 
    if ((toUpper _weapon isEqualTo "PUT" OR toUpper _weapon isEqualTo "THROW") AND _distanceCheck AND TAG_fnc_safeZoneActive) then { 
 
        deletevehicle _projectile; 
        _shooter addMagazine _magazine; 
        hint format ["You're not allowed to use %1 in a no fire zone!",_dispName]}; 
 
 
}];

Simply put both the above snippets into initPlayerLocal.sqf and you're set.

You can then enforce the safeZone from anywhere inside the mission using:


missionNamespace setVariable ["TAG_fnc_safeZoneActive",true,true];//enables safeZone
missionNamespace setVariable ["TAG_fnc_safeZoneActive",false,true];//disables safeZone

 

Cheers

 

nice post

 

removing the action is preferable due to the CPU-expensive per-frame call-compile of the condition.

  • Like 1

Share this post


Link to post
Share on other sites
11 minutes ago, fn_Quiksilver said:

 

nice post

 

removing the action is preferable due to the CPU-expensive per-frame call-compile of the condition.

 

call compile "player distance2d safezone < 25 AND player isEqualTo player AND TAG_fnc_safeZoneActive";//0.0023ms

Maybe I'm missing something, but 0.0023ms out of 16.6667ms (at 60fps for one frame) isn't really something to worry about (only 0.01379% of a frames runtime), even if it's running on 1000 players simultaneously.

 

Cheers

Share this post


Link to post
Share on other sites
On 4/7/2018 at 5:58 PM, Grumpy Old Man said:

 

Isn't it better to prevent the player from actually firing instead of deleting every fired projectile, since it was also the original request?

Probably a more aesthetic solution rather than having players running around the base firing on full-auto without hurting anyone.

 

@Kleine Bea:

 

If you plan on having your base attacked it could be useful to handle the enforcement of the safezone via a global variable, so into the initPlayerLocal.sqf inside your mission root put this:


TAG_fnc_safeZoneActive = true;

 

To actually enforce the safeZone this could be a simple solution:


player addAction ["", {true}, [], 0, false, false, "DefaultAction", "_this distance2d safezone < 25 AND _this isEqualTo _target AND TAG_fnc_safeZoneActive"];

No need to remove the addaction, weapon lock is handled via distance to an object called "safezone" and with the global variable added above, to allow the base getting attacked/defended.

You could replace safezone with another object in the center of your safezone or with a marker position and adjust the distance of 25 according to your preferences.

 

However it's still possible to place satchels, so you'd need another EH to prevent players from using throwables/placeables:


player addeventhandler ["Fired",{ 
 
    params ["_shooter","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile","_gunner"]; 
    _dispName = getText (configfile >> "CfgMagazines" >> _magazine >> "displayName"); 
    _distanceCheck = _shooter distance2d safezone < 150; 
 
    if ((toUpper _weapon isEqualTo "PUT" OR toUpper _weapon isEqualTo "THROW") AND _distanceCheck AND TAG_fnc_safeZoneActive) then { 
 
        deletevehicle _projectile; 
        _shooter addMagazine _magazine; 
        hint format ["You're not allowed to use %1 in a no fire zone!",_dispName]}; 
 
 
}];

Simply put both the above snippets into initPlayerLocal.sqf and you're set.

You can then enforce the safeZone from anywhere inside the mission using:


missionNamespace setVariable ["TAG_fnc_safeZoneActive",true,true];//enables safeZone
missionNamespace setVariable ["TAG_fnc_safeZoneActive",false,true];//disables safeZone

 

Cheers

For some reason, when the player regenerates, the script doesn't work, and they can shoot at will on base.

Share this post


Link to post
Share on other sites
58 minutes ago, Nana1999 said:

For some reason, when the player regenerates, the script doesn't work, and they can shoot at will on base.

For MP you need to add this on a respawn EH on the player unit, or in onPlayerRespawn.sqf or similar.

 

Cheers

Share this post


Link to post
Share on other sites
16 hours ago, Grumpy Old Man said:

For MP you need to add this on a respawn EH on the player unit, or in onPlayerRespawn.sqf or similar.

 

Cheers

ThankYou so much!😊

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

×