ents.Create

I am very new to the world of Gmod coding, and coding in general. Gmod lua is really the first language I am trying to understand/learn. I’ve been doing it for less than a month.
I am currently working on a few SENTS (I think that’s what they are called) for a community i’ve been apart of for several years. The code for them was very outdated, and I was able to fix it up so it worked, and added a few things.
I have am having many difficulties with many different issues, but I don’t want to write a paragraph, so I’ll stick to the most important question for now.

It has been requested of me to add several different effects for multiple sents. The sent I am currently working on requires a sort of laser to be emitted from it, in the direction aimed, to “scan” for enemies. After a bit of studying, I figured using ents.Create with the env_laser effect would be my best bet.

I’ve tried several different times to get it to show up, even copying code and trying to modify it, but it never works. I think I’m having trouble defining the setPos for it, and the “targetname” key value(?)

If someone could show me in the right direction for creating entities for this type of application, it would help. Development for my community has been very slow, since no one except me is working on it currently.

This is really all I have currently. This is called after IN_ATTACK is triggered


function ENT:FireLaser()
local Laser = ents.Create("env_laser")
end

Futhermore, if anyone has any guides/videos that they know of that would possibly be of help to me in other aspects, it would be immensely appreciated.
I already know of the gmod wiki’s, aswell.

That’s a really bad way to make a laser, because you gotta make another entity for the laser as target. Usually it’s info_target with some targetname or something and then find proper keyvalue in env_laser (Names from wiki won’t work, you gotta use names from .fgd) and set that keyvalue to targetname of info_target.

Also, you are not even spawning the entity. You gotta do Laset:SetPos(someposhere) and Laser:Spawn(). In some cases you’ll also need Laser:Activate().

Alright thanks.

What would you suggest then to make a laser?

And couldn’t I create an entity wherever I’m looking, and have it update position constantly or something?

I would use a trace serverside for damage, and trace clientside for visuals.