Advertisement
Guest User

VehicleKeyChanger.sqf 

a guest
Jan 28th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. /***********************************/
  2. /* Vehicle Key Changer v1.3 */
  3. /* Written by OtterNas3 */
  4. /* January, 11, 2014 */
  5. /* Last update: 02/20/2014 */
  6. /***********************************/
  7.  
  8.  
  9. /* Setup the private variables */
  10. private ["_magazinesPlayer","_max","_j","_actionArray","_targetVehicle","_targetVehicleID","_targetVehicleUID","_playerKeys","_playerKeysDisplayName","_targetVehicleKeyName","_itemKeyName","_targetVehicleClassname","_targetVehiclePos","_targetVehicleDir","_Price","_claimingPrice"];
  11.  
  12. /* Remove the Action Menu entry */
  13. player removeAction s_player_copyToKey;
  14. s_player_copyToKey = 0;
  15.  
  16. /* Get the array and setup the variables */
  17. _actionArray = _this select 3;
  18. _targetVehicle = _actionArray select 0;
  19. _targetVehicleID = _targetVehicle getVariable ["ObjectID","0"];
  20. _targetVehicleUID = _targetVehicle getVariable ["ObjectUID","0"];
  21.  
  22. /* Check if the Vehicle is in the Database, if false exit */
  23. if (_targetVehicleID == "0" && _targetVehicleUID == "0") exitWith {s_player_copyToKey = -1;};
  24.  
  25. /* Setup more variables */
  26. _playerKeys = _actionArray select 1;
  27. _playerKeysDisplayName = _actionArray select 3;
  28. _targetVehicleKeyName = _actionArray select 4;
  29. _itemKeyName = _actionArray select 5;
  30. _Price = _actionArray select 6;
  31. _claimingPrice = _actionArray select 7;
  32. _targetVehicleClassname = typeOf _targetVehicle;
  33. _targetVehiclePos = getPosATL _targetVehicle;
  34. _targetVehicleDir = getDir _targetVehicle;
  35.  
  36. /* Setup the Key Names list to select from */
  37. keyNameList = [];
  38. for "_i" from 0 to (count _playerKeysDisplayName) -1 do {
  39. keyNameList set [(count keyNameList), _playerKeysDisplayName select _i];
  40. };
  41.  
  42. /* Setup the Key Numbers list to select from */
  43. keyNumberList = [];
  44. for "_i" from 0 to (count _playerKeys) -1 do {
  45. keyNumberList set [(count keyNumberList), _playerKeys select _i];
  46. };
  47.  
  48. /* Resetting menu variables*/
  49. keyNameSelect = "";
  50. exitscript = true;
  51. snext = false;
  52.  
  53. /* Creating the menu */
  54. copyMenu =
  55. {
  56. private ["_keyMenu","_keyArray"];
  57. _keyMenu = [["",true], ["Change Vehicle to Key:", [-1], "", -5, [["expression", ""]], "1", "0"]];
  58. for "_i" from (_this select 0) to (_this select 1) do
  59. {
  60. _keyArray = [format['%1', keyNameList select (_i)], [_i - (_this select 0) + 2], "", -5, [["expression", format ["keyNameSelect = keyNameList select %1; keyNumberSelect = keyNumberList select %1", _i]]], "1", "1"];
  61. _keyMenu set [_i + 2, _keyArray];
  62. };
  63. _keyMenu set [(_this select 1) + 2, ["", [-1], "", -5, [["expression", ""]], "1", "0"]];
  64. if (count keyNameList > (_this select 1)) then
  65. {
  66. _keyMenu set [(_this select 1) + 3, ["Next", [12], "", -5, [["expression", "snext = true;"]], "1", "1"]];
  67. } else {
  68. _keyMenu set [(_this select 1) + 3, ["", [-1], "", -5, [["expression", ""]], "1", "0"]];
  69. };
  70. _keyMenu set [(_this select 1) + 4, ["Exit", [13], "", -5, [["expression", "keyNameSelect = 'exitscript';"]], "1", "1"]];
  71. showCommandingMenu "#USER:_keyMenu";
  72. };
  73.  
  74. /* Wait for the player to select a Key from the list */
  75. _j = 0;
  76. _max = 10;
  77. if (_max > 9) then {_max = 10;};
  78. while {keyNameSelect == ""} do {
  79. [_j, (_j + _max) min (count keyNameList)] call copyMenu;
  80. _j = _j + _max;
  81. waitUntil {keyNameSelect != "" || snext};
  82. snext = false;
  83. };
  84.  
  85. /* Player selected a Key, lets make the Vehicle update call */
  86. if (keyNameSelect != "exitscript") then {
  87.  
  88. /* Check again for the needed TinBar or claiming price and remove em from the players inventory */
  89. _magazinesPlayer = magazines player;
  90. _playerDollars = player getVariable['cashMoney', 0];
  91. if (_Price > 0) then {
  92. if (_Price < _playerDollars) then {
  93. //[player, _Price, 1] call BIS_fnc_invRemove;
  94. player setVariable["cashMoney",_playerDollars - _Price, true];
  95. systemChat (format["Keychange costs %1 Dollars, thanks for your Payment!", _Price]);
  96. } else {
  97. systemChat (format["Keychange costs %1 Dollars, you had it and tried to trick the system - Keychange for this Vehicle disabled!", Price]);
  98. _targetVehicle setVariable ["VKC_disabled", 1, true];
  99. s_player_copyToKey = -1;
  100. breakOut "exit";
  101. };
  102. };
  103. if (_claimingPrice > 0) then {
  104. if (_claimingPrice < _playerDollars) then {
  105. //[player, _claimingPrice, 1] call BIS_fnc_invRemove;
  106. player setVariable["cashMoney",_playerDollars - _claimingPrice, true];
  107.  
  108. systemChat (format["Claiming Vehicle costs %1 Dollars, thanks for your Payment!", _claimingPrice]);
  109. } else {
  110. systemChat (format["Claiming Vehicle costs %1 Dollars, you had it and tried to trick the system - Claiming for this Vehicle disabled!", Price]);
  111. _targetVehicle setVariable ["VKC_claiming_disabled", 1, true];
  112. s_player_copyToKey = -1;
  113. breakOut "exit";
  114. };
  115. };
  116.  
  117. /* We got the Money lets do our Job */
  118. /* Lock the vehicle */
  119. _targetVehicle setVehicleLock "LOCKED";
  120.  
  121. /* The super duper OneForAllAnimation... */
  122. player playActionNow "Medic";
  123.  
  124. /* Remove the Key from the Toolbelt of the player and put it in the Backpack - No Backpack and the Key gets lost */
  125. if (_itemKeyName != "0") then {
  126. if (!isNull (unitBackpack player)) then {
  127. [player, _itemKeyName, 1] call BIS_fnc_invRemove;
  128. (unitBackpack (vehicle player)) addWeaponCargoGlobal [_itemKeyName, 1];
  129. systemChat (format["%1 has been moved to your Backpack", _targetVehicleKeyName]);
  130. };
  131. };
  132.  
  133. /* Giving unique UID for claimed vehicles */
  134. if (_targetVehicleUID=="0") then {
  135. _targetVehicleUID = _targetVehicle call dayz_objectUID_vkc;
  136. _targetVehicle setVariable ["ObjectUID",_targetVehicleUID,true]; // It does probably nothing and it's not needed :)
  137. };
  138.  
  139. /* This calls the custom update function which we put it in server_updateObject.sqf */
  140. PVDZE_veh_Update = [_targetVehicle, "vehiclekey", player, _targetVehicleClassname, keyNumberSelect, keyNameSelect, _targetVehicleID, _targetVehicleUID];
  141. publicVariableServer "PVDZE_veh_Update";
  142.  
  143. /* Inform the player about the success and tell him to check the Key */
  144. systemChat (format["Changed Vehicle Key to %1", keyNameSelect]);
  145. if (_targetVehicleKeyName != "0") then {
  146. systemChat (format["Please check Vehicle function with %1 before you throw away %2!", keyNameSelect, _targetVehicleKeyName]);
  147. };
  148. };
  149.  
  150. /* Reset the action menu variable for a new run */
  151. s_player_copyToKey = -1;
  152.  
  153. /**************************************/
  154. /* That's it, hope you enjoy this Mod */
  155. /* */
  156. /* Yours sincerly, */
  157. /* Otter */
  158. /**************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement