Pardon the possible frustration I might create by asking this, but dynamic lights have been absolutely confusing for me. I can get them to work in a Think hook, but what I'm looking to do is light up a room when I shoot a bullet.
So far, I have this code which works perfectly fine in a think hook, outside of just being an endless light.
[code] if CLIENT then
local dlight = DynamicLight( self:EntIndex() )
if ( dlight ) then
local r, g, b, a = 255, 200, 50
dlight.Pos = self:GetPos( ) + self.Owner:GetForward() * 16
dlight.r = r
dlight.g = g
dlight.b = b
dlight.Brightness = 4
dlight.Size = 512
dlight.Decay = 0
dlight.DieTime = CurTime( ) + 1
dlight.Style = 0
end
end[/code]
How do I get a light that fires once after calling PrimaryAttack( )? I've looked all over the internet for this and I couldn't find any help.
Just a thought / theory / possible idea, but what about doing a quick flash with a flashlight entity using a large fov?
I think you're using DieTime and Decay incorrectly.
I got sort of a muzzleflash light effect by using a brightness of 1, size of 256, decay of 1500, and die time of 300.
PrimaryAttack is ran shared so you can just stick the dlight stuff in there.
Personally I would create an effect specifically for it, so when I use util.Effect it's networked to the other players and they see the flash as well. (Unless of course there's a better alternative client side for when a player attacks)
[QUOTE=Daemon White;42669816]Just a thought / theory / possible idea, but what about doing a quick flash with a flashlight entity using a large fov?[/QUOTE]
Not to be mean or anything, but I think that's more of a workaround than a solution. I'll keep it in mind for a worst case scenario, though!
[QUOTE=Walrus Viking;42670714]I think you're using DieTime and Decay incorrectly.
I got sort of a muzzleflash light effect by using a brightness of 1, size of 256, decay of 1500, and die time of 300.[/QUOTE]
So, DieTime doesn't need to utilize CurTime( ) at all? I guess I've been a bit confused with the example on the old wiki:
[code]function ENT:Think()
local dlight = DynamicLight( self:EntIndex() )
if ( dlight ) then
local r, g, b, a = self:GetColor()
dlight.Pos = self:GetPos()
dlight.r = r
dlight.g = g
dlight.b = b
dlight.Brightness = 1
dlight.Size = 256
dlight.Decay = dlight.Size * 5
dlight.DieTime = CurTime() + 1
dlight.Style = 0
end
end[/code]
Decay would be 1280, and DieTime would be one second from "now". What is decay anyway?
I'll have to try it when I get home from college.
[QUOTE=Chessnut;42670883]PrimaryAttack is ran shared so you can just stick the dlight stuff in there.[/QUOTE]
Yup, I'm running it in there. Nothing happening, though.
[QUOTE=Walrus Viking;42673785]Personally I would create an effect specifically for it, so when I use util.Effect it's networked to the other players and they see the flash as well. (Unless of course there's a better alternative client side for when a player attacks)[/QUOTE]
Not to be a bother, but searching for "creating an effect" and "util.Effect" didn't bring up anything about actually creating effects. I had no idea you could do that. What specifically should I look into for doing this?
The wiki is an invaluable resource:
[url]http://wiki.garrysmod.com/[/url]
[url]http://wiki.garrysmod.com/page/util/Effect[/url]
You should sharpen your detective skills.
Here's how I do it in my SWEPs.
[lua] local dlight = DynamicLight(self:EntIndex())
dlight.r = 255
dlight.g = 218
dlight.b = 74
dlight.Brightness = 4
dlight.Pos = muz.Pos + self.Owner:GetAimVector() * 3
dlight.Size = 96
dlight.Decay = 128
dlight.DieTime = CurTime() + FrameTime() * 2[/lua]
muz.Pos is the muzzleflash attachment's position.
Decay is basically Size but weaker, and it also takes a bit more time to dissapear than Size.
If I recall correctly, my dynamic lights wouldn't work until I got rid of the 'if (dlight) then' part.
I'm just going off of trial and error since I couldn't find any documentation on DynamicLight which is why I said I [i]think[/i] he's using them wrong.
[url]http://wiki.garrysmod.com/page/Classes/dlight_t[/url]
Here's what Decay is.
[QUOTE=Walrus Viking;42674296]The wiki is an invaluable resource:
[url]http://wiki.garrysmod.com/[/url]
[url]http://wiki.garrysmod.com/page/util/Effect[/url]
You should sharpen your detective skills.[/QUOTE]
I've already been to those pages, and I've also used util.Effect in the past. You made it seem as though you were able to create an effect to use with util.Effect.
[QUOTE=wauterboi;42679486]You made it seem as though you were able to create an effect to use with util.Effect.[/QUOTE]
You can. I'm sure there used to be a lua/effects/ folder you could look in but I can't find it in the gmod source now. Here's a random one I just found by googling 'gmod effects lua'
[url]https://www.assembla.com/code/elvenstarnet/subversion/nodes/10/Gmod/addons/Ion%20Systems/lua/effects/warpcore_breach/init.lua[/url]
[QUOTE=wh1t3rabbit;42680953]You can. I'm sure there used to be a lua/effects/ folder you could look in but I can't find it in the gmod source now. Here's a random one I just found by googling 'gmod effects lua'
[url]https://www.assembla.com/code/elvenstarnet/subversion/nodes/10/Gmod/addons/Ion%20Systems/lua/effects/warpcore_breach/init.lua[/url][/QUOTE]
It still exists, it's just never created by default. You can find some effects in base and sandbox gamemodes.
[QUOTE=wauterboi;42679486]I've already been to those pages, and I've also used util.Effect in the past. You made it seem as though you were able to create an effect to use with util.Effect.[/QUOTE]
You can create effect entities and use them with that. It's very handy as a shortcut method to make your own effects for weapons and such. TTT has a couple that are handy and easy to understand.
Making an entity to create an effect seems inefficient and unnecessary to me.
Effects are basically clientside scripted entities, instead of going into lua/entities, they go into lua/effects. So if you have an effect named "foo", you would need a Lua file located at "lua/effects/foo/init.lua". Since you usually don't need more than a single file per effect, you can also get rid of the folder and do "lua/effects/foo.lua" instead.
Unlike regular entities, effects have only three hooks, Init, Think and Render, which are more or less equivalent to the Initialize, Think and Draw hooks from SENTs: [url]http://wiki.garrysmod.com/page/Category:EFFECT_Hooks[/url]
They are spawned using util.Effect, which can be used either on the server or on the client (which is neat since you can easily spawn them from the server). However, since util.Effect doesn't return anything, you need to set the position and parameters of your effect before calling util.Effect, which is why you need an EffectData object.
This EffectData is then simply passed to the Init hook of your effect (which takes one argument, commonly named "data"), where you can read its values to initialize the effect.
Now keep in mind that the values in EffectData have absolutely no meaning until you give them one. If you use SetMagnitude to set a value, you'll read the same value in your effect's Init hook using data:GetMagnitude. Same goes for any other Get/Set pair from EffectData objects. You can see all of them here: [url]http://wiki.garrysmod.com/page/Category:CEffectData[/url]
If I remember correctly, the only exception to this is SetOrigin, which will automatically set the position of the effect.
Also you can't just put any type of value, SetStart and SetNormal take vectors, SetMagnitude and SetScale take floating point values, SetAttachment and SetHitBox take integer values and so on.
The Think hook acts as expected, although it has one extra feature: if you return false in it, it will delete the effect. That's usually how effects are removed, so keep that in mind.
As I said above, effects are pretty much clientside scripted entities, so you can give them a model and even physics. This is quite handy for gibs and shell ejections. But most of the time, you're going to use them as particle spawners, which will create particle effects and then immediately die.
In your case, you would probably need to pass the weapon and muzzle attachment (using SetEntity and SetAttachment), and initialize the dynamic light in Init. Make sure to use the weapon's entity index as the light's unique ID, as effects don't have an entity index (if I remember correctly, EntIndex returns -1). Leave the Render hook empty and make Think return false, this will cause the effect to be removed right after being initialized. (this won't remove the dynamic light since it's a completely independent object)
Wow, thanks man. I'm definitely gonna start using that more often!
I'll let you know how things turn out when I get a chance to work on things - I've been stuck sleeping or at college.
Alright, so I've come back and I decided to refer to the Wiki page posted, and I'm going to warn all of you right now that the code on that page is faulty and is in no way the proper way to do an effect. I was confused up until Kilburn talked to me about in on Steam and said they sucked.
Thanks everyone for your help. I've got everything working!
Sorry, you need to Log In to post a reply to this thread.