• Numpad Feature Help
    0 replies, posted
Alright so I basically want to add a numpad feature to this addon: [url]http://www.garrysmod.org/downloads/?a=view&id=42593[/url] The addon makes NPCs do an animation when you shoot them with a toolgun and I think it's annoying to have a toolgun beam shooting at an NPC in your recording. So I want to build a numpad feature for it. Here's the code so far, I was playing around with it. [code] TOOL.Category = "Poser" TOOL.Name = "#NPC Scene" TOOL.Command = nil TOOL.ConfigName = "" TOOL.ClientConVar["name"] = "scenes/npc/Gman/gman_intro" TOOL.ClientConVar["actor"] = "Alyx" TOOL.ClientConVar["SelectedNpc2"] = "1" local SelectedNpc = 1 if (CLIENT) then local SceneList = {} local function ParseDir(t, name, ext) for k,v in pairs(file.Find("../"..name.."*"..ext)) do local n = t:AddNode(string.gsub(v, ".vcd", "")) n.MyLabelThing = name..string.gsub(v, ".vcd", "") n.DoClick = function(self) RunConsoleCommand("npc_scene_name", self.MyLabelThing) end end for k,v in pairs(file.FindDir("../"..name.."*")) do local n = t:AddNode(v) ParseDir(n, name..v.."/", ext) n:SetExpanded(false) end end SceneListPanel = vgui.Create("DFrame") SceneListPanel:SetSize (300, 750 ) SceneListPanel:SetPos (100, 100 ) SceneListPanel:SetVisible (false ) SceneListPanel:SetDeleteOnClose (false ) SceneListPanel:SetTitle ("Scenes" ) local ctrl = vgui.Create("DTree", SceneListPanel) ctrl:SetPadding(5) ctrl:SetSize (300, 725 ) ctrl:SetPos (0, 25 ) local node = ctrl:AddNode("Scenes! (click one to select)") ParseDir(node, "scenes/", ".vcd") language.Add( "Tool_npc_scene_name", "NPC Scene" ) language.Add( "Tool_npc_scene_desc", "Make NPCs act!" ) language.Add( "Tool_npc_scene_0", "Left click to play entered scene, right to set the actor name." ) function ListScenes() SceneListPanel:SetVisible(true) SceneListPanel:MakePopup() end concommand.Add("npc_scene_list", ListScenes) function TOOL.BuildCPanel(CPanel) CPanel:AddControl("Header", {Text = "#NPC Scene", Description = "NPC Scenes"}) CPanel:AddControl("TextBox", { Label = "Scene Name", Command = "npc_scene_name", MaxLength = 500 }) CPanel:AddControl("Button", { Text = "List Scenes", Name = "List Scenes", Command = "npc_scene_list" }) CPanel:AddControl("TextBox", { Label = "Actor Name", Command = "npc_scene_actor", MaxLength = 500 }) CPanel:AddControl( "Numpad", { Label = "Animation", Command = "animation_start", ButtonSize = 22 } ) end end function TOOL:LeftClick(tr) if tr.Hit and tr.Entity and tr.Entity:IsValid() and tr.Entity:IsNPC() then SelectedNpc = tr.Entity return true end end function TOOL:RightClick(tr) if tr.Hit and tr.Entity and tr.Entity:IsValid() and tr.Entity:IsNPC() then if SERVER then tr.Entity:SetName(self:GetClientInfo("actor")) end return true end end function TOOL:Think( ) -- numpad.Register( "animation_start", function() -- if SERVER then -- SelectedNpc:PlayScene(string.gsub(self:GetClientInfo("name"), ".vcd", "")) -- end -- end ); function blah() print("WORKS") end numpad.Register( "animation_start", blah ) end [/code] Well I added a Cpanel: CPanel:AddControl( "Numpad", { Label = "Animation", Command = "animation_start", ButtonSize = 22 } ) And I want that numkey to start a function, and I have no idea where to put it under So I made a numpad.Register( "animation_start", blah ) in function TOOL:Think( ) Where should I properly place it? Also the compiler is saying that numpad.Register( "animation_start", blah ) is giving a nil value. The function blah has no errors so I don't know why the numpad is giving a nil. Here's the error: weapons\gmod_tool\stools/npc_scene.lua:97: attempt to index global 'numpad' (a nil value) [editline]05:37PM[/editline] Ok well I added a change to get rid of the error: [code] if SERVER then function blah() print("WORKS!") end numpad.Register( "animation_start", blah ) end [/code] Had to make it under if SERVER. So now I get this error when I push the key: Unknown command: animation_start
Sorry, you need to Log In to post a reply to this thread.