Is it possible to create a client-side only "spotlight"?
22 replies, posted
I would like to know if it's possible to create a client-side only spotlight because I want to modify Teta_Bonita's nightvision script for it creates a client-side spotlight to see better in total darkness. The spotlight would be as big as the player's screen, and would be positioned where the player aims.
If this is possible, and you feel like helping me, please insert an exemple in Teta_Bonita's code below please:
[code]
-- Clientside Night-Vision
-- Version 1.2
-- by Teta_Bonita
-- console commands:
-- toggle_nightvision -toggles nightvision on/off
if not CLIENT then return end -- Clientside only
-- ADJUSTABLE SETTINGS
local AdjustCoefficient = 0.02 -- The bigger this number, the more quickly the nightvision starts up
-- Colormod Settings
local Color_Brightness = 0.8
local Color_Contrast = 1.1
local Color_AddGreen = -0.35
local Color_MultiplyGreen = 0.028
-- Alpha Add Settings (for the CSS nightvision shader)
local AlphaAdd_Alpha = 1
local AlphaAdd_Passes = 1 -- The bigger this integer, the more brightness is added
-- alpha add = AlphaAdd_Alpha*AlphaAdd_Passes
-- Bloom Settings
local Bloom_Multiply = 3.6
local Bloom_Darken = 0
local Bloom_Blur = 0.1
local Bloom_ColorMul = 0.5
local Bloom_Passes = 1 -- Should be an integer
-- END ADJUSTABLE SETTINGS
local matNightVision = Material("effects/nightvision") -- CSS nightvision
matNightVision:SetMaterialFloat( "$alpha", AlphaAdd_Alpha )
local Color_Tab =
{
[ "$pp_colour_addr" ] = -1,
[ "$pp_colour_addg" ] = Color_AddGreen,
[ "$pp_colour_addb" ] = -1,
[ "$pp_colour_brightness" ] = Color_Brightness,
[ "$pp_colour_contrast" ] = Color_Contrast,
[ "$pp_colour_colour" ] = 0,
[ "$pp_colour_mulr" ] = 0 ,
[ "$pp_colour_mulg" ] = Color_MultiplyGreen,
[ "$pp_colour_mulb" ] = 0
}
local sndOn = Sound( "items/nvg_on.wav" )
local sndOff = Sound( "items/nvg_off.wav" )
if render.GetDXLevel() < 80 then -- the nightvision shader reverts to a white overlay for dx7 cards, so any more alpha add than 1 gives a white screen
AlphaAdd_Passes = 1
AlphaAdd_Alpha = 0.6 -- Make it less to reduce the whiteness
end
local DoNightVision = false
local CurScale = 0.5
-- A most likely futile attempt to make things faster
local render = render
-- Main effect call
local function NightVisionFX()
if CurScale < 0.995 then
CurScale = CurScale + AdjustCoefficient * (1 - CurScale)
end
-- Alpha add
for i=1,AlphaAdd_Passes do
render.UpdateScreenEffectTexture()
render.SetMaterial( matNightVision )
render.DrawScreenQuad()
end
-- Colormod
Color_Tab[ "$pp_colour_brightness" ] = CurScale * Color_Brightness
Color_Tab[ "$pp_colour_contrast" ] = CurScale * Color_Contrast
DrawColorModify( Color_Tab )
-- Bloom
DrawBloom( Bloom_Darken, -- Darken
CurScale * Bloom_Multiply, -- Multiply
Bloom_Blur, -- Horizontal Blur
Bloom_Blur, -- Vertical Blur
Bloom_Passes, -- Passes
CurScale * Bloom_ColorMul, -- Color Multiplier
0, -- Red
1, -- Green
0 ) -- Blue
end
local function ToggleNightVision()
if DoNightVision then
DoNightVision = false
surface.PlaySound( sndOff )
hook.Remove( "RenderScreenspaceEffects", "NV_Render" )
else
DoNightVision = true
CurScale = 0.5 -- This makes the nightvision start off dark when it's turned back on (for effect)
surface.PlaySound( sndOn )
hook.Add( "RenderScreenspaceEffects", "NV_Render", NightVisionFX )
end
end
concommand.Add( "toggle_worshipper_nightvision", ToggleNightVision )
[/code]
This is an example of a flashlight I found on the internet (garrysmod.org). I would like the same thing, but only clientside.
Without the spotlight:
[img]http://s3.garrysmod.org/img/dl/16247_1.jpg[/img]
With the spotlight:
[img]http://s3.garrysmod.org/img/dl/16247_2.jpg[/img]
Looking at the script you posted, I see nothing about lighting, just about modifying the brightness/contrast clientside.
I posted a brightness/contrast clientside script, because I want to add a clientside flashlight/lamp/spotlight into it.
I tried to add a simple DynamicLight into this code, but it's lagging like shit because it takes a lot of informations and I tried to add a Lamp and it didn't work so I need help and it's why I posted a thread.
(My english is not perfect, sorry.)
Create a dynamic light only on the client you want to be able to see it from.
It's too much lagging and this is not what I want, I want a client-side only flashlight.
Read my freaking post before posting anything...
Parent a light entity to the players gun? Then turn it off and on..
Easy to say, but hard to code, huh?
will post code when i'm on computer~
Thanks man. At last someone who understands the meaning of my thread.
Everyone understands the meaning of your thread... You just dont understand our points.
All I need is an example, but you're giving me how to do it.
[code]
local flashlight = CreateClientConVar("flashlight",1,true,false)
local flash_bright = CreateClientConVar("flashlight_brightness",5,true,false)
local flash_size = CreateClientConVar("flashlight_size",512,true,false)
local function FlashLight()
if (flashlight:GetBool() ~= true) then return end
local brightness = flash_bright:GetFloat()
local size = flash_size:GetFloat()
local tr = LocalPlayer():GetEyeTraceNoCursor()
if (LocalPlayer():Alive()) then
local light = DynamicLight(LocalPlayer():EntIndex())
if (light) then
light.Pos = tr.HitPos + tr.HitNormal * 50
light.r = 255
light.g = 255
light.b = 255
light.Brightness = brightness
light.Dcay = size * 5
light.Size = size
light.DieTime = CurTime() + 1
end
end
end
hook.Add("Think","FlashLight",FlashLight)
[/code]
May I add you to steam vokxim? :)
[QUOTE=vokxim;16051758]All I need is an example, but you're giving me how to do it.[/QUOTE]
No, you're saying
"How do I do blahblahblehblehcornwafflers"
and they're saying
"You just mix waffle iron with pastry toast"
and you're saying
"No, no I want you to GIVE me a blahblahblehblehcornwafflers"
All you're saying is, "Hey there I want you to give me the code to do something" which belongs in the requests section.
Did you understand MY point?
[QUOTE=DireAvenger;16052914]No, you're saying
"How do I do blahblahblehblehcornwafflers"
and they're saying
"You just mix waffle iron with pastry toast"
and you're saying
"No, no I want you to GIVE me a blahblahblehblehcornwafflers"
All you're saying is, "Hey there I want you to give me the code to do something" which belongs in the requests section.
Did you understand MY point?[/QUOTE]
yum waffles
I made something like this long ago, so I don't really know if this still works... (or if it ever worked :P)
[lua]
if not CLIENT then return end
-- Adjustable settings
local MAX_DIST = 600
local FOV = 50
local BRIGHTNESS = 1
-- Sounds
local sndFlashlightOn = Sound( "Player.FlashlightOn" )
local sndFlashlightOff = Sound( "Player.FlashlightOff" )
-- State
local cvShouldDrawFlashligh = CreateClientConVar( "r_flashlight_cheap", "0", false, false )
local DoFlashlight = false
-- Dynamic Light
local DynaLight = DynamicLight( LocalPlayer():EntIndex() )
DynaLight.Decay = 0
DynaLight.r = 255
DynaLight.g = 255
DynaLight.b = 255
DynaLight.Size = MAX_DIST
DynaLight.Brightness = BRIGHTNESS
DynaLight.MinLight = 0.08 * BRIGHTNESS
DynaLight.InnerAngle = 0.9 * FOV
DynaLight.OuterAngle = 1.1 * FOV
DynaLight.DieTime = CurTime() + 5 * 365.25 * 24 * 60 * 60 -- The flashlight only comes with a five-year warranty
-- Calculations
local SizeMul = math.tan( math.Deg2Rad( FOV ) )
local ScaleMul = 255 / MAX_DIST
local function DrawFlashlight()
DynaLight.Pos = LocalPlayer():EyePos()
DynaLight.Dir = LocalPlayer():EyeAngles():Forward()
--[[local tr = LocalPlayer():GetEyeTrace()
local pos = tr.HitPos - tr.Normal * 10
local dist = tr.StartPos:Distance( pos )
local scale = ( MAX_DIST - dist ) * ScaleMul
if scale < 0 then
DynaLight.Size = 0
return
end
DynaLight.r = scale
DynaLight.g = scale
DynaLight.b = scale
DynaLight.Pos = pos
DynaLight.Dir = tr.Normal
DynaLight.Size = SizeMul * dist]]
--DynaLight.Style = 0
--DynaLight.Key = 1
end
local function CC_ToggleFlashlight( plr, cmd, args )
if DoFlashlight then
hook.Remove( "RenderScene", "DrawFlashlight" )
plr:EmitSound( sndFlashlightOff )
DynaLight.Size = 0
DoFlashlight = false
else
hook.Add( "RenderScene", "DrawFlashlight", DrawFlashlight )
plr:EmitSound( sndFlashlightOn )
DynaLight.Size = MAX_DIST
DoFlashlight = true
end
end
concommand.Add( "ToggleFlashlight", CC_ToggleFlashlight )
local function OverrideFlashlight( plr, bind, bpressed )
if not cvShouldDrawFlashligh:GetBool() then return end
if string.find( bind, "impulse 100" ) then
RunConsoleCommand( "ToggleFlashlight" )
return true
end
end
hook.Add( "PlayerBindPressed", "OverrideFlashlight", OverrideFlashlight )
[/lua]
This is exactly the same as The-Stone's, except different.
[QUOTE=The-Stone;16052565]
May I add you to steam vokxim? :)
[/QUOTE]
Why not? My steam is worshiper (with 1 P), vokxim is my friend.
[QUOTE=Mr_Roberto]
I made something like this long ago, so I don't really know if this still works... (or if it ever worked :P)
[/QUOTE]
Thanks man, your code is really appreciated, but I want a clientside flashlight like that:
[URL=http://img259.imageshack.us/i/flashlight.jpg/][IMG]http://img259.imageshack.us/img259/1153/flashlight.th.jpg[/IMG][/URL]
Is it possible? If no, I'll use a normal light, but it's more lagging than a flashlight...
Sorry but I don't think that's possbile since that flashlight you want is an entity and as far as I know you can't spawn entities client sided.
[QUOTE=SFArial;16058299]Sorry but I don't think that's possbile since that flashlight you want is an entity and as far as I know you can't spawn entities client sided.[/QUOTE]
You can
The common source flash light uses a projected texture. The class name for this is "env_projectedtexture". Not sure if you can make it purely clientside, but check out the lamp entity in sandbox for how to set it up.
[QUOTE=_Muffin;16060138]You can[/QUOTE]
Well, that's new, I thought it gives an error.
[QUOTE=SFArial;16060459]Well, that's new, I thought it gives an error.[/QUOTE]
Depends on the entity you want to spawn.
[QUOTE=Gmod4ever;16061238]Depends on the entity you want to spawn.[/QUOTE]
env_projectedtexture
It doesn't work for me.
Maybee I just don't know how to spawn it correctly... so if someone wants to try it and test it if it works for him... please!
Sorry, you need to Log In to post a reply to this thread.