[Release] Anti-Theft Script (Prevent Opening BackPack)

UrbanSkaters

Valued Member!
Introduction: This script prevents another player from accessing your backpack. I've set it up below for Epoch Trader Zones, but you can easily set it to ALWAYS ON which will work with most other DayZ mods too. This script will let you remove or access backpacks from dead players and will also let you pick up backpacks that aren't attached to another "live" player.

Installation Instructions:
1. I'm assuming you're going to put this script in a folder called Custom.
2. Create a new text file and call it anti_theft.sqf
3. Cut and Paste the following code into the anti_theft.sqf file and save it.
4. Edit your init.sqf and right at the bottom add: execVM "custom\anti_theft.sqf";
7. Now choose which version you want:
7a. Replace { !canbuild } with { alive player } if you want it on ALL the time, not just in the trader zones.
8. Repackage your mission file, upload and everything should work.

Just to clarify: The script below is currently set up for Epoch trading zones. But if you want to have the script run all the time on Epoch or any other DayZ mod then replace { !canbuild } with { alive player }


Code:
// Thanks to SilverShot for starting this script.
// Anti-Theft (Backpack) by Hayward

_fix = false;
while { !canbuild } do
{
	sleep 0.2;
	
// Check if target is player and alive
 if (alive cursorTarget && (cursorTarget isKindOf "Man")) then { 
                         
        if( !isNull (FindDisplay 106) ) then
	{
		if( !_fix ) then
		{
			player action ["GEAR", ""];
			titleText["\n\nCan only access your own gear.", "PLAIN DOWN",0];
			_fix = true;
		};
	} else {
		if( _fix ) then
		{
			_fix = false;
		};
	};


     // If target is not a player then do nothing
     } else {
                }; 

};
 
There is a really simple bypass to this, i will start a convo with the author to let them know how - however do not be surprised if you hear people in ur trader zones (or whatever) saying "I got stuff stolen from my bag" when running these kinda scripts.

- Just a heads up
 
Silvershots version still has the bypass issue.
Here is some code I made, please feel free to use it along side the instructions given by the original author:
( I would PM the author, but i cant - his profile restricts it )

(this code has been modified from my original slightly, so i have not tested it)
Code:
/*
* Anti Backpack Theft
* - By Silvershot & AlienX
* - Should prevent the backpack bypass where you can still take from peoples bags.
* - This Allows: Getting gear from dead players, getting gear from weapon holders on the floor and gear inside vehicles.
*/
[] spawn {
    private ["_to","_dis","_inchk","_ia","_skip","_ct"];
    while { true } do
    {
        //Let's not hammer the client every frame.
        waitUntil { sleep 1; !canBuild };
 
        while { !canBuild } do
        {
            sleep 0.1;
   
            _ct = cursorTarget;
            _skip = false;
   
            if ( !isNull (_ct) ) then
            {
                _to = typeOf _ct;
                _dis = _ct distance player;
                _inchk = ["AllVehicles","WeaponHolder"];
                _ia = alive _ct;
       
                if ( (_to in _inchk) && (_dis < 10) ) then {_skip = true;};
                if ( !_ia ) then {_skip = true;};
            };
   
            if( !isNull (FindDisplay 106) && !_skip ) then
            {
                    (findDisplay 106) closeDisplay 1;
                    systemChat ("Entering other players gear is not allowed here, redirecting you to your own gear instead!");
            };
        };
    };
};


Gave this a try and it blocks access to your own backpack, and your car's inventory (via map -> gear). Is this intended?
 
Yeah apologies, i made a mistake in the script.
Here is a fixed one, while it does cause your gear screen to open, close and open again, i am unable to bypass it.

I hope this works better for you.

Code:
/*
* Anti Backpack Theft
* - By Silvershot & AlienX
* - Should prevent the backpack bypass where you can still take from peoples bags.
* - This Allows: Getting gear from dead players, getting gear from weapon holders on the floor and gear inside vehicles.
*/
[] spawn {
    private ["_to","_dis","_inchk","_ia","_skip","_ct","_iv"];
    while { true } do
    {
        //Let's not hammer the client every frame.
        waitUntil { sleep 1; !canBuild };
 
        while { !canBuild } do
        {
            sleep 0.1;
 
            _ct = cursorTarget;
            _skip = false;
 
            if ( !isNull (_ct) ) then
            {
                _to = typeOf _ct;
                _dis = _ct distance player;
                _inchk = ["WeaponHolder","FoodBox0","MedBox0"]; //Add more stuff here
                _ia = alive _ct;
                _iv = _ct isKindOf "AllVehicles";
   
                if ( (_to in _inchk) && (_dis < 10) ) then {_skip = true;};
                if ( !_ia ) then {_skip = true;};
                if ( _iv ) then {_skip = true;};
            };
 
            if( !isNull (FindDisplay 106) && !_skip ) then
            {
                (findDisplay 106) closeDisplay 1;
                sleep 0.1;
                createGearDialog [(player), 'RscDisplayGear'];
                systemChat (""[AGN] Entering other players gear is not allowed here, redirecting you to your own gear instead!"");
                waitUntil { isNull (FindDisplay 106) };
            };
        };
    };
};
 
AlienX your version stops you from accessing any vehicle gear or your own gear while inside a safezone.

This makes trading really difficult :D
 
I have updated the code to perhaps fix the vehicle gear issue :)
I will be making it so that you can access backpacks of tagged players soon.
 
Hello, so im having a bit of a problem. its not working at all and this is all im getting out of the server logs.

Error in expression <ayer), 'RscDisplayGear'];
systemChat (""[AGN] Entering other players gear is not>
16:36:22 Error position: <[AGN] Entering other players gear is not>
16:36:22 Error Missing )
16:36:22 File mpmissions\__cur_mp.chernarus\scripts\anti_theft.sqf, line 39
16:36:22 Error in expression <ayer), 'RscDisplayGear'];
systemChat (""[AGN] Entering other players gear is not>
16:36:22 Error position: <[AGN] Entering other players gear is not>
16:36:22 Error Missing )
16:36:22 File mpmissions\__cur_mp.chernarus\scripts\anti_theft.sqf, line 39

i followed the instructions to the tee. anyone know what that error is? i used the code from post #8 btw
 
Back
Top