Hi, Garry's Mod Developers,
My name is Jamie, and I developed an Ion Gun for Garry's Mod 14.
I'm having one issue. I need to add an effect, so that when the gun is fired, a blue beam of light, or in this case, 'Ion', is produced.
Do I stand correct, believing that I should use the below code in my primary attack function, to do so -
[CODE]self:ShootEffects(LaserTracer)[/CODE]
If not, please specify an alternative code to use in my primary attack function.
Thanks in advance,
Jamie
Not quite; but close. ShootEffects is a helper-function / convenience function.
It's there to help you organize your code.
To do an effect, inside the ShootEffects function:
The reason the timer.Simple is there, is because there have been issues with effects not being set properly on the muzzle, or other locations when being fired. The IsFirstTimePredicted is to ensure it only gets executed once because the way SWEPs work, is the CLIENT spams the function call, and the server doesn't. It's supposed to have something to do with prediction, I'll be removing that "feature" in my AWEP system..
[lua] local effectdata = EffectData( );
effectdata:SetOrigin( self.Owner:GetShootPos( ) );
effectdata:SetEntity( self );
effectdata:SetStart( self.Owner:GetShootPos( ) );
effectdata:SetNormal( self.Owner:GetAimVector( ) );
effectdata:SetAttachment( 1 );
timer.Simple( 0, function( )
if ( !self.Owner ) then return end
if ( !IsFirstTimePredicted( ) ) then return; end
util.Effect( "gunsmoke", effectdata );
end );[/lua]
Thank you for replying,
So, I must change the below to match my chosen effect?
[CODE]util.Effect( "gunsmoke", effectdata );[/CODE]
Which being, LaserTracer. Thus, resulting in a code of:
[CODE]util.Effect( "LaserTracer", effectdata );[/CODE]
Am I correct? Please could you also use easier terms to this matter, as I myself, am quite new to the LUA language, and wasn't taught as well as I could of been.
Best,
Jamie
[editline]21st April 2014[/editline]
Please tell me which example to use:
First example:
[CODE]timer.Simple( 0, function( )
if ( !self.Owner ) then return end
if ( !IsFirstTimePredicted( ) ) then return; end
util.Effect( "LaserTracer", effectdata );
end )[/CODE]
Second example:
[CODE]self:ShootEffects(timer.Simple( 0, function( )
if ( !self.Owner ) then return end
if ( !IsFirstTimePredicted( ) ) then return; end
util.Effect( "LaserTracer", effectdata );
end );)[/CODE]
I didn't quite understand what you first stated, being in the code, or as a separate code itself.
Best,
Jamie
The first one, but you need the stuff defined as effectdata which is in my post.
I'm guessing you mean this one, but modified to be my effect:
[CODE]local effectdata = EffectData( );
effectdata:SetOrigin( self.Owner:GetShootPos( ) );
effectdata:SetEntity( self );
effectdata:SetStart( self.Owner:GetShootPos( ) );
effectdata:SetNormal( self.Owner:GetAimVector( ) );
effectdata:SetAttachment( 1 );
timer.Simple( 0, function( )
if ( !self.Owner ) then return end
if ( !IsFirstTimePredicted( ) ) then return; end
util.Effect( "LaserTracer", effectdata );
end );[/CODE]
Now, I have one more issue - how would I change the colour of the effect, because as default, it is blue, and I may like it to be modified, green for one gun, and yellow for another, for e.g.
Best,
Jamie
It depends on how it's coded; SetColor on the effect-data may not work so I've seen workarounds where an alternative function is used.
Is it a Lua defined effect, or engine-defined? If it's Lua defined, you can take a look at the script where it sets the render color; if it pulls from a data-source which gets set in Init then you would just need to call that function to set the data; if it's hard-coded you'll need to add that functionality. Some materials can be stubborn in terms of taking on a new color because it's sort of "mixed". Full white = the normal color for the material. Example: if you use icon16/heart.png, it's red. If you set the surface color to white before rendering it, it'll be red. If you set it to green it may be a different color.
I'm unsure? I presumed you just picked a name from here, and that was that: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexe14a.html[/url]
Is there a specific file that I must download? If so, where do I place the file?
[editline]21st April 2014[/editline]
[IMG]http://i.imgur.com/Xu3pKcp.png[/IMG]
[editline]21st April 2014[/editline]
I found these around on Google -
Blue Eletric Laser Beam - cable/blue_elec
Red Laser Beam - cable/redlaser
Hydra - cable/hydra
XBeam - cable/xbeam
Would I use these as set out below:
[CODE] local effectdata = EffectData( );
effectdata:SetOrigin( self.Owner:GetShootPos( ) );
effectdata:SetEntity( self );
effectdata:SetStart( self.Owner:GetShootPos( ) );
effectdata:SetNormal( self.Owner:GetAimVector( ) );
effectdata:SetAttachment( 1 );
timer.Simple( 0, function( )
if ( !self.Owner ) then return end
if ( !IsFirstTimePredicted( ) ) then return; end
util.Effect( "cable/hydra", effectdata );
end );[/CODE]
Or, would I need to use the name of the cable, and not the path?
[editline]21st April 2014[/editline]
See:
Screenshot:
[IMG]http://i.imgur.com/LqVr47V.png[/IMG]
The code:
[CODE] local effectdata = EffectData( );
effectdata:SetOrigin( self.Owner:GetShootPos( ) );
effectdata:SetEntity( self );
effectdata:SetStart( self.Owner:GetShootPos( ) );
effectdata:SetNormal( self.Owner:GetAimVector( ) );
effectdata:SetAttachment( 1 );
timer.Simple( 0, function( )
if ( !self.Owner ) then return end
if ( !IsFirstTimePredicted( ) ) then return; end
util.Effect( "blue_elec", effectdata );
end );[/CODE]
I believe I understand it, now! Although, correct me if I'm wrong.
not quite. There are some engine effects that can be used like ToolTracer, etc; then there are some defined by Lua located in the entities/effects/ folder of your game-mode and the base / derived-from-gamemode which is usually base/ or sandbox/
The names you found are for materials, they can be used to create effects but they aren't the effect themselves, simply a texture used to help visualize the effect and usually what's used for creating effects.
Oh, why did you create a new thread on the same topic?
Could you tell me the possible effect names I could put into the script? I'm clueless.
[editline]21st April 2014[/editline]
Hi again, I found a particle effects list ([url]https://www.assembla.com/code/Gmod_update/subversion/nodes/16/data/particle%20materials.txt[/url]) in which I presume lists off the effects I could use in the code - [CODE]util.Effect( "effects/bluelaser1", effectdata );[/CODE]
All I need now is a function that ignites everything the gun fires at on collide.
[editline]21st April 2014[/editline]
[CODE] local LASER = Material('cable/blue_elec')
function SWEP:Initialize()
local ply = LocalPlayer()
util.PrecacheSound("fire.wav")
util.PrecacheSound("reload.wav")
self:SetWeaponHoldType( self.HoldType )
self.VM = ply:GetViewModel()
local attachmentIndex = self.VM:LookupAttachment("muzzle")
if attachmentIndex == 0 then attachmentIndex = self.VM:LookupAttachment("1") end
self.Attach = attachmentIndex
end
function SWEP:ViewModelDrawn()
render.SetMaterial( LASER )
render.DrawBeam(self.VM:GetAttachment(self.Attach).Pos, self.Owner:GetEyeTrace().HitPos, 2, 0, 12.5, Color(0, 221, 255, 255))
end[/CODE]
Sorry, you need to Log In to post a reply to this thread.