Last active
August 29, 2015 14:16
-
-
Save Neefay/bc1555c81c8c63620d60 to your computer and use it in GitHub Desktop.
How to use box open script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (isServer) then { | |
| _initBox = { | |
| _box = _this select 0; | |
| _box setVariable ["used",false,true]; | |
| _box setVariable ["looted",false,true]; | |
| clearItemCargoGlobal _box; | |
| clearMagazineCargoGlobal _box; | |
| clearWeaponCargoGlobal _box; | |
| }; | |
| [myBox] call _initBox; | |
| startBoxes = { | |
| myBox addAction ["<t color='#FF0000'>Open the box</t>", "mission\scripts\open-crate.sqf",nil,0.5,true,true,"'","!(myBox getVariable 'used')"]; | |
| }; | |
| publicVariable "startBoxes"; | |
| [[],"startBoxes",true,true] spawn BIS_fnc_MP; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| HOW TO USE THIS SCRIPT: | |
| 1 - Place the code inside "init-code.sqf" anywhere within your init.sqf. | |
| 2 - Save "open-crate.sqf" inside your "mission\scripts" folder. | |
| 3 - Make a box/crate/whatever object, name it something like "myBox". | |
| 4 - If you want to customize what happens when the box is opened, use line @46 in the "open-crate.sqf" script, within the { }. | |
| 5 - Customize the desired time needed on line @5 of the "open-crate.sqf" script. | |
| 6 - If it all works, you should have an action to open the box. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _safe = _this select 0; | |
| _caller = _this select 1; | |
| _minutes = 5; | |
| _difficulty = (_minutes*60); | |
| _listEasy = []; | |
| _crackTime = 0; | |
| _remaining = _difficulty; | |
| _extramsg = "This is a simple lock so it won't take long."; | |
| if (!(_caller in _list)) then { | |
| _difficulty = _difficulty * 3; | |
| _extramsg = "You have no idea what you're doing so this will take a while."; | |
| }; | |
| _safe setVariable ["used",true,true]; | |
| cancelCrack = false; | |
| waituntil {!(IsNull (findDisplay 46))}; | |
| _EHid = (findDisplay 46) displayAddEventHandler ["KeyDown"," | |
| if ((_this select 1 == 1) || (_this select 1 == 30) || (_this select 1 == 31) || (_this select 1 == 32) ||(_this select 1 == 17) ) then {cancelCrack = true;} else {cancelCrack = false;}"]; | |
| [-1,{_this switchMove "Acts_TreatingWounded05"},_caller] call CBA_fnc_globalExecute; | |
| _playerHealth = getDammage _caller; | |
| while {(_crackTime < _difficulty)} do { | |
| hintSilent format ["********************\n\n You start opening the crate.\n\n%1 minute(s) remaining.\n\n %2 \n\n********************",_remaining/60, _extramsg]; | |
| if (cancelCrack) exitWith { cancelCrack = false }; | |
| if ((_playerHealth != getDammage _caller)) exitWith {}; | |
| _crackTime = _crackTime + 1; | |
| if ((_crackTime mod 60) == 0) then { | |
| _remaining = _remaining - 60; | |
| }; | |
| sleep 1; | |
| }; | |
| if (_crackTime == _difficulty) exitWith { | |
| hint "You've successfully opened the box."; | |
| switch(_safe) do { | |
| case myBox: { }; | |
| }; | |
| _safe setVariable ["looted",true,true]; | |
| [-1,{(_this select 0) switchMove "aidlpknlmstpslowwrfldnon_idlesteady02"},[_caller]] call CBA_fnc_globalExecute; | |
| }; | |
| hint "Opening stopped, try again!"; | |
| _safe setVariable ["used",false,true]; | |
| [-1,{ (_this select 0) switchMove "aidlpknlmstpslowwrfldnon_idlesteady02" },[_caller]] call CBA_fnc_globalExecute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment