Jump to content

Recommended Posts

I'm trying to make a safe zone where you can't shoot or throw grenades. I have a scripts that deletes the projectiles in the area so if someone shots the bullet is deleted. Is there any way to actually prevent someone from firing? During briefings its annoying if someone is firing their weapons to test something and with the current script the person can still shot, there is just no bullets coming out. 

Share this post


Link to post
Share on other sites

This might not be what you want, but disableUserInput is used to prevent player actions during cutscenes.  if you want them to be able to move still, and restrict shooting/throwing only, this won't work.  That would be complicated.

Share this post


Link to post
Share on other sites

This might not be what you want, but disableUserInput is used to prevent player actions during cutscenes.  if you want them to be able to move still, and restrict shooting/throwing only, this won't work.  That would be complicated.

Yes i found that before, also read about disabling the mouse button but that would indeed prevent them from firing but also prevent them from using any other feature that requires mouse clicks

Share this post


Link to post
Share on other sites

You could use DisplaySetEventHandler to redefine/block certain keys for a while.

 

Make sure to use the actionKeys command to grab the correct keys. Do not rely on the default keybindings.

 

actionKeys "Throw"

actionKeys "Fire"

actionKeys "Action"

actionKeys "DefaultAction"

 

block all of these and you should be safe (the last two will block interaction with any objects and therefor also makes it impossible to place explosives)

 

Yes i found that before, also read about disabling the mouse button but that would indeed prevent them from firing but also prevent them from using any other feature that requires mouse clicks

true, thats the downside...

Well, instead of blocking the fire button, you could also force people to keep their weapon lowered or force them to have their weapon on the back.

Share this post


Link to post
Share on other sites

Here is what I use. You can add to the case if you need other sides to be considered.

 

 

safezone.sqf

/*
safeZone

Setup: Place in the init
[] execVM "scripts\safeZone.sqf";

Add marker with unique name and specify the distance for safety_zones

Example: [["marker1", radius1], ["marker2", radius2], ...]
*/



if (isServer) exitWith {};


#define SAFETY_ZONES    [["safe", 300]]
#define MESSAGE "WTH! Stop shooting or throwing grenades! You are in a safe zone!"

     if (isDedicated) exitWith {};
     waitUntil {!isNull player};

switch (playerSide) do
{
    case west:
    {


     player addEventHandler ["Fired", {
            if ({(_this select 0) distance getMarkerPos (_x select 0) < _x select 1} count SAFETY_ZONES > 0) then
            {
             deleteVehicle (_this select 6);
             titleText [MESSAGE, "PLAIN", 3];
             };
        }];

    };
    
    
};

  • Like 1

Share this post


Link to post
Share on other sites

Well, instead of blocking the fire button, you could also force people to keep their weapon lowered or force them to have their weapon on the back.

 

I might try that. Been searching a bit but i can't find any information on forcing to lower the weapon

 

 

 

Here is what I use. You can add to the case if you need other sides to be considered.

 

 

safezone.sqf

/*
safeZone

Setup: Place in the init
[] execVM "scripts\safeZone.sqf";

Add marker with unique name and specify the distance for safety_zones

Example: [["marker1", radius1], ["marker2", radius2], ...]
*/



if (isServer) exitWith {};


#define SAFETY_ZONES    [["safe", 300]]
#define MESSAGE "WTH! Stop shooting or throwing grenades! You are in a safe zone!"

     if (isDedicated) exitWith {};
     waitUntil {!isNull player};

switch (playerSide) do
{
    case west:
    {


     player addEventHandler ["Fired", {
            if ({(_this select 0) distance getMarkerPos (_x select 0) < _x select 1} count SAFETY_ZONES > 0) then
            {
             deleteVehicle (_this select 6);
             titleText [MESSAGE, "PLAIN", 3];
             };
        }];

    };
    
    
};

 

 

That is the one i'm using right now

Share this post


Link to post
Share on other sites

player action ["SwitchWeapon", player, player, 99];

Puts the weapon on the back.

 

player action ["WeaponOnBack", player];

Lowers the weapon (despite the name of the action).

  • Like 1

Share this post


Link to post
Share on other sites

How about onKeyDown EHs? Although you need to be cautious with it...

Share this post


Link to post
Share on other sites

You could utilize a "Fired" eventhandler to auto delete explosives and reAdd them to the player (because we're nice people) while in the no fire zone.

Something like this:

player addeventhandler ["Fired",{

    params ["_shooter","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile","_gunner"];
    _dispName = getText (configfile >> "CfgMagazines" >> _magazine >> "displayName");
    _distanceCheck = _shooter distance2d getmarkerpos "NOFIREZONE" < 150;

    if (toUpper _weapon isEqualTo "PUT" AND _distanceCheck) then {

        deletevehicle _projectile;
        _shooter addMagazine _magazine;
        hint format ["You're not allowed to put %1 on the ground in a no fire zone!",_dispName]};


}];

Assuming there's a marker named "NOFIREZONE" and the no fire zone is 150m in radius.

See KK's blog for a way to override LMB, adding a simple distancecheck would prevent players from firing weapons.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

That is very handy. thank you

Share this post


Link to post
Share on other sites
On 10/20/2016 at 9:10 AM, Grumpy Old Man said:

You could utilize a "Fired" eventhandler to auto delete explosives and reAdd them to the player (because we're nice people) while in the no fire zone.

Something like this:


player addeventhandler ["Fired",{

    params ["_shooter","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile","_gunner"];
    _dispName = getText (configfile >> "CfgMagazines" >> _magazine >> "displayName");
    _distanceCheck = _shooter distance2d getmarkerpos "NOFIREZONE" < 150;

    if (toUpper _weapon isEqualTo "PUT" AND _distanceCheck) then {

        deletevehicle _projectile;
        _shooter addMagazine _magazine;
        hint format ["You're not allowed to put %1 on the ground in a no fire zone!",_dispName]};


}];

Assuming there's a marker named "NOFIREZONE" and the no fire zone is 150m in radius.

See KK's blog for a way to override LMB, adding a simple distancecheck would prevent players from firing weapons.

 

Cheers

 

How would I go about setting a length and width instead of a radius that way I can make the area a rectangular shape? I'm trying to use this for an airfield and I don't want it to extend outward too much.

Share this post


Link to post
Share on other sites
13 hours ago, KlutchDecal said:

 

How would I go about setting a length and width instead of a radius that way I can make the area a rectangular shape? I'm trying to use this for an airfield and I don't want it to extend outward too much.

Then wouldn't something like

_distanceCheck = _shooter inArea "NOFIREZONE";

work?

  • Like 1

Share this post


Link to post
Share on other sites
On 10/19/2016 at 5:59 PM, kerozen said:

I'm trying to make a safe zone where you can't shoot or throw grenades.

 

 How about overriding the left mouse button, as KK explains it here

 

Edited by Nikander
GOM

Share this post


Link to post
Share on other sites
21 hours ago, X Pro Octane said:

Then wouldn't something like


_distanceCheck = _shooter inArea "NOFIREZONE";

work?

I toyed around with that for a bit and managed to work it out. Thanks m8!

  • Like 1

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

×