fired_laser.sqf 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Author: HorribleGoat
  3. Author: Turmio
  4. Author: Battlestad
  5. Description:
  6. Searches for start point and end point from object and calculates crosshair to screen based on direction vector. Also returns the distance to the crosshair position from weapon end position.
  7. Parameter(s):
  8. 0 (Mandatory):
  9. OBJECT - Data object
  10. 1 (Mandatory):
  11. STRING - Weapon start point name
  12. 2 (Mandatory):
  13. STRING - Weapon end point name
  14. 3 (Mandatory):
  15. STRING - Path to crosshair img
  16. Returns:
  17. NUMBER - Distance to target
  18. */
  19. // should only be executed on server, but will need proper testing in a MP environment
  20. if (isServer) then {
  21. params ["_v","_w"];
  22. private [
  23. "_selectionLod",
  24. "_weaponStartPos",
  25. "_weaponEndPos",
  26. "_weaponWorldStart",
  27. "_weaponWorldEnd",
  28. "_weaponDir",
  29. "_maxDistance",
  30. "_crosshairPos",
  31. "_intersection"
  32. ];
  33. private [
  34. "_laser_chamber",
  35. "_laser_muzzle",
  36. "_laser_anim"
  37. ];
  38. _v = _this select 0;
  39. _w = _this select 1;
  40. //hintsilent str _w;
  41. // replace weapons classnames with whatever your left and right lasers will be named
  42. if (_w == "RD501_turret_laat_ball_beam_l" || _w == "RD501_turret_laat_ball_beam_r") then {
  43. if (_w == "RD501_turret_laat_ball_beam_l") then {
  44. _laser_chamber = "Laser_L_chamber";
  45. _laser_muzzle = "Laser_L_muzzle";
  46. _laser_anim = "Laser"; // would be cleaner if you renamed this to "Laser_Left" or something
  47. } else {
  48. if (_w == "RD501_turret_laat_ball_beam_r") then { // replace this with the new "Laser_weapon_right" weapon classname
  49. _laser_chamber = "Lazer_R_chamber";// replace this with new "Laser_R_chamber" that you set up in the memory lod
  50. _laser_muzzle = "Laser_R_muzzle";// replace this with new "Laser_R_muzzle" that you set up in the memory lod
  51. _laser_anim = "Laser_R";// replace this with a new animationSource (Laser_Right or something)
  52. };
  53. } ; //else {
  54. // if (_w == "ParticleBeamCannon_F") then { // replace this with the new "Laser_weapon_right" weapon classname
  55. // _laser_chamber = "Lazer_F_chamber";// replace this with new "Laser_R_chamber" that you set up in the memory lod
  56. // _laser_muzzle = "Laser_F_muzzle";// replace this with new "Laser_R_muzzle" that you set up in the memory lod
  57. // _laser_anim = "Laser_F";// replace this with a new animationSource (Laser_Right or something)
  58. // };
  59. // };
  60. if (_v animationphase _laser_anim == 0) then {
  61. _selectionLod= "memory";
  62. _weaponStartPos = _v selectionPosition [_laser_chamber ,_selectionLod];
  63. _weaponEndPos = _v selectionPosition [_laser_muzzle ,_selectionLod];
  64. _weaponWorldStart = _v modelToWorld _weaponStartPos;
  65. _weaponWorldEnd = _v modelToWorld _weaponEndPos;
  66. _weaponDir = _weaponWorldStart vectorFromTo _weaponWorldEnd;
  67. _maxDistance = 2000;
  68. _crosshairPos = [(_weaponWorldStart select 0 )+ ((_weaponDir select 0)*_maxDistance ),(_weaponWorldStart select 1 ) + ((_weaponDir select 1)*_maxDistance ),(_weaponWorldStart select 2)+ ((_weaponDir select 2)*_maxDistance )];
  69. _intersection = lineIntersectsSurfaces
  70. [
  71. AGLToASL _weaponWorldEnd,
  72. AGLToASL _crosshairPos,
  73. vehicle player,
  74. player,
  75. true,
  76. 1,
  77. "VIEW",
  78. "GEOM"
  79. ];
  80. if (count _intersection > 0) then
  81. {
  82. _crosshairPos = ASLToAGL (_intersection select 0 select 0);
  83. };
  84. _distanceToTarget = _weaponWorldEnd vectorDistance _crosshairPos;
  85. //hintSilent str _distanceToTarget;
  86. _v animateSource [_laser_anim, _distanceToTarget, true];
  87. sleep 0.08;
  88. _v animateSource [_laser_anim, 0, true];
  89. };
  90. };
  91. };