Help with a Break-In Script (some bugs I need to iron out)

Cannorn

New Member
So I've been trying to write a breakin script to complement my indestructable player bases based on an unfinished bit of code by another user (FreakingFred), who wrote the core code that lets you open a locked door and left it at that.

I've managed to fluff it out with all the things I need to make it a release version (Usual checks/variables etc) as well as some extras like sound effects but I have a few bugs and it's probably a simple scripting error I hope someone better can spot (I'm really new to this!)

What's broken:
The Player cheating loop doesn't seem to work and lets you finish the break-in attempt even if you drop your tools.
If you fail and break a tool it doesn't display the text properly to let you know, it just fails (Correctly)
The sound keeps firing every half second and overlapping itself instead of playing out then repeating (despite being properly defined as a 20second clip in description.ext)
Finally if you look at a locked door, get the Break-In option then move away...the Break-In option remains on your menu....

Other than that it does work...just need to iron the bugs out and would love some help.
Original thread is on another forum (not sure on the rules on linking to other forums) but not had any response from the original guy for 2 months and no help from anyone else either so...


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
I'll try replace it with the Combat check from playerbuild which IS working.
 
Back
Top