• Creating a simple NPC
    7 replies, posted
Hello, I want to create a simple NPC, that can sell items. Is there any documentation? The wiki only has a tutorial about Next Bot. The NPC shouldn't be able to walk etc, it should just stand there and when you click E on it, then a menu should open. Also, why are those npcs in the Entitys tab and not in the NPC tab? (Car Dealers etc) Thanks, Pascal
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7853.html[/url]
Thanks! This information should also be provided in the new wiki. [editline]4th December 2015[/editline] I got in some trouble with this. I tried creating my first npc shop, but the entity is showing twice in the spawn menu and the model is shown as ERROR. cl_init.lua: [CODE] include("shared.lua") local function shop() local main = vgui.Create("DFrame") main:SetSize(400, 400) main:SetPos(ScrW()/2 - main:GetWide()/2, ScrH()/2 - main:GetTall()/2) main:SetTitle("NPC Shop") main:SetDraggable(true) main:ShowCloseButton(true) main:MakePopup() end net.Receive("first_npc", shop) [/CODE] shared.lua: [CODE] ENT.Base = "base_ai" ENT.Type = "ai" ENT.SetAutomaticFrameAdvance = true ENT.PrintName = "Wood Seller" ENT.Author = "P4sca1" ENT.Category = "P4sca1 NPCs" ENT.Instructions = "" ENT.Spawnable = true ENT.AdminSpawnable = true [/CODE] init.lua: [CODE] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include("shared.lua") util.AddNetworkString("first_npc") function ENT:Initialize() self:SetModel("models/player/Group02/male_08.mdl") self:SetHullType(HULL_HUMAN) self:SetHullSizeNormal() self:SetNPCState(NPC_STATE_SCRIPT) self:SetSolid(SOLID_BBOX) self:CapabilitiesAdd(CAP_ANIMATEDFACE) self:SetUseType(SIMPLE_USE) self:DropToFloor() self:SetMaxYawSpeed(90) end function ENT:AcceptInput(inputName, activator, caller, data) if inputName == "Use" and caller:IsPlayer() then net.Start("first_npc") net.Send(caller) end end [/CODE]
AcceptInput most likely runs constantly while used
[QUOTE=NiandraLades;49246794]AcceptInput most likely runs constantly while used[/QUOTE] I commented out this function. Has nothiung to do with it. The entity still shows twice and is an error.
What happens when you try to spawn it? As for it showing in the wrong tab, it's just using a different function to add itself to the spawn menu
[QUOTE=gurgle528;49248526]What happens when you try to spawn it? As for it showing in the wrong tab, it's just using a different function to add itself to the spawn menu[/QUOTE] Then it is spawned, but has no model (ERROR) and the ENT:AcceptInput funciton is not called.
[code] list.Set("NPC", "FILENAMEHERE", { Name = "Shop NPC", Class = "FILENAMEHERE", Category = "P4sca1 NPCs" }) -- Draws the model, so its not an error or something (client) function ENT:Draw() self:DrawModel() end [/code]
Sorry, you need to Log In to post a reply to this thread.