Advertisement
Guest User

object_build

a guest
May 23rd, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. private ["_array","_object","_item","_classname","_text","_build","_inside","_location","_nearObjects","_dis","_sfx"];
  2. _array = _this select 3;
  3. _object = _array select 0;
  4. _item = _array select 1;
  5. _classname = _array select 2;
  6. _text = _array select 3;
  7. _build = _array select 4;
  8. _dis = _array select 5;
  9. _sfx = _array select 6;
  10.  
  11. if (isNull _object) exitWith {};
  12.  
  13. player setVariable ["constructionObject", objNull];
  14.  
  15. //diag_log("Array: "+str(_array));
  16. //diag_log(format["Array: object: %1 item: %2, classname: %3, text: %4, build: %5, booleans: %6, dis: %7, sfx: %8", _object, _item, _classname, _text, _build, _booleans, _dis,_sfx]);
  17. _createPoints = {
  18. private ["_unit","_boundingBox","_points"];
  19. _unit = _this select 0;
  20. _scale = _this select 1;
  21. _boundingBox = boundingBox _unit;
  22. _boundingBox =[[((_boundingBox select 0) select 0) * _scale, ((_boundingBox select 0) select 1) * _scale, (_boundingBox select 0) select 2], [((_boundingBox select 1) select 0) * _scale, ((_boundingBox select 1) select 1) * _scale, (_boundingBox select 1) select 2]];
  23.  
  24. _points = [getPosATL _unit];
  25.  
  26. for "_i" from 1 to 0 step -0.5 do {
  27. for "_j" from 0 to 1 do {
  28. _points set [count _points, _unit modelToWorld [0, ((_boundingBox select 0) select 1) * _i, 0]];
  29. _points set [count _points, _unit modelToWorld [0, ((_boundingBox select 1) select 1) * _i, 0]];
  30. _points set [count _points, _unit modelToWorld [((_boundingBox select 0) select 0) * 0.5, ((_boundingBox select _j) select 1) * _i, 0]];
  31. _points set [count _points, _unit modelToWorld [((_boundingBox select 1) select 0) * 0.5, ((_boundingBox select _j) select 1) * _i, 0]];
  32. _points set [count _points, _unit modelToWorld [((_boundingBox select 0) select 0) * 1, ((_boundingBox select _j) select 1) * _i, 0]];
  33. _points set [count _points, _unit modelToWorld [((_boundingBox select 1) select 0) * 1, ((_boundingBox select _j) select 1) * _i, 0]];
  34. };
  35. };
  36. _points;
  37. };
  38.  
  39. _insideCheck = {
  40. private ["_x","_inside","_myX","_myY","_building","_unit","_boundingBox","_points","_min","_max"];
  41. _building = _this select 0;
  42. _unit = _this select 1;
  43.  
  44. _inside = false;
  45. //Change these to tweak collision detection
  46. _scale = switch (_this select 2) do {
  47. case "building": { 0.65 };
  48. case "tree": { 0.25 };
  49. case "picea": { 0.0 };
  50. };
  51.  
  52. _points = [_unit, _scale] call _createPoints;
  53.  
  54. _boundingBox = boundingBox _building;
  55. _min = _building modelToWorld (_boundingBox select 0);
  56. _max = _building modelToWorld (_boundingBox select 1);
  57. //diag_log format["boundingBox: %1 min: %2 max: %3", _boundingBox, _min, _max];
  58.  
  59. {
  60. _myX = _x select 0;
  61. _myY = _x select 1;
  62.  
  63. if ((_myX > ((_min select 0) min (_max select 0))) and {(_myX < ((_max select 0) max (_min select 0)))}) then {
  64. if ((_myY > ((_min select 1) min (_max select 1))) and {(_myY < ((_max select 1) max (_min select 1)))}) then {
  65. _inside = true;
  66. //diag_log format["result: %1", _inside];
  67. };
  68. };
  69.  
  70. if (_inside) exitWith {};
  71. } forEach _points;
  72.  
  73. _inside;
  74. };
  75.  
  76. if (_build) then {
  77. _inside = false;
  78. _nearObjects = nearestObjects [player, [], 15];
  79. //diag_log format["nearObjects: %1", _nearObjects];
  80. {
  81. if ((!isNull _x) and (!(_x == player)) and (!(_x == _object))) then {
  82. //diag_log format["object: %1 type: %2 string: %3 t_: %4 b_: %5 building: %6 vehicle: %7", _x, typeOf _x, str(_x), [": t_", str(_x)] call fnc_inString, [": b_", str(_x)] call fnc_inString, _x isKindOf "Building", _x isKindOf "AllVehicles"];
  83. switch true do {
  84. case ((_x isKindOf "Building") or (_x isKindOf "AllVehicles") or (["rock", str(_x)] call fnc_inString)): { //Building or Vehicle or Rock
  85. _inside = [_x, _object, "building"] call _insideCheck;
  86. if (!_inside) then {
  87. _inside = [_object, _x, "building"] call _insideCheck;
  88. };
  89. //diag_log "BUILDING";
  90. };
  91. case ([": t_picea", str(_x)] call fnc_inString): {
  92. _inside = [_object, _x, "picea"] call _insideCheck;
  93. //diag_log "PICEA";
  94. };
  95.  
  96. case (([": t_", str(_x)] call fnc_inString) or ([": b_", str(_x)] call fnc_inString)): { //Tree or Bush
  97. _inside = [_object, _x, "tree"] call _insideCheck;
  98. //diag_log "TREE";
  99. };
  100. };
  101. //diag_log format["result: %1", _inside];
  102. };
  103. if (_inside) exitWith {};
  104. }forEach _nearObjects;
  105.  
  106. _inside = false;
  107. if (!_inside) then {
  108. [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
  109. [player,_dis,true,(getPosATL player)] call player_alertZombies;
  110.  
  111. player playActionNow "Medic";
  112.  
  113. sleep 5;
  114.  
  115. _location = getPosATL _object;
  116. _object setPosATL [_location select 0, _location select 1, 0.01];
  117. _object setDir (getDir _object);
  118.  
  119. player reveal _object;
  120.  
  121. _object setVariable ["characterID",dayz_characterID,true];
  122.  
  123. if (_object isKindOf "TrapItems") then {
  124. if (getNumber (configFile >> "CfgVehicles" >> typeOf _object >> "initState") > 0) then {
  125. _object setVariable ["armed", true, true];
  126. } else {
  127. _object setVariable ["armed", false, true];
  128. };
  129. };
  130.  
  131. cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  132.  
  133. PVDZ_obj_Publish = [dayz_characterID,_object,[getDir _object, getPosATL _object],_classname];
  134. publicVariableServer "PVDZ_obj_Publish";
  135.  
  136. r_action_count = 0;
  137. cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  138. } else {
  139. r_action_count = 0;
  140. deleteVehicle _object;
  141. player addMagazine _item;
  142. cutText [format[localize "str_build_failed_01",_text], "PLAIN DOWN"];
  143. };
  144. } else {
  145. r_action_count = 0;
  146. deleteVehicle _object;
  147. player addMagazine _item;
  148. cutText [format[localize "str_build_failed_01",_text], "PLAIN DOWN"];
  149. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement