• Snpc
    11 replies, posted
My snpc is not working when a press the use key on it. I do not get a error in my console and i don't get the user message. Here are the init.lua and cl_init.lua in my entity. Init.lua [lua]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') function ENT:Initialize( ) self.Entity:SetModel( "models/Humans/Group01/Female_01.mdl" ) self.Entity:SetHullType( HULL_HUMAN ) self.Entity:SetUseType( SIMPLE_USE ) self.Entity:SetHullSizeNormal( ) self.Entity:SetSolid( SOLID_BBOX ) self.Entity:CapabilitiesAdd( CAP_ANIMATEDFACE | CAP_TURN_HEAD ) self.Entity:SetMaxYawSpeed( 5000 ) end function ENT:AcceptInput( name, activator, caller, data ) if caller:IsPlayer() then umsg.Start("shopmenu", caller) umsg.End() end end local schdChase = ai_schedule.New( "AIFighter Chase" ) //creates the schedule used for this npc // Run away randomly (first objective in task) schdChase:EngTask( "TASK_GET_PATH_TO_RANDOM_NODE", 128 ) schdChase:EngTask( "TASK_RUN_PATH", 0 ) schdChase:EngTask( "TASK_WAIT_FOR_MOVEMENT", 0 ) schdChase:AddTask( "PlaySequence", { Name = "cheer1", Speed = 1 } ) // Find an enemy and run to it (second objectives in task) schdChase:AddTask( "FindEnemy", { Class = "player", Radius = 2000 } ) schdChase:EngTask( "TASK_GET_PATH_TO_RANGE_ENEMY_LKP_LOS", 0 ) schdChase:EngTask( "TASK_RUN_PATH", 0 ) schdChase:EngTask( "TASK_WAIT_FOR_MOVEMENT", 0 ) // Shoot it (third objective in task) schdChase:EngTask( "TASK_STOP_MOVING", 0 ) schdChase:EngTask( "TASK_FACE_ENEMY", 0 ) schdChase:EngTask( "TASK_ANNOUNCE_ATTACK", 0 ) schdChase:EngTask( "TASK_RANGE_ATTACK1", 0 ) schdChase:EngTask( "TASK_RELOAD", 0 ) //schedule is looped till you give it a different schedule function ENT:Initialize() self:SetModel( "models/Humans/Group01/Female_01.mdl" ) self:SetHullType( HULL_HUMAN ); self:SetHullSizeNormal(); self:SetSolid( SOLID_BBOX ) self:SetMoveType( MOVETYPE_STEP ) self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_OPEN_DOORS | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_USE_SHOT_REGULATOR | CAP_AIM_GUN ) self:SetMaxYawSpeed( 5000 ) //don't touch stuff above here self:SetHealth(100) self:Give( "weapon_ak47" ) //Can be given sweps. end function ENT:OnTakeDamage(dmg) self:SetHealth(self:Health() - dmg:GetDamage()) if self:Health() <= 0 then //run on death self:SetSchedule( SCHED_FALL_TO_GROUND ) //because it's given a new schedule, the old one will end. end end /*--------------------------------------------------------- Name: SelectSchedule ---------------------------------------------------------*/ function ENT:SelectSchedule() self:StartSchedule( schdChase ) //run the schedule we created earlier end [/Lua] cl_init.lua [lua]include('shared.lua') include('init.lua') function myMenu() local DFrame1 DFrame1 = vgui.Create('DFrame') DFrame1:SetSize(674, 252) DFrame1:Center DFrame1:SetTitle('My Place Shop') DFrame1:SetSizable(true) DFrame1:SetDeleteOnClose(false) DFrame1:MakePopup() end usermessage.Hook("shopmenu",myMenu) ENT.RenderGroup = RENDERGROUP_BOTH /*--------------------------------------------------------- Name: Draw Desc: Draw it! ---------------------------------------------------------*/ function ENT:Draw() self.Entity:DrawModel() end /*--------------------------------------------------------- Name: DrawTranslucent Desc: Draw translucent ---------------------------------------------------------*/ function ENT:DrawTranslucent() // This is here just to make it backwards compatible. // You shouldn't really be drawing your model here unless it's translucent self:Draw() end /*--------------------------------------------------------- Name: BuildBonePositions Desc: ---------------------------------------------------------*/ function ENT:BuildBonePositions( NumBones, NumPhysBones ) // You can use this section to position the bones of // any animated model using self:SetBonePosition( BoneNum, Pos, Angle ) // This will override any animation data and isn't meant as a // replacement for animations. We're using this to position the limbs // of ragdolls. end /*--------------------------------------------------------- Name: SetRagdollBones Desc: ---------------------------------------------------------*/ function ENT:SetRagdollBones( bIn ) // If this is set to true then the engine will call // DoRagdollBone (below) for each ragdoll bone. // It will then automatically fill in the rest of the bones self.m_bRagdollSetup = bIn end /*--------------------------------------------------------- Name: DoRagdollBone Desc: ---------------------------------------------------------*/ function ENT:DoRagdollBone( PhysBoneNum, BoneNum ) // self:SetBonePosition( BoneNum, Pos, Angle ) end [/Lua]
Try this [url]http://wiki.garrysmod.com/?title=NPC_Shop_Tutorial[/url] You don't have to make it a shop, but it gives you a basic overview of how to make it accept players when they press a certain key on them.
[QUOTE=LuckyLuke;22560633]Try this [url]http://wiki.garrysmod.com/?title=NPC_Shop_Tutorial[/url] You don't have to make it a shop, but it gives you a basic overview of how to make it accept players when they press a certain key on them.[/QUOTE] Thats what I used.
You've missed out a vital part in the ENT:AcceptInput function. [lua]if calller:IsPlayer() and name == "Use" then[/lua]
That tutorial is a mess, as i stated before you should use KeyPress and traces, means you can get the NPC useable through glass and stuff, but that method works if you want to make it simple
[QUOTE=LuckyLuke;22561509]You've missed out a vital part in the ENT:AcceptInput function. [lua]if calller:IsPlayer() and name == "Use" then[/lua][/QUOTE] Still nothing.
I'm going to clean up that tutorial with a completed example at the end.
[QUOTE=Crazy Quebec;22561670]I'm going to clean up that tutorial with a completed example at the end.[/QUOTE] Cool beans.
[code] function ENT:AcceptInput(activator) if activator:IsPlayer() then umsg.Start("shopmenu", activator) umsg.End() end [/code] try that
H4rDm0D : Your missing an end on that function :P [LUA] function ENT:AcceptInput(activator) if activator:IsPlayer() then umsg.Start("shopmenu", activator) umsg.End() end end [/LUA] now ... [QUOTE] ...try that [/QUOTE]
or you could use [code] function ENT:Use(activator) if activator:IsPlayer() and activator:IsAlive() then umsg.Start("shopmenu", activator) umsg.End() end end [/code]
[Lua]function ENT:AcceptInput(activator, pl) if ( pl:KeyPressed( IN_USE ) ) then umsg.Start("shopmenu", activator) umsg.End() end end [/Lua] Ok I changed to look for key presses and it worked.
Sorry, you need to Log In to post a reply to this thread.