1
0

fn_beam.sqf 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Author: TheTimidShade
  3. Description:
  4. Creates laser beam on the given position. Should be executed on all connected clients and server using remoteExec.
  5. Parameters:
  6. 0: OBJECT - The object the beam is created above.
  7. 1: ARRAY (OPTIONAL) - Colour of the beam in format [r,g,b].
  8. 2: ARRAY (OPTIONAL) - Colour of dust created on impact in format [r,g,b].
  9. Returns:
  10. NONE
  11. */
  12. params [
  13. ["_target", objNull, [objNull]],
  14. ["_beamColour", [1,0.6,0.2], [[]]],
  15. ["_debrisColour", [0.3, 0.27, 0.15], [[]]]
  16. ];
  17. // input validation
  18. if (isNull _target) exitWith {systemChat "Invalid position given for beam target! Exited";};
  19. if (count _beamColour < 3) then {_beamColour = [1,0.6,0.2]; systemChat "Invalid colour given for beam, default used instead";};
  20. if (count _debrisColour < 3) then {_debrisColour = [0.3, 0.27, 0.15]; systemChat "Invalid colour given for beam debris, default used instead";};
  21. private _maxKillRange = 200;
  22. private _maxDamageRange = 400;
  23. private _targetPos = getPosATL _target;
  24. // create emitters
  25. private _impactEmitter = "Land_HelipadEmpty_F" createVehicleLocal _targetPos;
  26. private _beamEmitter = "Land_Battery_F" createVehicleLocal _targetPos;
  27. _beamEmitter setPosATL [_targetPos#0, _targetPos#1, 2000];
  28. // accelerate beam emitter towards ground
  29. _beamEmitter setVelocity [0,0,-600];
  30. // create bright flash when beam is initially fired
  31. _flash = "#lightpoint" createVehicleLocal (getpos _beamEmitter);
  32. _flash setLightBrightness 300;
  33. _flash setLightAmbient _beamColour;
  34. _flash setLightColor _beamColour;
  35. _flash lightAttachObject [_beamEmitter, [0,0,200]];
  36. _flash spawn {sleep 0.1; deleteVehicle _this;};
  37. // create beam particles
  38. [_beamEmitter, _beamColour, _targetPos] spawn tts_beam_fnc_rayParticles;
  39. // wait until the beam is almost halfway and play laser sound
  40. waitUntil {sleep 0.01; ((getPosATL _beamEmitter)#2 < 750)};
  41. _impactEmitter say3D ["laser", 20000, 1, false];
  42. // wait until touching ground/near target
  43. waitUntil {sleep 0.01; vectorMagnitude (velocity _beamEmitter) < 20 || _beamEmitter distance _targetPos < 5 || (getPosATL _beamEmitter)#2 < 5};
  44. _impactEmitter say3D ["laser_impact", 20000, 1, false];
  45. _impactEmitter setPosATL (getPosATL _beamEmitter);
  46. deleteVehicle _beamEmitter;
  47. // destroy/damage any nearby units/objects/buildings
  48. if (isServer) then {[_impactEmitter, _maxKillRange, _maxDamageRange] spawn tts_beam_fnc_explosionDamage;};
  49. // explosion particles
  50. [_impactEmitter, _debrisColour] spawn tts_beam_fnc_explosionParticles;
  51. // impact post processing effects
  52. [_target] spawn tts_beam_fnc_postProcessEffects;
  53. sleep 30;
  54. deleteVehicle _impactEmitter;