Simple Flashlight

Scripts and code that enhance the gameplay functionality of the engine.
8 posts Page 1 of 1
Jason Campbell
Posts: 331
Joined: Fri Feb 13, 2015 2:51 am
 
by Jason Campbell » Sun Mar 31, 2019 9:25 am
Here is a very simple flashlight that uses the weapons fire light as a flashlight.

Some of it was from a few different posts from the old forum.

Some obvious problems are that the flash of light from your weapon is disabled while the flashlight is on. The AI Turret doesn't have light.

Really just a starting point but thought it might be useful.

lightRadius is equal to "range" so change that for distance of beam.

Download:
https://drive.google.com/open?id=1CreRU ... Yh0NoeD417

Install instructions:

1) in game/scripts/client/default.bind.cs

add to bottom:

//Add Flashlight

$FlashlightVar = "1";
function toggleFlashlight(%val)
{
   if (%val)
   {
      if($FlashlightVar)
      {
         $FlashlightVar = "0";
         commandToServer('EnableFlashlight');
      }
      else
      {
         $FlashlightVar = "1";
         commandToServer('DisableFlashlight');
      }
   }
}
moveMap.bind( keyboard, f, toggleFlashlight );


2) in game/scripts/server/player.cs

add to bottom:
//Add Flashlight

function Player::FlashlightEnable(%player)
{
    %player.getMountedImage($WeaponSlot).setFieldValue("lightType", "SpotLight");
    %player.getMountedImage($WeaponSlot).setFieldValue("lightRadius", "25"); 
}

function Player::FlashlightDisable(%player)
{
     %player.getMountedImage($WeaponSlot).setFieldValue("lightType", "WeaponFireLight");
     %player.getMountedImage($WeaponSlot).setFieldValue("lightRadius", "10");
}
3) in game/scripts/server/commands.cs

add to bottom:
//Add Flashlight

function serverCmdEnableFlashlight(%client)
 {
    %player = %client.player;
    %player.FlashlightEnable();
 }


function serverCmdDisableFlashlight(%client)
 {
    %player = %client.player;
    %player.FlashlightDisable();
 }

Attachments

flashLight.jpg
flashLight.jpg (123.34 KiB) Viewed 1849 times
SimpleFlashlight.zip
install Flashlight
(12.84 KiB) Downloaded 28 times
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Sun Mar 31, 2019 2:12 pm
Thanks very much for this Jason,....for my project I just need a flashlight so it's great resource....Thanks a lot.
Jason Campbell
Posts: 331
Joined: Fri Feb 13, 2015 2:51 am
 
by Jason Campbell » Sun Mar 31, 2019 3:46 pm
No problem, it does leave a bit to be desired. It was your night screenshots that made me think of posting this. It was just sitting there in my last project.
marauder2k9
Posts: 287
Joined: Wed Feb 18, 2015 7:36 am
by marauder2k9 » Sun Mar 31, 2019 10:10 pm
another addition to this is to add a cookie to the light
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Mon Apr 01, 2019 11:27 pm
another addition to this is to add a cookie to the light
...what are the cookies for?
Azaezel
Posts: 461
Joined: Tue Feb 03, 2015 9:50 pm
 
by Azaezel » Mon Apr 01, 2019 11:45 pm
marauder2k9
Posts: 287
Joined: Wed Feb 18, 2015 7:36 am
by marauder2k9 » Tue Apr 02, 2019 12:43 am
exactly what az shared only in png format lol

Do cookies need to be png format ? or can they be any format?
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Tue Apr 02, 2019 3:01 am
Thanks...i see!...projected shadows
..I think the best is png....tga, jpge2000....only what they support the alpha channel.
8 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 9 guests