Jump to content

Recommended Posts

I need to get a flashlight on a PDW, which isn't equipped with a flashlight slot. Is there a generic way to script a light onto any weapon? Not necessarily the flashlight object, but any kind of light will do, as long as it "acts" like a weapon flashlight. Thanks much.

Share this post


Link to post
Share on other sites

Well... I'm not sure you can script a flashlight beam.  You can add a light point (spot light) in direction of the weapon. That works fine in SP. In MP, each player will switch on/switch off his light but the created light will stay local. That means other players will not see the other players' light...

Of course, it's always possible to script all lights for all players... but I can't imagine the resource consuming for updating the weapons movements, intersects with world objects, then the positions of spots... A decent way for that is far above my head.

 

So, for SP (and MP alone in the beam 😊), just run (in init.sqf, a trigger or else)

 

0 = [] spawn {
    if (!hasInterface) exitWith {};
    waitUntil {local player};
    flLight = "#lightpoint" createVehicleLocal [0,0,0];
    flLight setLightBrightness 0;
    flLight setLightAmbient[0,0,0];
    flLight setLightColor[255, 255, 200];
    flLight setLightUseFlare true;
    flLight setLightFlareSize 5;
    flLight setLightDayLight TRUE;
    SLBright = 0;
    SLAmbient = [0,0,0];
    _SL_on = {
      player addAction ["<t color='#11ff11'>S.L. On</t>", {
        params ["_tgt","_caller","_id"];
        private _SLMenu = (_tgt actionParams _id) select 0;
          if (_SLMenu isEqualTo "<t color='#11ff11'>S.L. On</t>") then {
            _SLMenu = "<t color='#ff1111'>S.L. Off</t>";
          SLBright = 0.05;
          SLAmbient = [0.255, 0.255, 0.2];
        } else {
          _SLMenu = "<t color='#11ff11'>S.L. On</t>";
          SLBright = 0;
          SLAmbient = [0,0,0];
        };
        (_this select 1) setUserActionText [(_this select 2),_SLMenu];
      },nil,0.8,false,true,"", ""]
    };
 
  call _SL_on;
  player addEventHandler ["respawn", {call _SL_on}];
 
    addMissionEventHandler ["EachFrame", {
        _ins = lineIntersectsSurfaces [eyepos player,eyePos player vectorAdd (player weaponDirection currentWeapon player vectorMultiply 100),player,objNull,true,1,"VIEW","FIRE"];
         if (count _ins >0) then {
             flLight setPosASL (_ins select 0 select 0);
            flLight setLightBrightness SLBright;
            flLight setLightAmbient SLAmbient;
        } else {
            flLight setLightBrightness 0;
            flLight setLightAmbient  [0,0,0]
        };
    }];
};

That creates an action menu for player(s). You can add a condition on weapon's type if you want.

 

  • Like 4
  • Thanks 1

Share this post


Link to post
Share on other sites
11 hours ago, pierremgi said:

Well... I'm not sure you can script a flashlight beam.  You can add a light point (spot light) in direction of the weapon. That works fine in SP. In MP, each player will switch on/switch off his light but the created light will stay local. That means other players will not see the other players' light...

Of course, it's always possible to script all lights for all players... but I can't imagine the resource consuming for updating the weapons movements, intersects with world objects, then the positions of spots... A decent way for that is far above my head.

 

So, for SP (and MP alone in the beam 😊), just run (in init.sqf, a trigger or else)

 

That creates an action menu for player(s). You can add a condition on weapon's type if you want.

 

I noticed that you use flLight setLightDayLight TRUE;

 

Does that really work?

 

In my tests setLightDayLight will not make light emitters work during the day. (Perhaps it is a bug?)

Share this post


Link to post
Share on other sites

That seems to work at dawn / dusk. Not really tested deeper.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×