Garry's Mod

Making NPC

I'll teach you how to create your very own custom NPC for Gmod2007. It's not very hard, quite simple, actually.

So I'll start out with a default citizen NPC:

Citizen NPC

local Category = "Your NPC Category"

local NPC = { Name = "Your NPC",

            Class = "npc_citizen",      
            Model = "models/yourmodelname.mdl",
            Health = "100",
            KeyValues = { citizentype = 4 },
            Category = Category    }

list.Set( "NPC", "npc_yourfirstNPC", NPC )

Then I'll go over what each one is:

local NPC = { Name = "Your NPC",

//This is your NPC's name, shown on the spawnmenu. Just replace 'Your NPC" with the name you want.

Class = "npc_citizen",

// This is the class of your NPC ( combine, citizen, vortigaunt, etc.)

You can't make any NPC type. You can only make NPCs with the following classes. This is because the rest of the npcs ( gman, fast zombie, others I didn't mention) do not have preset keyvalues.

npc_combine_s //Combine Soldier npc_vortigaunt //Vortigaunt ( pretty self explanatory) npc_alyx //Alyx npc_strider // Strider npc_citizen // A basic citizen who can follow you.

Model = "models/yourmodelname.mdl",

// This is the NPC's model directory. Make sure it's right or your NPC will spawn as a big whopping ERROR sign. Oh, and one very important thing:

MAKE SURE YOUR MODEL HAS THE CORRECT ANIMATIONS.

If your model does not have the correct animations they will spawn in a T shape and not move whatsoever. If you want to modify a ragdoll to have animations, you must decompile the model and edit the .qc file's animations( I will soon make a tut of this later).

Health = "100",

//This is already quite self-explanatory, no need to go over this.

KeyValues = { citizentype = 4 },

//This part of the code only applies to citizens. These are the keyvalues of the citizen to show what type of citizen it is ( If I can remember, i think it was Citizen, DownTrodden, Rebel, and medic). Experiment with those to see if I am right.

Category = Category }

//This part validates the NPC so it's in the category.

list.Set( "NPC", "npc_yourfirstNPC", NPC )

// Finally, this will set the NPC into the list and this creates the NPC's in-name game ( not the one in the spawnlist, just the "console" name. just change "Npcyourfirstnpc" to anything, but make sure npc is there at all times.

That's it! Stick it all together and you've got your first NPC done!

Combine NPC ( enemy NPC)

local NPC = { Name = "Enemy",

            Class = "npc_combine_s",
            Model = "models/enemy.mdl",
            Squadname = "squad",
            Numgrenades = "4",
            Category = Category    }

list.Set( "NPC", "npc_enemy", NPC )

I won't go over the first 2 or the ones I've gone over, but I'll go over the ones you haven't seen:

Squadname = "squad",

//The squad name. If 2 have the same, I think both NPCS will stick together at all times. You can change it to anything you like, or not have it.

Numgrenades = "4",

//The number of grenades the enemy has. Change the number to anything you like.

That should do it. Well, have fun creating NPCS!

Share

Embed HTML:
Embed BB Code:
Embed Markdown:

More embeddable images

Bookmark and Share

Oh noes! You're not a Member!

Want access to cool stuff? As a member you can:

  • Post. Give the submitter your thoughts on this Tutorial.
  • Say Thanks. Show your appreciation by sending the submitter points.
  • Stamp Posts. Let other posters know what you think of their posts.
  • Rate. Give this Tutorial a rating out of 10.
  • Flag. Alert moderators and warn members of a problem with this Tutorial.
  • Vote. Vote the submitter for the Monthly Awards.
  • Subscribe. Get notified when this submitter submits again.

Interested? Register or Login

Comments

  • shcfyd avatar
    shcfyd Offline
    4 medals 1 rare
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    Member Joined 3 years ago
    • Report icon
    2 years ago:

    Posted by LucasHenkel When I try to make a zombie npc but with a different model it always has the same thing, everything works but it doesn't use the model I inserted. Can someone help?

    As the tutorial says, you are limited to npc_combine_s, npc_citizen, vortiguant and so on. Zombie, metropolice and some others can not have their model swapped via lua. I think you will need to compile a new Zombie model in order to make a custom npc_zombie

    Bananite
  • LucasHenkel avatar
    LucasHenkel Offline
    438 points Ranked 7612th
    4 medals 1 rare
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    Member Joined 3 years ago
    • Report icon
    3 years ago:

    When I try to make a zombie npc but with a different model it always has the same thing, everything works but it doesn't use the model I inserted. Can someone help?

    LucasGodzilla
  • asteroidrules avatar
    asteroidrules Offline
    5,458 points Ranked 666th
    7 medals 2 rare
    • Reached 1,000 Points Medal
    • Reached 2,500 Points Medal
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    • 4 years a member (bonus 4 points on daily login) Medal
    Member Joined 5 years ago
    • Report icon
    4 years ago:

    The category thing doesn't change no matter what you type in. It also doesn't work with custom models.

  • asteroidrules avatar
    asteroidrules Offline
    5,458 points Ranked 666th
    7 medals 2 rare
    • Reached 1,000 Points Medal
    • Reached 2,500 Points Medal
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    • 4 years a member (bonus 4 points on daily login) Medal
    Member Joined 5 years ago
    • Report icon
    4 years ago:

    What do you save the file as and where do you put it? I'm trying to make a scanner.

  • zeppoking avatar
    zeppoking Offline
    5 medals 2 rare
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    • 4 years a member (bonus 4 points on daily login) Medal
    Member Joined 5 years ago
    • Report icon
    4 years ago:

    When I spawn my Npc they are invisible

    Bananite
  • chrisspyb avatar
    chrisspyb Offline
    5 medals 2 rare
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    • 4 years a member (bonus 4 points on daily login) Medal
    Member Joined 5 years ago
    • Report icon
    5 years ago:

    Great tutorial man!

    The cake is a lie- IS A LIE!
  • Ghost07 avatar
    Ghost07 Offline
    5 medals 2 rare
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    • 4 years a member (bonus 4 points on daily login) Medal
    Member Joined 5 years ago
    • Report icon
    5 years ago:

    ¿Can I open LUA, with wordpad?

    Bananite
  • Dot. avatar
    Dot. Offline
    115 points Ranked 19635th
    7 medals 3 rare
    • 1 post awarded Exemplary Feedback (bonus 1 point for posting) Medal
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    • 4 years a member (bonus 4 points on daily login) Medal
    • 6 years a member (bonus 6 points on daily login) Medal
    Member Joined 6 years ago
    • Report icon
    6 years ago:

    This is all great info that could be useful if you added a few more things for the average n00bs as myself:

    o Where are we putting all this? Do we create a file? If so what do we name it? Also, where are we putting this file?

    o Do we structure the file just like you have it? Are there no brackets () , {}, [] ?

    28RL.NET avatar
    User Title
    28RL.NET
  • Corhunger avatar
    Corhunger Offline
    6 medals 3 rare
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    • 4 years a member (bonus 4 points on daily login) Medal
    • 6 years a member (bonus 6 points on daily login) Medal
    Member Joined 7 years ago
    • Report icon
    6 years ago:

    Is there any kleiner npc that fights? If not can i just take his normal model and throw it on a citizen/rebel? and where do i put all that text, in lua as a txt file?

    Bananite
  • juggalo83 avatar
    juggalo83 Offline
    5,456 points Ranked 667th
    9 medals 3 rare
    • Reached 1,000 Points Medal
    • Reached 2,500 Points Medal
    • Unlocked Treehouse VIP clearance Medal
    • One month a member (bonus 1 point on daily login) Medal
    • 6 months a member  (bonus 1 point on daily login) Medal
    • 1 year a member (bonus 1 point on daily login) Medal
    • 2 years a member (bonus 2 points on daily login) Medal
    • 4 years a member (bonus 4 points on daily login) Medal
    • 6 years a member (bonus 6 points on daily login) Medal
    Member Joined 8 years ago
    • Report icon
    7 years ago:
    Posted by zaks88
    Posted by juggalo83 Good work on this but im still having trouble finding them ingame
    Make sure you put the lua file in lua/autorun and if it still doesnt work make sure u have no spaces in the name , instead of spaces use _

    no i figured it out, it was a case of the misspelling of a word that was giving me a problem but its fixed now

    donate points to the poor avatar
    User Title
    donate points to the poor

Credits

Key Authors
Pwnz0r
Unknown

Submitter

Pwnz0r avatar
Pwnz0r Offline
241 points Ranked 11940th
6 medals 3 rare
  • One month a member (bonus 1 point on daily login) Medal
  • 6 months a member  (bonus 1 point on daily login) Medal
  • 1 year a member (bonus 1 point on daily login) Medal
  • 2 years a member (bonus 2 points on daily login) Medal
  • 4 years a member (bonus 4 points on daily login) Medal
  • 6 years a member (bonus 6 points on daily login) Medal
Member Joined 7 years ago

Pwnz0r
Creator

Category

Rating

8.9/10

Details

Genre
Coding/Scripting
Difficulty Level
Intermediate

Stats

Post Count
19
ViewCount
53,679
Date Added
7 years ago
Date Modified
7 years ago