• NPC Store Help
    0 replies, posted
Well, my problem is that the NPC is spawning as an error with no bounding box and I can't hit use on it. My codes are: 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. [/lua] init.lua [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/breen.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 [/lua] shared.lua [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. [/lua] Part of Gamemode init.lua [lua] function NpcShop() NPCShop = ents.Create("npc_shop") //800,480,33 NPCShop:SetPos(Vector(800,480,33)) -- sets the position NPCShop:SetAngles(Vector(0,0,0)) NPCShop:Spawn() -- spawns the npc_shop entity end hook.Add("InitPostEntity","shop",NpcShop) [/lua] [editline]05:54PM[/editline] Resolved by localling NPCShop I think.
Sorry, you need to Log In to post a reply to this thread.