NPC Shop Tutorial

When follow the NPC Shop Tutorial, nothing ever defines where the NPC will be spawned in the map. Maybe it does, but I see NO vector coordinates.

These are the files in merchant_shop folder (entity folder)

SHARED.LUA


ENT.Base = "base_ai" -- This entity is based on "base_ai"
ENT.Type = "ai" -- What type of entity is it, in this case, it's an AI.
ENT.AutomaticFrameAdvance = true -- This entity will animate itself.
 
function ENT:SetAutomaticFrameAdvance( bUsingAnim ) -- This is called by the game to tell the entity if it should animate itself.
	self.AutomaticFrameAdvance = bUsingAnim
end

-- Since this file is ran by both the client and the server, both will share this information.

INIT.LUA


AddCSLuaFile( "cl_init.lua" ) -- This means the client will download these files
AddCSLuaFile( "shared.lua" )

include('shared.lua') -- At this point the contents of shared.lua are ran on the server only.


function ENT:Initialize( ) --This function is run when the entity is created so it's a good place to setup our entity.
	
	self:SetModel( "models/humans/group01/female_01.mdl" ) -- Sets the model of the NPC.
	self:SetHullType( HULL_HUMAN ) -- Sets the hull type, used for movement calculations amongst other things.
	self:SetHullSizeNormal( )
	self:SetNPCState( NPC_STATE_SCRIPT )
	self:SetSolid(  SOLID_BBOX ) -- This entity uses a solid bounding box for collisions.
	self:CapabilitiesAdd( CAP_ANIMATEDFACE | CAP_TURN_HEAD ) -- Adds what the NPC is allowed to do ( It cannot move in this case ).
	self:SetUseType( SIMPLE_USE ) -- Makes the ENT.Use hook only get called once at every use.
	self:DropToFloor()
	
	self:SetMaxYawSpeed( 90 ) --Sets the angle by which an NPC can rotate at once.
	
end

function ENT:OnTakeDamage()
	return false -- This NPC won't take damage from anything.
end 

function ENT:AcceptInput( Name, Activator, Caller )	

	if Name == "Use" and Caller:IsPlayer() then
		
		umsg.Start("ShopNPCUsed", Caller) -- Prepare the usermessage to that same player to open the menu on his side.
		umsg.End() -- We don't need any content in the usermessage so we're sending it empty now.
		
	end
	
end




CL_INIT.LUA


include('shared.lua') -- At this point the contents of shared.lua are ran on the client only.

function NPCShopMenu()

	-- Small derma panel just for the example.
	local pShop = vgui.Create('DFrame')
	pShop:SetSize(334, 63)
	pShop:SetPos(ScrW()*0.5, ScrH()*0.5)
	pShop:SetTitle('Rock & Gravel shop')
	pShop:SetSizable(true)
	pShop:SetDeleteOnClose(false)
	pShop:MakePopup()

	-- We can also do anything else the client can do, like using the chat!
	chat.AddText(Color(255,255,128), "Merchant: ",Color(255,255,255), "Welcome to my shop, how can I help you?" )
	
end

usermessage.Hook("ShopNPCUsed", NPCShopMenu) --Hook to messages from the server so we know when to display the menu.

And the point of this thread is?

Are you blindly scanning through threads to increase your post count? If you have nothing helpful to contribute, then I strongly recommend that you get the fuck out of my threads.

You didn’t take the time to try to figure it out for yourself. I’m sure that if you think VERY, VERY HARD (I know that it may seem like somewhat of a challenge, especially for you), then you should be capable of figuring it out for yourself.

This hook should be used to spawn the entity.
http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexfa7e.html

[lua]
local function SpawnEntities()
if SERVER then
local npc = ents.Create(“npc_shop”)
npc:SetPos(Vector(0,0,0))
npc:SetAngles(Angle(0,0,0))
npc:Spawn()
end
end
hook.Add( “InitPostEntity”, “SpawnEntities”, SpawnEntities)
[/lua]

Quality posting at it’s best. I think his avatar strongly reflects this post lol.

Nice work tho.

EDIT:
I just realized, every single time the usermessage is sent, the client creates a totally new DFrame panel WITHOUT removing the old one… LOL, enjoy your 200 invisible DFrames and 30 fps drop.

You forget to take into consideration that THIS IS NOT MY CODE.

This is where it came from, and now I am asking questions about it. Sorry about the two threads, that part is MY BAD.

But you can go ahead and worry about something else, try not to worry too much about myself.

…but seriously, you could have done so many productive things rather than making a worthless attempt to shame me.

He wasn’t talking about you dude, cool down. He was talking about Ludicium’s incredibly rich-with-content post of " And the point of this thread is? "

You need to cool your gasket,

just stand where you want the npc type in console rp_getpos and it will give you your position then just put that in as where you want your npc to spawn and he will spawn there

Brandonj4 pretty much explained it but there are also some darkrp functions that would be useful for actually verifying if someone has the money for it and actually taking the money.

http://wiki.darkrp.com/index.php/DarkRP:Functions


local function SpawnEntities()
    if SERVER then
        local npc = ents.Create("npc_shop")
        npc:SetPos(Vector(0,0,0))
        npc:SetAngles(Angle(0,0,0))
        npc:Spawn()
    end
end
hook.Add( "InitPostEntity", "SpawnEntities", SpawnEntities)

That chunk should go into init.lua, right?

You’ll have to set the class name for the entity also, assuming you only used my code.


local npc = ents.Create("yourNPC's**FolderName**")

You’ll have to set your own positions and angles for it if you haven’t already.


npc:SetPos(Vector(0,0,0))
npc:SetAngles(Angle(0,0,0))

You’ll have to place the spawning code in an init.lua or shared.lua file inside of the Gamemode, or an Addon that autoruns the .lua files.
Ex: If you want to place in the gamemode. Go inside DarkRP’s folders, go inside of init.lua, paste at the bottom.

The tutorial assumes you know some lua so that’s why it dosn’t include any vector points to spawn it. So just use brandonj4’s suggestion to do that. To fix the user message from spamming use the following code in the serverside lua (just paste over the AcceptInput() command):

[lua]
function antispam()
spam = 0
timer.Destroy(“antispam”)
end

function ENT:AcceptInput( Name, Activator, Caller )
if spam == 0 then
if Name == “Use” and Caller:IsPlayer() then
umsg.Start(“ShopNPCUsed”, Caller)
umsg.End()
spam = 1
timer.Create(“antispam”, 2, 1, antispam)
end
end
end
[/lua]

This is a little somthing I made up for use on the store of my gamemode. All this does is creates a timer timed for 2 seconds when a player uses the store. For two seconds you won’t be able to use the store since it’s already open so the code prevents it. After the two seconds it then re-allows use of the store. This is a good place for learning the derma part. Simply put all derma into the client script under the function where the usermessage is called. Some things have changed in Garry’s Mod 13 so don’t be too suprised (I’ll assume your using Garry’s Mod 13).

I don’t understand why you’d do that when you already have:

I’m sure that it won’t open the menu again if the menu is already open and you use the NPC again.

Thanks for all the help everybody, I’ll see where I get to in a few with all this.

But I’m actually developing my server for the current version of GMod, not GMod 13 because I heard that lots of shit on DarkRP was broken on it so…I was thinking that I could just transfer everything over once the release version of GM13 comes out but I guess not.

Well I made mine a bit different but I geuss that would work. I could try it.

You really didn’t ask a question hence why I asked what the point of the thread is…Unless you were implying hey Face punch I don’t know how to Google, do my work for me now. Also if your going to ask for help from people you should learn to ask applicable questions not rhetorical statements. And no I’m not trying to increase my post count, I wasn’t trying to be sarcastic either I was asking a legitimate question. People shouldn’t have to look through 3 different hunks of code to figure out what your asking.

Sure.

On the other hand, though, it doesn’t matter anymore because I fixed my issue with a little arguing with your sorry ass on the side.

So basicly, this ain’t working anymore, well these



self:SetHullSizeNormal()
self.Entity:SetNPCState(NPC_STATE_SCRIPT)
self.Entity:CapabilitiesAdd(CAP_ANIMATEDFACE, CAP_TURN_HEAD)
self.Entity:SetHullType(HULL_HUMAN)


aint working anymore…

Cool post. thanks :slight_smile:


(User was banned for this post ("Dumb bump" - NiandraLades))