Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- _player should be the player unit building the structure.
- _objectType should be the class name of the object to be built.
- _cost should be an array of [Supply, Ammo, Fuel] integers.
- _fob should be the FOB variable name.
- */
- params["_player", "_objectType", "_cost", "_fob"];
- /* Check if the needed supplies exists at the current fob */
- private _resources = TRA_playerResources getOrDefault [_fob, [1000,1000,1000]];
- if !([_resources, _cost] call TRA_fnc_resourceCheck) exitWith {
- ["TaskFailed", ["", "Not enough resources to build object!"]] call BIS_fnc_showNotification;
- false
- };
- /* Create Provided Object */
- private _object = createVehicle[_objectType, [1, 1, 1000], [], 0, "NONE"];
- /* Attach object to player */
- private _playerDist = 10;
- _object attachTo[_player, [0, _playerDist, 0]];
- /* Make the object a mission variable in order to grab it later. */
- missionNamespace setVariable ['TRA_buildObject', _object];
- /* Make mission variables to be used later */
- missionNamespace setVariable ['TRA_buildHeight', 0];
- missionNamespace setVariable ['TRA_buildRotation', 0];
- missionNamespace setVariable ['TRA_buildSuccess', false];
- missionNamespace setVariable ['TRA_buildCancel', false];
- /* Create display in order to reserve keys for object manipulation. */
- private _id = (findDisplay 46) displayAddEventHandler ["KeyDown","_this call TRA_rotateObject"];
- private _id2 = (findDisplay 46) displayAddEventHandler ["MouseButtonDown","_this call TRA_cancelRotation"];
- /* ID needed to escape the FOB orienting */
- missionNamespace setVariable ['TRA_buildDisplayID', _id];
- missionNamespace setVariable ['TRA_cancelDisplayID', _id2];
- TRA_buildCtrlPic = "res\Controls.paa";
- with uiNamespace do {
- TRA_buildControls = findDisplay 46 ctrlCreate ["RscPicture", -1];
- TRA_buildControls ctrlSetPosition [0.1, 0.4, 0.7, 0.5];
- TRA_buildControls ctrlCommit 0;
- };
- (uiNamespace getVariable "TRA_buildControls") ctrlSetText (TRA_buildCtrlPic);
- TRA_rotateObject = {
- params["_display", "_key", "_shift", "_ctrl", "_alt"];
- if (isNil 'TRA_buildObject') exitWith {
- systemChat "Build object was not set as a missionNamespace variable";
- false;
- };
- if (missionNamespace getVariable ['TRA_buildCancel', false]) then {
- _key = 1000;
- };
- if !(_key in [203, 205, 200, 208, 57, 1000]) exitWith {
- false
- };
- private _rotation = TRA_buildRotation;
- private _height = TRA_buildHeight;
- private _rotate = false;
- private _elevate = false;
- private _rotateIncrement = 1;
- private _elevateIncrement = 0.2;
- switch (_key) do {
- case 203: {
- _rotation = _rotation + _rotateIncrement;
- _rotate = true;
- };
- case 205: {
- _rotation = _rotation - _rotateIncrement;
- _rotate = true;
- };
- case 200: {
- _height = _height + _elevateIncrement;
- _elevate = true;
- };
- case 208: {
- _height = _height - _elevateIncrement;
- _elevate = true;
- };
- case 57: {
- (findDisplay 46) displayRemoveEventHandler ["KeyDown", TRA_buildDisplayID];
- detach TRA_buildObject;
- missionNamespace setVariable ['TRA_buildHeight', 0];
- missionNamespace setVariable ['TRA_buildRotation', 0];
- missionNamespace setVariable ['TRA_buildObject', objNull];
- (uiNamespace getVariable "TRA_buildControls") ctrlSetText ("");
- missionNamespace setVariable ['TRA_buildSuccess', true];
- ["TaskSucceeded", ["", "Object Built!"]] call BIS_fnc_showNotification;
- };
- case 1000: {
- (findDisplay 46) displayRemoveEventHandler ["KeyDown", TRA_buildDisplayID];
- detach TRA_buildObject;
- deleteVehicle TRA_buildObject;
- missionNamespace setVariable ['TRA_buildHeight', 0];
- missionNamespace setVariable ['TRA_buildRotation', 0];
- missionNamespace setVariable ['TRA_buildObject', objNull];
- (uiNamespace getVariable "TRA_buildControls") ctrlSetText ("");
- missionNamespace setVariable ['TRA_buildSuccess', false];
- ["TaskFailed", ["", "Object build canceled!"]] call BIS_fnc_showNotification;
- };
- };
- if (_rotate) then {
- TRA_buildObject setDir _rotation;
- };
- if (_elevate) then {
- _player = attachedTo TRA_buildObject;
- TRA_buildObject attachTo [_player, [0, 10, _height]];
- TRA_buildObject setDir TRA_buildRotation;
- };
- TRA_buildRotation = _rotation;
- TRA_buildHeight = _height;
- true
- };
- TRA_cancelRotation = {
- params["_display", "_key", "_shift", "_ctrl", "_alt"];
- if (_key isNotEqualTo 1) exitWith {
- false
- };
- // systemChat (str _this);
- missionNamespace setVariable ['TRA_buildCancel', true];
- (findDisplay 46) displayRemoveEventHandler ["KeyDown", TRA_cancelDisplayID];
- false
- };
- /* While build KeyDown event handler exists, do: */
- while {(findDisplay 46) getEventHandlerInfo ["KeyDown", TRA_buildDisplayID] select 0} do {
- sleep 1;
- };
- /* Return whether build was a success or failure after KeyDown eh is removed */
- missionNamespace getVariable ['TRA_buildSuccess', false];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement