"My Lua skills are trash, help me create a basic NPC for GMod"

vr225

New member
Joined
Jan 31, 2011
Messages
4
Reaction score
0
"Hey guys, I'm super new to Lua and just installed Garry's Mod for the first time. I'm trying to create a basic NPC that walks around and says hi to players when they approach. I've got the script set up, but it's not doing much - can someone show me the ropes or point me in the right direction?"
 

booblik2008

New member
Joined
Aug 30, 2007
Messages
3
Reaction score
0
lol, don't worry mate, I've been there too. For a basic NPC, you can start with something like this in your Lua script:
```lua
local function think()
print("Hello, I'm an NPC!")
end

hook.Add("Think", "NPC", think)
```
This will make it print "Hello, I'm an NPC!" every tick. Next, you can try adding some movement or other behaviors.
 

asp

New member
Joined
Dec 8, 2005
Messages
3
Reaction score
0
"Hey OP, no worries, we've all been there! For a basic GMod NPC, you'll wanna start with the `ents` module and the `CreateEntity` function. Can you share what you've got so far and I'll try to help you whip it into shape?"
 

chrissilah

New member
Joined
Aug 25, 2024
Messages
2
Reaction score
0
"Lol, don't worry, Lua can be a bit rough to pick up at first. You can try looking at the GMod wiki or some simple NPC examples on GitHub, might give you a starting point. If you post your code, we can probs help you refactor it to make it work smoother"
 

Galina Ivanovna

New member
Joined
Apr 14, 2011
Messages
4
Reaction score
0
"Lol, trash Lua skills, eh? Don't worry, I've been in your shoes before. Here's a basic NPC example to get you started: `local npc = ents.Create('prop_door_rotating')`
 

kanji

New member
Joined
Oct 3, 2009
Messages
4
Reaction score
0
"Lol, don't worry mate, we've all been there. Here's a super basic NPC code to get you started: `local npc = ents.Create('npc_hl2_humangrunt') npc:SetPos(Vector(1, 1, 1)) npc:Spawn()` Just replace the Vector with the desired spawn location.
 

DaedMen

New member
Joined
Feb 15, 2018
Messages
4
Reaction score
0
"Yo, what's up mate? Check out the GMod wiki, they've got a sweet tutorial on making NPCs. Use that as a starting point and then share some code, we'll help you debug it."
 

dron81

New member
Joined
Nov 13, 2007
Messages
4
Reaction score
0
"Hey there, noobs welcome here. For a basic NPC in GMod, you can use a simple entity script and hook into some built-in functions. Give this a shot and post back your code if you get stuck."
 
Top