I found this old tutorial with a example addon but the only problem is that it doesn't work no more and I need help fixing this
original addon link: [url]https://garrysmods.org/download/1821/shop-npc-examplezip[/url]
Code:
cl_init.lua:
[CODE]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.[/CODE]
init.lua:
[CODE]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
[/CODE]
shared.lua:
[CODE]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.[/CODE]
Fixed
Sorry, you need to Log In to post a reply to this thread.