Where do I place my Lua Script..

Okay, I have made a Lua Script, but I do not know where to put it. If I put it into the garrysmod/garrysmod/lua/autorun folder, some of the functions mess up, such as ParticleEmitter and vgui.Create.

This is all that is in my script:

Making a Table of Strings
Build a Derma Menu when someone runs the command: “open_dmenu” which is added by:
concommand.Add(“open_dmenu”, Makedermamenu)
Hook the player’s chat, so the commands are chat activated. If I use lua_openscript_cl test.lua
it works perfectly fine, but I’m rather new to Lua, so I don’t know the placement of the Lua files, and how to actually make them ‘work’. I only know how to develop Ass_Mod plugins, which are self-called. Can you please help? Thanks.

Why do you have ParticleEmitter in an autorun script? Do you mind posting the code?

[lua]
function Spit(ent)
local pos = ent:EyePos()
local heading = ent:GetAimVector()
local emitter = ParticleEmitter(pos)
emitter:SetNearClip(16, 20)

local particle = emitter:Add("particle/rain", pos)
particle:SetDieTime(3)
particle:SetStartAlpha(255)
particle:SetEndAlpha(100)
particle:SetStartSize(4)
particle:SetEndSize(0)
particle:SetRoll(math.Rand(0, 360))
particle:SetRollDelta(math.Rand(-20, 20))
particle:SetCollide(true)
particle:SetGravity(Vector(0, 0, -600))
particle:SetVelocity(heading * 350)
particle:SetAirResistance(10)

for i=1, 14 do
	local particle = emitter:Add("particle/rain", pos)
	particle:SetDieTime(math.Rand(1, 2))
	particle:SetStartAlpha(255)
	particle:SetEndAlpha(100)
	particle:SetStartSize(1)
	particle:SetEndSize(0)
	particle:SetRoll(math.Rand(0, 360))
	particle:SetRollDelta(math.Rand(-20, 20))
	particle:SetCollide(true)
	particle:SetGravity(Vector(0, 0, -600))
	particle:SetVelocity(heading * 300 + VectorRand():Normalize() * 64)
	particle:SetAirResistance(20)
end

emitter:Finish()

end
[/lua]

You need to make an individual file for the effect. (example: lua/effects/spit/init.lua)

Example…



function EFFECT:Init( data )

	local vOffset = data:GetOrigin()

	local emitter = ParticleEmitter( data:GetOrigin() );
		for i = 40, 50 do

			local smoke = emitter:Add( "particle/particle_smokegrenade", vOffset );

			if (smoke) then

				smoke:SetVelocity(VectorRand() * 600);
				
				smoke:SetLifeTime(0);
				smoke:SetDieTime(math.Rand(5, 10));
				
				smoke:SetColor(120, 120, 120);
				smoke:SetStartAlpha(math.Rand(240, 255));
				smoke:SetEndAlpha(0);
				
				smoke:SetStartSize(math.Rand(30, 45));
				smoke:SetEndSize(math.Rand(175, 225));
				
				smoke:SetRoll(math.Rand(-180, 180));
				smoke:SetRollDelta(math.Rand(-0.1, 0.1));
				
				smoke:SetAirResistance(math.Rand(400, 600));
				smoke:SetGravity( Vector( 0, 0, math.Rand(0, 10) ) );

				smoke:SetCollide( true );

				smoke:SetLighting(1);
			end
		end
		
	emitter:Finish()
end

function EFFECT:Think( )
	return false
end

function EFFECT:Render()
end


Then to emit the effect you need to do something like this…



function Spit(ent)
local effectdata = EffectData()
effectdata:SetOrigin(ent:GetPos())
util.Effect(nameoftheeffectfiledirectory,effectdata)
end


As you can see in the first codebox, local variable vOffset is data:GetOrigin(). This is what you just defined in the above code. It is the position of the entity.

Okay, but this does not help me place the Lua file… Would I have to use something like: CSAddLuaFile(“test.lua”)?
or would I have to use include(‘test.lua’)?
If so, how exactly would I have to do that?

Nope.

Just fix the effect thing (make an individual serverside file for it and place it in lua/effects/spit) and place the other file in your autorun directory.

No, this does not fix it, as then vgui.Create still does not work. I’ve never gotten any derma menu to work with the autorun directory.

make an delay on it, like timer.Simple(2, function() ******* end)
as the derma module might run later then this script it wil error out.

edit:

why the fuck am i dumb?

Post the code with vgui.Create in it.

I tried the timer function, and it didn’t work. Do you know how to use the:
[lua]if SERVER then
AddCSLuaFile(“test.lua”)//I don’t know what goes here, is it supposed to be the name of the lua script that’s being run?
return
end
[/lua]

If you do know how to use it, could you explain?

also, I didn’t mark you as dumb.

You’re all unhelpful.
The answer is:
If your code is entirely clientside, then it goes in autorun/client.
If your code is entirely serverside then it goes in autorun/server.
If your code is mixed, then it goes in autorun, with if statements differentiating which it should be run on.
[lua]if SERVER then
– Server Code
else
– Client code
end[/lua]

sorry for trying to help you fucking dick

Hold your horses, dude. He only said that you didn’t give him the help he needed.

You don’t need to Spazz out.