Hello im pretty new to lua and im trying to make a NPC shop for a darkRP server. I have looked at the practically only 2 NPC shop tutorials online and none of them have helped. none of them have given me options on where to put what the shop is selling. also i need to make this a VIP and admin only thing. (this is based off here http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7853.html) (currently unreachable)
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
– Since this file is ran by both the client and the server, both will share this information.
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.
return false – This NPC won’t take damage from anything.
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
include(‘shared.lua’) – At this point the contents of shared.lua are ran on the client only.
-- 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('VIP 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?" )
usermessage.Hook(“ShopNPCUsed”, NPCShopMenu) --Hook to messages from the server so we know when to display the menu.