I'm using this to for slowness in my swep.
[CODE]function EFFECT:Init( data )
self.Position = data:GetOrigin()
local emitter = ParticleEmitter( self.Position )
local emittersed = ParticleEmitter( self.Position )
local RanParticle = math.random( 1, 3)
for i=1, 10 do
if RanParticle == 1 then
local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )
particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
particle:SetDieTime(math.Rand( 2, 3 ))
particle:SetStartAlpha(230)
particle:SetEndAlpha(0)
particle:SetStartSize(math.random(1, 5))
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( 0,10 ) )
particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
particle:VelocityDecay( false )
end
[/CODE]
But I get this error in Gmod:
[lua\weapons\sample\shared.lua:90] 'end' expected (to close 'for' at line 73) near '<eof>'
What does it mean and what should I do about it?
[CODE]function EFFECT:Init( data )
self.Position = data:GetOrigin()
local emitter = ParticleEmitter( self.Position )
local emittersed = ParticleEmitter( self.Position )
local RanParticle = math.random( 1, 3)
for i=1, 10 do
if RanParticle == 1 then
local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )
particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
particle:SetDieTime(math.Rand( 2, 3 ))
particle:SetStartAlpha(230)
particle:SetEndAlpha(0)
particle:SetStartSize(math.random(1, 5))
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( 0,10 ) )
particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
particle:VelocityDecay( false )
end
end
end
[/CODE]
That should solve it.
[QUOTE][lua\weapons\sample\shared.lua:90] 'end' expected (to close 'for' at line 73) near '<eof>'[/QUOTE]
Means that you didn't close the for loop.
[QUOTE=goldenlukis;36482002][CODE]function EFFECT:Init( data )
self.Position = data:GetOrigin()
local emitter = ParticleEmitter( self.Position )
local emittersed = ParticleEmitter( self.Position )
local RanParticle = math.random( 1, 3)
for i=1, 10 do
if RanParticle == 1 then
local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )
particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
particle:SetDieTime(math.Rand( 2, 3 ))
particle:SetStartAlpha(230)
particle:SetEndAlpha(0)
particle:SetStartSize(math.random(1, 5))
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( 0,10 ) )
particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
particle:VelocityDecay( false )
end
end
end
[/CODE]
That should solve it.
Means that you didn't close the for loop.[/QUOTE]
Thanks a ton, I'm pretty new at this. Sorry to have so many questions, but now it says:
[lua\weapons\sample\shared.lua:64] attempt to index global 'EFFECT' (a nil value)
Haha, np, everyone has to start somewhere :)
Ummm, then I think you'll need to create a new effect, since it's a swep, not an effect x) (e.g. create a init.lua in lua\effects\<name-of-effect>\ and do some coding).
I'm not good when it comes to particles/effects, however you could check out the [URL="http://wiki.garrysmod.com/"]Garry's Mod wiki[/URL] and the backup on the old one on [URL]http://maurits.tv/data/garrysmod/[/URL]. Or maybe [URL="http://glua.me/search/"]luasearch[/URL].
Though, atm the maurits one is offline and cloudflare doesn't seem to help much, and I'm not on my desktop comp atm, if I was, I would be able to help more since I have all my lua-related things on there.
Create an EFFECT table at the top [code]local EFFECT = {}[/code]
Then register the effect and use it somewhere. [code]effects.Register(EFFECT,"name_of_effect")[/code]
[QUOTE=skullorz;36483065]Create an EFFECT table at the top [code]local EFFECT = {}[/code]
Then register the effect and use it somewhere. [code]effects.Register(EFFECT,"name_of_effect")[/code][/QUOTE]
Like this?
[CODE]function EFFECT:Init( data )
local EFFECT: = {}
self.Position = data:GetOrigin()
effects.Register(EFFECT,"slow")
local emitter = ParticleEmitter( self.Position )
local emittersed = ParticleEmitter( self.Position )
local RanParticle = math.random( 1, 3)
for i=1, 10 do
if RanParticle == 1 then
local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )
particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
particle:SetDieTime(math.Rand( 2, 3 ))
particle:SetStartAlpha(230)
particle:SetEndAlpha(0)
particle:SetStartSize(math.random(1, 5))
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( 0,10 ) )
particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
particle:VelocityDecay( false )
end
end
end[/CODE]
No, he meant like this.
[lua]
local EFFECT = {}
function EFFECT:Init( data )
self.Position = data:GetOrigin()
local emitter = ParticleEmitter( self.Position )
local emittersed = ParticleEmitter( self.Position )
local RanParticle = math.random( 1, 3)
for i=1, 10 do
if RanParticle == 1 then
local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )
particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
particle:SetDieTime(math.Rand( 2, 3 ))
particle:SetStartAlpha(230)
particle:SetEndAlpha(0)
particle:SetStartSize(math.random(1, 5))
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( 0,10 ) )
particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
particle:VelocityDecay( false )
end
end
end
effects.Register(EFFECT,"slow")[/lua]
Now I get this error :/
[lua\weapons\sample\shared.lua:94] attempt to index global 'effects' (a nil value)
Sorry if these are noobish questions, I'm not good at this.
[QUOTE=Marche100;36482186]Thanks a ton, I'm pretty new at this. Sorry to have so many questions, but now it says:
[lua\weapons\sample\shared.lua:64] attempt to index global 'EFFECT' (a nil value)[/QUOTE]
You can't reload a swep's files with lua_openscript or lua_openscript_cl if you are trying to reload the swep just restart the map.
Sorry, you need to Log In to post a reply to this thread.