Jump to content
GEORGE FLOROS GR

Disable the option for opening the backpacks of others (inventory) when they are alive

Recommended Posts

Hello there to Everyone!

 

I was searching , on how to disable the option for opening the backpacks of others.

So for anyone interested , this is the code:

 

Spoiler
On 5/3/2018 at 12:58 AM, GEORGE FLOROS GR said:

Copy in your init.sqf



while {true} do {
waituntil {dialog and (cursorTarget iskindof "Man" and alive cursorTarget)};
cutText ["You Cannot access the backpacks of the others!" , "PLAIN DOWN"];
//titleText ["You Cannot access the backpacks of the others!", "plain"];
closeDialog 602;
sleep 0.1;
}; 

 

 

 

The best solution so far is here

thanks to

Grumpy Old Man :

Spoiler
On 5/3/2018 at 2:28 PM, Grumpy Old Man said:

Quick solution:



player addEventHandler ["InventoryOpened",{

params ["_unit","_container"];
_override = false;
_allUnitBackpackContainers = allUnits select {alive _x} apply {backpackContainer _x};

if (_container in _allUnitBackpackContainers) then {

	systemchat "This is not the backpack you're looking for";
	_override = true;
};

_override

}];

 

Put this in initPlayerLocal.sqf

 

  • Thanks 3

Share this post


Link to post
Share on other sites

No need to use a while loop.  You can use the InventoryOpened EH and check the container and who opened it, etc.

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#InventoryOpened

Also, using while loop in the init.sqf will stop the rest from executing, unless put last or inside spawn block.

  • Thanks 2

Share this post


Link to post
Share on other sites
10 hours ago, HazJ said:

No need to use a while loop.  You can use the InventoryOpened EH and check the container and who opened it, etc.

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#InventoryOpened

Also, using while loop in the init.sqf will stop the rest from executing, unless put last or inside spawn block.

 

True, it's a good rule of thumb to go through eventhandlers first if you think you need a loop.

 

Quick solution:

player addEventHandler ["InventoryOpened",{

params ["_unit","_container"];
_override = false;
_allUnitBackpackContainers = allUnits select {alive _x} apply {backpackContainer _x};

if (_container in _allUnitBackpackContainers) then {

	systemchat "This is not the backpack you're looking for";
	_override = true;
};

_override

}];

 

Put this in initPlayerLocal.sqf or wherever you seem fit.

This will override the opening of backpacks from alive units, I'm sure dead ones don't mind us going through their stuff.

 

Cheers

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
12 hours ago, HazJ said:

No need to use a while loop

is true!

 

Guys thank you very much ! 

@Hazj   and   @Grumpy Old Man

 

 

I was also trying to do the same , for the NON empty vehicles ,

is there any good option about it?

 

Thanks again!

 

Share this post


Link to post
Share on other sites
19 minutes ago, GEORGE FLOROS GR said:

I was also trying to do the same , for the NON empty vehicles ,

is there any good option about it?

 

Of course.

Funny enough, according to arma you're the driver of your backpack, so the check basically checks if the container opened has a crew, if none or none are alive then you can access it.

So this

Opens:

Backpacks of dead units

Inventory of empty vehicles

Inventory of vehicles where every crew member is dead

 

Forbids

Backpacks of alive units

Inventory of vehicles with alive crew

 


player addEventHandler ["InventoryOpened",{

	params ["_unit","_container"];
	_override = false;
	_allUnitBackpackContainers = allUnits select {alive _x} apply {backpackContainer _x};

	if (_container in _allUnitBackpackContainers OR !(crew _container select {alive _x} isEqualTo []) ) then {

		systemchat "Access denied!";
		_override = true;

	};

	_override

}];

 

Tested it on manned vehicle, empty vehicle and some poor sob with a backpack.

 

Cheers

  • Like 1
  • Thanks 2

Share this post


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

Of course.

Funny enough, according to arma you're the driver of your backpack,

 

Thank you very much @Grumpy Old Man !

  • Like 1

Share this post


Link to post
Share on other sites

Hello I'm a little bit confused. Playing Ravage mod I saw you post on the forum.
But here there is different scripts to use and I don't know witch one to use.

Do I use your script in the OP or the one from Grumpy ?

Thank you in advance

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, MisterOth said:

Do I use your script in the OP or the one from Grumpy ?

 

Grumpy 's script is generally better , so you should use this.

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 05/03/2018 at 2:28 PM, Grumpy Old Man said:

 

True, it's a good rule of thumb to go through eventhandlers first if you think you need a loop.

 

Quick solution:


player addEventHandler ["InventoryOpened",{

params ["_unit","_container"];
_override = false;
_allUnitBackpackContainers = allUnits select {alive _x} apply {backpackContainer _x};

if (_container in _allUnitBackpackContainers) then {

	systemchat "This is not the backpack you're looking for";
	_override = true;
};

_override

}];

 

Put this in initPlayerLocal.sqf or wherever you seem fit.

This will override the opening of backpacks from alive units, I'm sure dead ones don't mind us going through their stuff.

 

Cheers


Hello,

first of all thank you for sharing this script Grumpy Old Man!

I've been testing your script today and for some reason I can access the backpacks of AI units and take whatever they happen to be carrying. Other than that the script does work since the line This is not the backpack you're looking for is being output in the system chat every time I access a backpack (that is being carried by an AI soldier).

I guess though that no one else has observed this behavior?

Fyi, I've placed the script in initPlayerLocal.sqf. While testing I was using the following mods: @CBA_A3, @ALiVE, @IFA3_AIO_LITE and @CUP Terrains - Core
The AI units whose backpacks I was going through were from Iron Front mod.

FIXED: by removing a conflicting InventoryOpened event handler that was being used in a mission framework. See this reply for additional info:

Spoiler

 

 

Edited by Asmodeuz
Solution found
  • Like 1

Share this post


Link to post
Share on other sites

Try it without mods in vanilla, worked last time I checked. You shouldn't even see the inventory screen pop up.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

@Asmodeuz

That is not setup for AI units. You can use forEach to add to all. Replace player with _x magic variable and wrap Grumpy's code in:

{
	// Replace player with _x
	// Grumpy's code...
} forEach allUnits;

 

  • Like 2

Share this post


Link to post
Share on other sites

Thank you for the quick replies Grumpy Old Man and HazJ!

After reading your posts I went to first test HazJ's suggestion in the existing mission I'm creating and the result was (as far as I remember anymore) the same: I still could access the AI's backpacks and manipulate its inventory while the line This is not the backpack you're looking for was still being output in the system chat.

After that I went on to disable all the modifications and created the simplest mission with an editor placed AI group and one slot for myself to once again test GOM's script. The result from that test was that the script works as intended. Then I started adding modifications one by one and finally the "mission framework" I'm using to create missions. Eventually I got the hang of the fact that the mission framework includes a InventoryOpened EH that gets executed slightly later than the GOM's one placed (in this case) in initPlayerLocal.sqf. Solution in my case was to remove the framework's EH after which GOM's version started working as it should.

  • Like 2

Share this post


Link to post
Share on other sites
4 hours ago, Asmodeuz said:

Solution in my case

 

Just to know if you want to keep your EH there is also my original post with the alternative way.

The point is that Grumpy Old Man 's code is way better !

Share this post


Link to post
Share on other sites

Here is something similar from the post:

#[Release] Lock backpack (ACE Compatible)

 

17 hours ago, pierremgi said:

Here is a little code for those you want something for vanilla ARMA (no mod required, JIP compatible):

 

in init.sqf:


 


if (isServer) then {bpkList = []; publicVariable "bpkList"};
MGI_lock_action = {
  player addAction ["<t color='#00ff00'>lock backpack</t>", {
    params ["_plyr","","_id"];
    call {
      if (isNil {_plyr getVariable "lockedBpk"}) exitWith {
        _plyr setVariable ["lockedBpk",true,true];
        _bpk = backpackContainer _plyr;
        bpkList pushBack _bpk;
        publicVariable "bpkList";
        _plyr setUserActionText [_id, "<t color='#ff0000'>unlock backpack</t>"];
        hintSilent "backpack is locked";
      };
      if (!isNil {_plyr getVariable "lockedBpk"}) exitWith {
        _plyr setVariable ["lockedBpk",nil,true];
        _plyr setUserActionText [_id, "<t color='#00ff00'>lock backpack</t>"];
        hintSilent "backpack is unlocked";
        _bpk = backpackContainer _plyr;
        bpkList = bpkList -[_bpk];
        publicVariable "bpkList";
      };
    };
  }]
};
waituntil {!isNull player};
call MGI_lock_action;
player addEventHandler ["respawn",{call MGI_lock_action}];
0 = [] spawn {
  while {true} do {
    {
      _x setVariable ["JIPtreated",true];
      _x addEventHandler ["InventoryOpened", {
        params ["_unit","_container"];
        if (_container in bpkList) then {
          [] spawn {
            waitUntil {!(isNull findDisplay 602)};
            findDisplay 602 closeDisplay 1;
          }
        }  
      }]
    } forEach (allPlayers select {isnil {_x getVariable "JIPtreated"}});
    sleep 2;
  }
};

This doesn't lock the backpack for the owner. This feature is treated in an other post.

Have fun.

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

By the way, I was focused on JIP from init.sqf but it's possible to avoid the loop while true, placing the code

in initPlayerLocal.sqf:
 


MGI_lock_action = {
  player addAction ["<t color='#00ff00'>lock backpack</t>", {
  params ["_plyr","","_id"];
  call {
    if (isNil {_plyr getVariable "lockedBpk"}) exitWith {
      _plyr setVariable ["lockedBpk",true,true];
      _bpk = backpackContainer _plyr;
      bpkList pushBack _bpk;
      publicVariable "bpkList";
      _plyr setUserActionText [_id, "<t color='#ff0000'>unlock backpack</t>"];
      hintSilent "backpack is locked"; };
    if (!isNil {_plyr getVariable "lockedBpk"}) exitWith {
      _plyr setVariable ["lockedBpk",nil,true];
      _plyr setUserActionText [_id, "<t color='#00ff00'>lock backpack</t>"];
      hintSilent "backpack is unlocked";
      _bpk = backpackContainer _plyr;
      bpkList = bpkList -[_bpk];
      publicVariable "bpkList";
    };
  };
  }]
};
call MGI_lock_action;
player addEventHandler ["respawn",{call MGI_lock_action}];
player addEventHandler ["InventoryOpened", {
  params ["_unit","_container"];
  if (_container in bpkList) then {
    [] spawn { 
      waitUntil {!(isNull findDisplay 602)};
      findDisplay 602 closeDisplay 1;
    }
  }
}];

 

and in initserver.sqf:
 


bpkList = [];
publicVariable "bpkList";
  • Haha 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

×