Jump to content
  • 0

Creating a "Break In" script - Stuck and tired - Looking for help


FreakingFred

Question

I have base destruction off on my server to limit base griefing slightly.  However, I would still like there to be a less destructive method of breaking into another players base.  So, I have been working on a "break in" script since last night.  The concept of the script is to require a player to have a toolbox, crowbar and Sledge Hammer (in hands) to attempt to break in to a door.  There is a 10% chance to break into cinder, a 20% chance to break into wood and a 20% chance to break (delete) each tool required.  I, at one point, had the tool check in the beginning working perfectly.  However, the rest of the script was not running properly.  I edited it a bit and got the rest of the script working and then the tool check in the beginning stopped, haha.  I am so tired at this point that the code is just blending together.  I could really use a few more sets of eyes on this to steer me in the right direction.  Thanks in advance.

private ["_tools","_crowbar","_toolbox","_sledge","_cinderChance","_woodChance","_toolBreakChance","_cursor","_typeCursor","_cinder"];

_tools = weapons player; 
_crowbar = "ItemCrowbar";
_toolbox = "ItemToolbox";
_sledge = "MeleeSledge";
_cinderChance = 10;
_woodChance = 5;
_toolBreakChance = 5;
_cursor = cursorTarget;
_typeCursor = typeOf _cursor;
_cinder = ["CinderWallDoorLocked_DZ","CinderWallDoorSmallLocked_DZ"];


{
	if !(_x in _tools) exitWith {	
		hint "You are missing one or more items required to break in.  You must have a toolbox, crowbar and sledge hammer.";
	};
} forEach [_crowbar, _toolbox, _sledge];

if (_typeCursor in _cinder) then {
	if (random(_cinderChance) < 1) then {
		_cursor lock false;
		hint "You have broken in.";
		{
			_cursor animate [_x,1];
		} forEach ["Open_hinge","Open_latch"];
	
	} else {
	
		hint "You have failed to break in.";
	
		{
			if (random(_toolBreakChance) < 1) then {
			player removeWeapon _x;
			};
		} forEach [_crowbar, _toolbox, _sledge];
		
		sleep 1;
		
		{
			if !(_x in _tools) then {
				hint format["You have broken your %1.",_x];
				sleep 2;
			};
		} forEach [_crowbar, _toolbox, _sledge];
	};

} else {
	
	if (random(_woodChance) < 1) then {
		_cursor lock false;
		hint "You have broken in.";
		{
			_cursor animate [_x,1];
		} forEach ["Open_hinge","Open_latch"];
	
	} else {
		
		{
			if (random(_toolBreakChance) < 1) then {
			player removeWeapon _x;
			};
		} forEach [_crowbar, _toolbox, _sledge];
		
		sleep 1;
		
		{
			if !(_x in _tools) then {
				hint format["You have broken your %1.",_x];
				sleep 2;
			};
		} forEach [_crowbar, _toolbox, _sledge];
	};
}:
Link to comment
Share on other sites

20 answers to this question

Recommended Posts

  • 0

Also, just for reference, this is what I have added into fn_selfAction.sqf for the scroll-wheel option.

if (_typeOfCursorTarget in DZE_DoorsLocked) then {
	_isDoor = true;
} else {
	_isDoor = false;
};

if (_isDoor) then {
	if((speed player <= 1) && _canDo && !_inVehicle) then {
		if (s_player_breakIn < 0) then {
			s_player_breakIn = player addAction[("<t color=""#038BAD"">" + ("Break In") +"</t>"),"scripts\breakIn.sqf","",5,false,true,"", ""];
		};
	} else {
		player removeAction s_player_breakIn;
		s_player_breakIn = -1;
	};
};
Link to comment
Share on other sites

  • 0
private ["_tools","_crowbar","_toolbox","_sledge","_cinderChance","_woodChance","_toolBreakChance","_cursor","_typeCursor","_cinder"];

_tools = weapons player; 
_crowbar = "ItemCrowbar";
_toolbox = "ItemToolbox";
_sledge = "MeleeSledge";
_cinderChance = 10;
_woodChance = 5;
_toolBreakChance = 5;
_cursor = cursorTarget;
_typeCursor = typeOf _cursor;
_cinder = ["CinderWallDoorLocked_DZ","CinderWallDoorSmallLocked_DZ"];

if (_crowbar in _tools && _toolbox in _tools && _sledge in _tools) then{
		if (_typeCursor in _cinder) then {
			if (random(_cinderChance) < 1) then {
				_cursor lock false;
				hint "You have broken in.";
				{
					_cursor animate [_x,1];
				} forEach ["Open_hinge","Open_latch"];
			
			} else {
			
				hint "You have failed to break in.";
			
				{
					if (random(_toolBreakChance) < 1) then {
					hint format["You have broken your %1.",_x];
						sleep 2;
					player removeWeapon _x;
					};
				} forEach [_crowbar, _toolbox, _sledge];
				

		} else {
			
			if (random(_woodChance) < 1) then {
				_cursor lock false;
				hint "You have broken in.";
				{
					_cursor animate [_x,1];
				} forEach ["Open_hinge","Open_latch"];
			
			} else {
				
				{
					if (random(_toolBreakChance) < 1) then {
					hint format["You have broken your %1.",_x];
						sleep 2;
					player removeWeapon _x;
					};
				} forEach [_crowbar, _toolbox, _sledge];
				
			};
		};
	};
};
Link to comment
Share on other sites

  • 0

I have something similar but in my script Toolbox is not a weapon. Its an item...maybe thats breaking it ? Cause in mine it works fine.

ex:

_hasToolbox    =  "ItemToolbox" in items player;
_hasEtool      =  "ItemEtool" in weapons player;
_hasItemCrowbar = "ItemCrowbar" in items player;

if (!_hasToolbox)  exitWith {cutText ["You are missing ....."], "PLAIN DOWN"];};
if (!_hasEtool)  exitWith {cutText ["You are missing ....."], "PLAIN DOWN"];};
if (!_hasItemCrowbar)  exitWith {cutText ["You are missing ....."], "PLAIN DOWN"];};

Link to comment
Share on other sites

  • 0

I figured it out.  I was under the impression that the exitWith command exited the entire script, which is not the case.  I have edited the initial forEach loop and got everything working with a new variable called _hasTools.

private ["_tools","_crowbar","_toolbox","_sledge","_cinderChance","_woodChance","_toolBreakChance","_cursor","_typeCursor","_cinder","_hasTools"];

_tools = weapons player; 
_crowbar = "ItemCrowbar";
_toolbox = "ItemToolbox";
_sledge = "MeleeSledge";
_cinderChance = 10;
_woodChance = 5;
_toolBreakChance = 5;
_cursor = cursorTarget;
_typeCursor = typeOf _cursor;
_cinder = ["CinderWallDoorLocked_DZ","CinderWallDoorSmallLocked_DZ"];
_hasTools = true;


{
	if !(_x in _tools) exitWith {	
		hint "You are missing one or more items required to break in.  You must have a toolbox, crowbar and sledge hammer.";
		_hasTools = false;
	};
} forEach [_crowbar, _toolbox, _sledge];

if (_hasTools) then {
	if (_typeCursor in _cinder) then {
		if (random(_cinderChance) < 1) then {
			_cursor lock false;
			hint "You have broken in.";
			{
				_cursor animate [_x,1];
			} forEach ["Open_hinge","Open_latch"];
	
		} else {
	
			hint "You have failed to break in.";
	
			{
				if (random(_toolBreakChance) < 1) then {
				player removeWeapon _x;
				};
			} forEach [_crowbar, _toolbox, _sledge];
		
			sleep 1;
		
			{
				if !(_x in _tools) then {
					hint format["You have broken your %1.",_x];
					sleep 2;
				};
			} forEach [_crowbar, _toolbox, _sledge];
		};

	} else {
	
		if (random(_woodChance) < 1) then {
			_cursor lock false;
			hint "You have broken in.";
			{
				_cursor animate [_x,1];
			} forEach ["Open_hinge","Open_latch"];
	
		} else {
		
			{
				if (random(_toolBreakChance) < 1) then {
				hint format["You have broken your %1.",_x];
				player removeWeapon _x;
				sleep 1;
				};
			} forEach [_crowbar, _toolbox, _sledge];
		};
	};
};

Now, I just have to add a distance check in the fn_selfActions so that players won't get the scroll-wheel option unless they are next to the door and an animation and time to the break in process so that it can't be spammed. :)

Link to comment
Share on other sites

  • 0

Edited the fn_selfActions.sqf to have a minimum distance requirement.

_distanceDoor = player distance _cursorTarget;

if (_typeOfCursorTarget in DZE_DoorsLocked) then {
	_isDoor = true;
} else {
	_isDoor = false;
};

if (_isDoor) then {
	if((speed player <= 1) && _canDo && !_inVehicle && (_distanceDoor <= 3)) then {
		if (s_player_breakIn < 0) then {
			s_player_breakIn = player addAction[("<t color=""#038BAD"">" + ("Break In") +"</t>"),"scripts\breakIn.sqf","",5,false,true,"", ""];
		};
	} else {
		player removeAction s_player_breakIn;
		s_player_breakIn = -1;
	};
};
Link to comment
Share on other sites

  • 0

nice idea

 

i can understand you just started this, so i guess you are still working on it, but i would still like to come with my pov

 

tbh i never liked using "in" to compare as it is case seitive ... i think i would have found some way around that and i think i personally would use hasWeapon to check the items and then currentWeapon for the one you want the player to be wielding.

 

some items are kinda easy to figure, but not all are as easy to guess from the classname ... to make sure the players knows what item you are reffering you can use this

you can also get the ingame item name from config, something like this:

_txt = (gettext (configFile >> 'cfgweapons' >> "ItemToolbox" >> 'displayName'));
//_txt will return "Toolbox"
_txt = (gettext (configFile >> 'cfgmagazines' >> "PartGeneric" >> 'displayName'));
//_txt will return "Scrap Metal"

also, you are practicly giving the player the posibility to drop the items, before they are removed with that sleep.

imo you should rather figure earlier wheter the item is removed or not set it to an array, then quickly remove them all without any sleep and showing the entire array of items removed, instead of a hint that overwrites last hint for each item.

 

other than that ...

good work man, awsome idea ;)

Link to comment
Share on other sites

  • 0

Fred i would suggest you take a look at this script here: https://github.com/Daimyo21/BaseBuilding_1.3_Community/blob/master/Version%20Epoch%201.0.3.1/dayz.mission/dayz_code/actions/player_remove.sqf , especially bellow the part where it says

if (!_hasToolbox) then {cutText [format["You need a tool box to remove %1",_text], "PLAIN DOWN",1];remProc = false; breakOut "exit"; };

You could implement a similar thing (waiting, and chance breaking, and "if player cheating").

Link to comment
Share on other sites

  • 0

Ive always loved freds ideas, in dayz a year or so ago, when the mod forums were the same ole thing, and nothing really new was coming out.. there was fred with cool little mods he came up with.. Zombie Bait, Exploding Zombie Bait were a couple of my favs. Im glad you are back and getting that dayz brain going again.

Link to comment
Share on other sites

  • 0

Looks like they don't even know them selfs how it works outside a loop :)

 

"When you use exitWith not inside a loops, the behaviour is undefined - sometimes it may exit the script, sometimes some other scope, but this is not intended and designed behavior of this command, and it is not guaranteed to work reliably."

Link to comment
Share on other sites

  • 0

I've tried to finish this off myself given it's been a few months and I can't see that this was ever release but I seem to be getting an error around line 49 where it complains about a missing )

Basically I added the usual checks (standing still, not in a vehicle, not on cooldown (configurable), not in combat, and added an option to reduce player humanity.

I've changed the hints to cut text (much better imho) and added some sounds to the break in.

 

I get it working as far as passing the checks (marked as //passed checks) and it my test script it outputs "success".

Combat and cooldown fails as expected with the correct messages.

But as soon as I add in the animation etc it keeps failing, I've only spent a couple days looking at it (and I'm a complete noob) but figured I'd post it here in case someone better could see the fix.

 

 

private ["_tools","_crowbar","_toolbox","_sledge","_cinderChance","_woodChance","_toolBreakChance","_breakinattemptduration","_breakincooldown","_humanityBool","_humanityAmount","_breakintime","_cursor","_typeCursor","_cinder","_hasTools","_failcheck","_breakinattempttime","_timeout","_inCombat","_lastbreakin"];

//Configuration
_tools = weapons player;
_crowbar = "ItemCrowbar";
_toolbox = "ItemToolbox";
_sledge = "ItemSledge";
_cinderChance = 20;
_woodChance = 10;
_toolBreakChance = 5;
_breakinattemptduration = 30; // Time in Seconds it takes the player to attempt a Break-In
_breakincooldown = 60; //Time in seconds before the player can attempt another Break-In
_humanityBool = true; // Whether the player can lose humanity from Break-In Attempts (True = On | False = off)
_humanityAmount = -50; // Amount of humanity to lose if _humanityBool is true
_cursor = cursorTarget;
_typeCursor = typeOf _cursor;
_cinder = ["CinderWallDoorLocked_DZ","CinderWallDoorSmallLocked_DZ"];
_hasTools = true;
_failcheck = false;

//Checks
_breakintime = time - lastbreakin; // Variable used in determining the Break-In cooldown
_breakinattempttime = time;
_timeout = player getVariable["combattimeout", 0];
_inCombat = if (_timeout >= diag_tickTime) then {true} else {false};

    //Cooldown Check
    if(_breakintime < _breakincooldown) exitWith { //
    cutText [format["You can't attempt another Break-In this soon please wait %1!",(_breakintime - _breakincooldown)], "PLAIN DOWN"]; //display cooldown remaining
    _failcheck = true;
    };
    
    //Combat Check
    if (_inCombat) exitWith {
    cutText [format["You are in Combat and cannot attempt a Break-In"], "PLAIN DOWN"];
    _failcheck = true;
    };
    
    //Tools Check
    {
    if !(_x in _tools) exitWith {    
        cutText [format["You are missing one or more items required to break in.  You must have a toolbox, crowbar and sledge hammer."],"PLAIN DOWN"];
        _hasTools = false;
    };
    } forEach [_crowbar, _toolbox, _sledge];
    
//Passed Checks

if (_hasTools & !_failcheck) then {
    player removeAction s_player_breakin;
   
//Kill time and check for Interrupts
    r_interrupt = false; // public interrupt variable
    _animState = animationState player; // get the animation state of the player
    r_doLoop = true; // while true sets whether to continue self Break-In attempt
    _started = false; // this starts as false as a check
    _finished = false; // this starts as false and when true later checks for Success or fail
    while {r_doLoop} do {
         if (_typeCursor in _cinder) then {rSAY, "cinderhammer", 120} else {rSAY, "woodcrack", 120};
        _animState = animationState player; // keep checking to make sure player is in correct animation
        _isMedic = ["medic",_animState] call fnc_inString; // checking to make sure the animstate is the medic animation still
        if (_isMedic) then {
            _started = true; // this is a check to make sure everything is still ok
        };
        if(!_isMedic && !r_interrupt && (time - _breakinattempttime) < _breakinattemptduration) then {
            player playActionNow "Medic"; //play Break-In animation
            _isMedic = true;
        };
        if (_started && !_isMedic && (time - _breakinattempttime) > _breakinattemptduration) then {
            r_doLoop = false; // turns off the loop
            _finished = true; // set finished to true to finish the Break-In attempt, set humanity if true, and check for success or failure
            lastbreakin = time; // the last Break-In attempt
        };
        if (r_interrupt) then {
            r_doLoop = false; // if interrupted turns loop off early so _finished is never true
        };
        sleep 0.1;
    };
    r_doLoop = false; // make sure loop is off on completing a Break-In attempt

    if (_finished) then {
    
    if (_typeCursor in _cinder) then {
        if (random(_cinderChance) < 1) then {
            _cursor lock false;
            cutText [format["You have broken in."],"PLAIN DOWN"];
            {
                _cursor animate [_x,1];
            } forEach ["Open_hinge","Open_latch"];
    
        } else {
    
            cutText [format["You have failed to break in."],"PLAIN DOWN"];
    
            {
                if (random(_toolBreakChance) < 1) then {
                player removeWeapon _x;
                };
            } forEach [_crowbar, _toolbox, _sledge];
        
            sleep 1;
        
            {
                if !(_x in _tools) then {
                    hint format["You have broken your %1.",_x];
                    sleep 2;
                };
            } forEach [_crowbar, _toolbox, _sledge];
        };

    } else {
    
        if (random(_woodChance) < 1) then {
            _cursor lock false;
            hint "You have broken in.";
            {
                _cursor animate [_x,1];
            } forEach ["Open_hinge","Open_latch"];
    
        } else {
        
            {
                if (random(_toolBreakChance) < 1) then {
                hint format["You have broken your %1.",_x];
                player removeWeapon _x;
                sleep 1;
                };
            } forEach [_crowbar, _toolbox, _sledge];
        };
    };
} else {
        // this is for handling if interrupted
        r_interrupt = false;
        player switchMove "";
        player playActionNow "stop";
        cutText [format["You have interrupted the Break-In attempt"], "PLAIN DOWN"];
    };
};
    

Link to comment
Share on other sites

  • 0

OK so now it works but not 100%

Anti-cheating isn't picking up correctly (so players can just drop their tools once the attempt has started) it does break tools but doesn't display this properly, and the combat check doesn't work.

Finally if you DON'T chose to breaking...the option remains on your actions menu....but it's almost there :(.

The bulk works, it takes the defined time to run during which the animation runs, you can interrupt it, you lose humanity if you go the full duration regardless of success or fail, you break tools on failure etc, sounds play globally and attract zeds

If anyone wants to run an eye over what I've done wrong with the anti-cheating etc...

 

I'll update if I fix it myself.

 

BreakIn.sqf

private ["_tools","_crowbar","_toolbox","_sledge","_cinderChance","_woodChance","_toolBreakChance","_breakinattemptduration","_breakincooldown","_humanityBool","_humanityAmount","_breakintime","_cursor","_typeCursor","_cinder","_hasTools","_failcheck","_breakinattempttime","_timeout","_inCombat","_lastbreakin"];

//Configuration
_tools = weapons player;
_crowbar = "ItemCrowbar";
_toolbox = "ItemToolbox";
_sledge = "ItemSledge";
_cinderChance = 1;
_woodChance = 10;
_toolBreakChance = 5;
_breakinattemptduration = 10; // Time in Seconds it takes the player to attempt a Break-In
_breakincooldown = 60; //Time in seconds before the player can attempt another Break-In
_humanityBool = true; // Whether the player can lose humanity from Break-In Attempts (True = On | False = off)
_humanityAmount = -50; // Amount of humanity to lose if _humanityBool is true
_cursor = cursorTarget;
_typeCursor = typeOf _cursor;
_cinder = ["CinderWallDoorLocked_DZ","CinderWallDoorSmallLocked_DZ"];
_hasTools = true;
_failcheck = false;

//Checks
_breakintime = time - lastbreakin; // Variable used in determining the Break-In cooldown
_breakinattempttime = time;
_timeout = player getVariable["combattimeout", 0];
_inCombat = if (_timeout >= diag_tickTime) then {true} else {false};

    //Cooldown Check
    if(_breakintime < _breakincooldown) exitWith { //
    cutText [format["You may attempt another Break-In this soon please wait %1!",(_breakintime - _breakincooldown)], "PLAIN DOWN"]; //display cooldown remaining
    _failcheck = true;
    };
    
    //Combat Check
    if (_inCombat) exitWith {
    cutText [format["You are in Combat and cannot attempt a Break-In"], "PLAIN DOWN"];
    _failcheck = true;
    };
    
    //Tools Check
    {
    if !(_x in _tools) exitWith {    
        cutText [format["You are missing one or more items required to break in.  You must have a toolbox, crowbar and sledge hammer."],"PLAIN DOWN"];
        _hasTools = false;
    };
    } forEach [_crowbar, _toolbox, _sledge];
    
//Passed Checks

if (_hasTools && !_failcheck) then {
    lastbreakin = time;
    player removeAction s_player_breakin;
    r_interrupt = false; // public interrupt variable
    _animState = animationState player; // get the animation state of the player
    r_doLoop = true; // while true sets whether to continue self Break-In attempt
    _started = false; // this starts as false as a check
    _finished = false; // this starts as false and when true later checks for Success or fail
    while {r_doLoop} do {
         if (_typeCursor in _cinder) then {playSound "cinderhammer";} else {playSound "woodcrack";};
        _animState = animationState player; // keep checking to make sure player is in correct animation
        _isMedic = ["medic",_animState] call fnc_inString; // checking to make sure the animstate is the medic animation still
        if (_isMedic) then {
            _started = true; // this is a check to make sure everything is still ok
        };
        if(!_isMedic && !r_interrupt && (time - _breakinattempttime) < _breakinattemptduration) then {
            player playActionNow "Medic"; //play Break-In animation
            _isMedic = true;
        };
        if (_started && !_isMedic && (time - _breakinattempttime) > _breakinattemptduration) then {
            r_doLoop = false; // turns off the loop
            _finished = true; // set finished to true to finish the Break-In attempt, set humanity if true, and check for success or failure
            lastbreakin = time; // the last Break-In attempt
        };
        if (r_interrupt) then {
            r_doLoop = false; // if interrupted turns loop off early so _finished is never true
        };
        sleep 0.1;
    };
    r_doLoop = false; // make sure loop is off on completing a Break-In attempt

    if (_finished) then {
    // check if giving player humanity is on
        if(_humanityBool) then {
        [player,_humanityAmount] call player_humanityChange; // Set players humanity based on amount listed in config area
        };    
    //Player Cheating Check
    {
    if !(_x in _tools) exitWith {    
        cutText [format["You appear to have dropped some tools, you aren't cheating are you?."],"PLAIN DOWN"];
        _hasTools = false;
    };
    } forEach [_crowbar, _toolbox, _sledge];
    
    if (_typeCursor in _cinder && _hasTools) then {
        if (random(_cinderChance) < 1) then {
            _cursor lock false;
            cutText [format["You have broken in."],"PLAIN DOWN"];
            {
                _cursor animate [_x,1];
            } forEach ["Open_hinge","Open_latch"];
    
        } else {
    
            cutText [format["You have failed to break in."],"PLAIN DOWN"];
    
            {
                if (random(_toolBreakChance) < 1) then {
                player removeWeapon _x;
                };
            } forEach [_crowbar, _toolbox, _sledge];
        
            sleep 1;
        
            {
                if !(_x in _tools) then {
                    hint format["You have broken your %1.",_x];
                    sleep 2;
                };
            } forEach [_crowbar, _toolbox, _sledge];
        };

    } else {
    
        if (random(_woodChance) < 1 && _hasTools) then {
            _cursor lock false;
            hint "You have broken in.";
            {
                _cursor animate [_x,1];
            } forEach ["Open_hinge","Open_latch"];
    
        } else {
        
            {
                if (random(_toolBreakChance) < 1) then {
                hint format["You have broken your %1.",_x];
                player removeWeapon _x;
                sleep 1;
                };
            } forEach [_crowbar, _toolbox, _sledge];
        };
    };
} else {
        // this is for handling if interrupted
        r_interrupt = false;
        player switchMove "";
        player playActionNow "stop";
        cutText [format["You have interrupted the Break-In attempt"], "PLAIN DOWN"];
    };
};

 

fn_selfactions.sqf  - directly above

} else {
    //Engineering

//BreakIn
_distanceDoor = player distance _cursorTarget;
if (_cursorTarget isKindOf "Land_DZE_WoodDoorLocked_Base" or _cursorTarget isKindOf "CinderWallDoorLocked_DZ_Base") then
{
    if((speed player <= 1) && _canDo && !_inVehicle && (_distanceDoor <= 3)) then
    {
        if (s_player_breakIn < 0) then
        {s_player_breakIn = player addAction[("<t color="#038BAD"">" + ("Break In") +"</t>"),"custom\BreakIn.sqf","",5,false,true,"", "];};
    } else {
        player removeAction s_player_breakIn;
        s_player_breakIn = -1;
            };
};

 

Edit : I took the Combat check from Krixes self blood bag and just realised it's broken there too, I can self BB while in combat so that may be the problem =p

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...