A good bit of help required...

So I’ve been trying to make a custom shop NPC using decently simple Lua, the shop would go something like (Press E on entity) (Opens shop in DFrame) (List of bunch of items) I have a small base, but I need help figuring out an issue. The main issue I am having is that once I reload my game, it will no longer have my custom entity in the Q menu under entities This is an issue since I can’t test it. I’m still learning networking since I just started learning Lua a few days ago, but here is what I have (sorry for the bad formatting, I’m new here):

init.Lua


AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")

ENT.Type = "ai"
ENT.Base = "base_ai"

ENT.PrintName = "Test NPC"
ENT.Instructions = "This is a test it probably won't work"

ENT.Spawnable = true

function ENT:Initialize()

	self:SetModel("models/breen.mdl")

	self:SetHullType( HULL_HUMAN );

	self:SetHullSizeNormal();

	self:SetSolid( SOLID_BBOX ) 

	self:SetMoveType( MOVETYPE_STEP )

	self:CapabilitiesAdd(CAP_TURN_HEAD + CAP_ANIMATEDFACE)

	self:SetHullType(HULL_HUMAN)

	self:SetHullSizeNormal()

	self:SetUseType( SIMPLE_USE )
	
	self:SetMaxYawSpeed( 5000 )
end

util.AddNetworkString("Test")

function AcceptInput(name, activator, caller, data)
	if IsValid( caller ) and caller:IsPlayer() then
		net.Start("Test")
		net.Send(ply)
	end
end



cl_init.lua


include("shared.lua")

net.Receive( "Test", function(len, pl))
	if ( IsValid( pl ) and pl:IsPlayer() ) then
		print("Hello")
end
end

shared.Lua


ENT.Type = "ai"
ENT.Base = "base_gmodentity"

ENT.PrintName = "Test NPC "
ENT.Instructions = "This is a test it probably won't work"
ENT.Category = "Dark's Custom Remnant Entities"
ENT.Spawnable = true

Any help will be greatly appreciated, again, I am new to all of this so if I make a stupid mistake that is probably why.

Yes, things get removed on reload. Use


 tags next time and try to indent.



code



:P

And also make your thread titles descriptive rather than just a vague call for help

As said by Lavacoal, restarting your game stops the server and thus removes all entities. Unless you make the entity (NPC) spawn at the same place once the server restarts, it’ll not automatically show up again.
If you don’t want to code a solution yourself, you might be able to make use of this addon for permanent props. If you want to make your own, you’ll need to hook into

GM:InitPostEntity or similar and spawn it at a saved location. You can use the file library to save data like this across sessions.

Sorry, I am quite dumb, I meant that it was not showing in the Q menu under entities at all

And no errors are thrown? You’re sure it’s loading properly? Are you able to forcibly spawn it in (ent_create or equivalent)?

No need to call yourself dumb, just misinterpreted your post.

No errors, I got it to work, but now the function to create the actual DFrame is not loading properly, no errors or anything, here is the code for init and cl_init

init.lua



AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")

ENT.Type = "ai"
ENT.Base = "base_ai"

ENT.PrintName = "Test NPC"
ENT.Instructions = "This is a test it probably won't work"

ENT.Spawnable = true

function ENT:Initialize()

	self:SetModel("models/breen.mdl")

	self:SetHullType( HULL_HUMAN );

	self:SetHullSizeNormal();

	self:SetSolid( SOLID_BBOX ) 

	self:SetMoveType( MOVETYPE_STEP )

	self:CapabilitiesAdd(CAP_TURN_HEAD + CAP_ANIMATEDFACE)

	self:SetHullType(HULL_HUMAN)

	self:SetHullSizeNormal()

	self:SetUseType( SIMPLE_USE )
	
	self:SetMaxYawSpeed( 5000 )
end

util.AddNetworkString("OpenMenu")

function ENT:Use(a, caller) 
    if(IsValid(caller) && caller:IsPlayer()) then 
        net.Start("OpenMenu")
        net.Send(caller) 
    end
end

cl_init.lua



include("shared.lua")

net.Receive("OpenMenu", function() 
    frame:SetSize(500, 500) 
    frame:Center() 
    frame:MakePopup() 
    frame:ShowCloseButton(true)
end)

Not the most experienced coder, so again, no clue what would cause the DFrame to not show when I press E on the entity

Also, thanks for answering so fast to all my questions, and one more question, how do I get it to hide the little line and text that comes out of the legs of my entity when I spawn it?

You have to do


include("shared.lua")

net.Receive("OpenMenu", function() 
    local frame = vgui.Create("DFrame")
    frame:SetSize(500, 500) 
    frame:Center() 
    frame:MakePopup() 
    frame:ShowCloseButton(true)
end)

Note what I changed there. You have tell it to actually create the frame. Then the variable ‘frame’ can now be manipulated.

Side note:


frame:ShowCloseButton(true)

is unnecessary because it already is shown by default.

Ah, that would typically help, I was getting help from someone else and they gave me that, so I assume I forgot that line or they did, either way, thank you for pointing out the mistake!

[editline]30th October 2017[/editline]

When I spawn in the entity, and press E on him, nothing happens, it is just like I don’t even have that function

[editline]30th October 2017[/editline]

Should I just use the acceptinput function instead?

-snip-