• DFrame not showing up when activated
    16 replies, posted
So I have this shop NPC I am trying to make, and I am having issues with the initial DFrame that is supposed to open when a user uses the entity, but when I press E on him, nothing happens, no errors are thrown, here is my code, please help if you know what is wrong here. init.lua [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") ENT.Type = "ai" ENT.Base = "base_ai" ENT.PrintName = "Test NPC" ENT.Instructions = "This is a test it probably won't work" ENT.Spawnable = true function ENT:Initialize() self:SetModel("models/breen.mdl") self:SetHullType( HULL_HUMAN ); self:SetHullSizeNormal(); self:SetSolid( SOLID_BBOX ) self:SetMoveType( MOVETYPE_STEP ) self:CapabilitiesAdd(CAP_TURN_HEAD + CAP_ANIMATEDFACE) self:SetHullType(HULL_HUMAN) self:SetHullSizeNormal() self:SetUseType( SIMPLE_USE ) self:SetMaxYawSpeed( 5000 ) end util.AddNetworkString("OpenMenu") function ENT:Use(a, caller) if(IsValid(caller) && caller:IsPlayer()) then net.Start("OpenMenu") net.Send(caller) end end [/CODE] cl_init.lua [CODE]include("shared.lua") net.Receive("OpenMenu", function() local frame = vgui.Create("DFrame") frame:SetSize(ScrW()/2, ScrH()/2) frame:Center() frame:MakePopup() local rgb = Color local DScrollPanel = vgui.Create( "DScrollPanel", frame ) DScrollPanel:SetSize( 565, 300 ) DScrollPanel:SetPos( 5, 500 ) DScrollPanel:Dock( FILL ) DScrollPanel:Center() local sbar = DScrollPanel:GetVBar() function sbar:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(52, 73, 94,100) ) end function sbar.btnUp:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) ) end function sbar.btnDown:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) ) end function sbar.btnGrip:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(44, 62, 80) ) end end)[/CODE] shared.lua [CODE] ENT.Type = "ai" ENT.Base = "base_gmodentity" ENT.PrintName = "Test NPC " ENT.Instructions = "This is a test it probably won't work" ENT.Category = "Dark's Custom Remnant Entities" ENT.Spawnable = true[/CODE] I also would like help on how to remove this little tag under him and add a nametag above him that says his name in a little textbox. Here is the little tag I mean. [IMG]https://cdn.discordapp.com/attachments/365677161719267328/375037911713972224/unknown.png[/IMG] Any help will be greatly appreciated, thank you!
Youve just created another thread for the same issue? Dude, lock this one and ask help in the other one...
[QUOTE=gonzalolog;52841966]Youve just created another thread for the same issue? Dude, lock this one and ask help in the other one...[/QUOTE] I have a new issue now, my old one should be closed but I guess not I'll go close those
I was having the same issue, for now I've given up and worked on other things.
[QUOTE=ActuallyFBI;52843083]I was having the same issue, for now I've given up and worked on other things.[/QUOTE] I don't have the time to give up as someone has promised another person I will get it done without my knowing so getting this done is urgent for me AND IVE ONLY BEEN CODING FOR 5 DAYS
Try taking some [b]extremely basic and beginner-level[/b] debugging steps and let us know what you find out. such as using print() to make sure that ent:Use() is being called, that "caller" is actually a player etc etc.
If you have it in a folder that is setup as a addon, make sure that there are no uppercase's. Because if you run addon folders with upper cases on a Linux dedicated server it will just ignore the addon, and your addon won't even run the lua.
print("This is working.") on anything sent or used. (USE Function and the net receive) Like Pyro said. If one of them doesn't print anything out. Look at that part.
[QUOTE=Snowa;52845184]print("This is working.") on anything sent or used. (USE Function and the net receive) Like Pyro said. If one of them doesn't print anything out. Look at that part.[/QUOTE] Nothing is working on it, it won't even show up in the Q menu anymore, I have these codes right now: init.lua [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") ENT.Type = "ai" ENT.Base = "base_ai" ENT.PrintName = "Test NPC" ENT.Instructions = "This is a test it probably won't work" ENT.Spawnable = true function ENT:Initialize() self:SetModel("models/breen.mdl") self:SetHullType( HULL_HUMAN ); self:SetHullSizeNormal(); self:SetSolid( SOLID_BBOX ) self:SetMoveType( MOVETYPE_STEP ) self:CapabilitiesAdd(CAP_TURN_HEAD + CAP_ANIMATEDFACE) self:SetHullType(HULL_HUMAN) self:SetHullSizeNormal() self:SetUseType( SIMPLE_USE ) self:SetMaxYawSpeed( 5000 ) end util.AddNetworkString("OpenMenu") function ENT:Use(a, caller) net.Start(caller) net.Send("OpenMenu") end end[/CODE] cl_init.lua [CODE]include("shared.lua") net.Receive("OpenMenu", function() print("This is working") end local rgb = Color local DScrollPanel = vgui.Create( "DScrollPanel", frame ) DScrollPanel:SetSize( 565, 300 ) DScrollPanel:SetPos( 5, 500 ) DScrollPanel:Dock( FILL ) DScrollPanel:Center() local sbar = DScrollPanel:GetVBar() function sbar:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(52, 73, 94,100) ) end function sbar.btnUp:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) ) end function sbar.btnDown:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) ) end function sbar.btnGrip:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(44, 62, 80) ) end end)[/CODE] and shared.lua is the same as up top.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/AddNetworkString]util.AddNetworkString[/url]
Bam fixed. init.lua [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel("models/breen.mdl") self:SetSolid(SOLID_BBOX); self:PhysicsInit(SOLID_BBOX); self:SetHullType(HULL_HUMAN) self:SetHullSizeNormal() self:SetNPCState(NPC_STATE_SCRIPT) self:CapabilitiesAdd(CAP_ANIMATEDFACE) self:CapabilitiesAdd(CAP_TURN_HEAD) self:SetUseType(SIMPLE_USE) self:SetMaxYawSpeed(90) self:DropToFloor() end util.AddNetworkString("OpenMenu") function ENT:AcceptInput(input, activator, caller) if input == "Use" and activator:IsPlayer() then net.Start("OpenMenu") net.Send(caller) end end [/CODE] cl_init.lua [CODE]include("shared.lua") ENT.RenderGroup = RENDERGROUP_BOTH net.Receive("OpenMenu", function() local frame = vgui.Create("DFrame") frame:SetSize(ScrW()/2, ScrH()/2) frame:Center() frame:MakePopup() local rgb = Color local DScrollPanel = vgui.Create( "DScrollPanel", frame ) DScrollPanel:SetSize( 565, 300 ) DScrollPanel:SetPos( 5, 500 ) DScrollPanel:Dock( FILL ) DScrollPanel:Center() local sbar = DScrollPanel:GetVBar() function sbar:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(52, 73, 94,100) ) end function sbar.btnUp:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) ) end function sbar.btnDown:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) ) end function sbar.btnGrip:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(44, 62, 80) ) end end) hook.Add("PostDrawOpaqueRenderables", "NpcTitle", function() for _, ent in pairs (ents.FindByClass("testnpc")) do if ent:GetPos():Distance(LocalPlayer():GetPos()) < 800 then local plyAng = LocalPlayer():GetAngles() local ang = Angle(0, plyAng.y - 180, 0) ang:RotateAroundAxis(ang:Forward(), 90) ang:RotateAroundAxis(ang:Right(), -90) cam.Start3D2D(ent:GetPos() + ent:GetForward() + ent:GetUp() * 85, ang, 0.1) draw.RoundedBox(4, -50, -22, 100, 20, Color(10, 10, 10, 150)) draw.SimpleText( "Test Npc", "Trebuchet24", 0, -25, Color(0, 139, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) cam.End3D2D() end end end) [/CODE] shared.lua [CODE]ENT.Type = "ai" ENT.Base = "base_ai" ENT.PrintName = "Test NPC " ENT.Instructions = "This is a test it WILL FOR SURE work thanks to -ICE- my lord and savior :D" ENT.Category = "Dark's Custom Remnant Entities" ENT.Spawnable = true ENT.AdminSpawnable = true[/CODE] [editline]1st November 2017[/editline] [QUOTE=MrRalgoman;52845404][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/AddNetworkString]util.AddNetworkString[/url][/QUOTE] Read closer silly :P
[QUOTE=-ICE-;52845448]Bam fixed. init.lua [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel("models/breen.mdl") self:SetSolid(SOLID_BBOX); self:PhysicsInit(SOLID_BBOX); self:SetHullType(HULL_HUMAN) self:SetHullSizeNormal() self:SetNPCState(NPC_STATE_SCRIPT) self:CapabilitiesAdd(CAP_ANIMATEDFACE) self:CapabilitiesAdd(CAP_TURN_HEAD) self:SetUseType(SIMPLE_USE) self:SetMaxYawSpeed(90) self:DropToFloor() end util.AddNetworkString("OpenMenu") function ENT:AcceptInput(input, activator, caller) if input == "Use" and activator:IsPlayer() then net.Start("OpenMenu") net.Send(caller) end end [/CODE] cl_init.lua [CODE]include("shared.lua") ENT.RenderGroup = RENDERGROUP_BOTH net.Receive("OpenMenu", function() local frame = vgui.Create("DFrame") frame:SetSize(ScrW()/2, ScrH()/2) frame:Center() frame:MakePopup() local rgb = Color local DScrollPanel = vgui.Create( "DScrollPanel", frame ) DScrollPanel:SetSize( 565, 300 ) DScrollPanel:SetPos( 5, 500 ) DScrollPanel:Dock( FILL ) DScrollPanel:Center() local sbar = DScrollPanel:GetVBar() function sbar:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(52, 73, 94,100) ) end function sbar.btnUp:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) ) end function sbar.btnDown:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) ) end function sbar.btnGrip:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, rgb(44, 62, 80) ) end end) hook.Add("PostDrawOpaqueRenderables", "NpcTitle", function() for _, ent in pairs (ents.FindByClass("testnpc")) do if ent:GetPos():Distance(LocalPlayer():GetPos()) < 800 then local plyAng = LocalPlayer():GetAngles() local ang = Angle(0, plyAng.y - 180, 0) ang:RotateAroundAxis(ang:Forward(), 90) ang:RotateAroundAxis(ang:Right(), -90) cam.Start3D2D(ent:GetPos() + ent:GetForward() + ent:GetUp() * 85, ang, 0.1) draw.RoundedBox(4, -50, -22, 100, 20, Color(10, 10, 10, 150)) draw.SimpleText( "Test Npc", "Trebuchet24", 0, -25, Color(0, 139, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) cam.End3D2D() end end end) [/CODE] shared.lua [CODE]ENT.Type = "ai" ENT.Base = "base_ai" ENT.PrintName = "Test NPC " ENT.Instructions = "This is a test it WILL FOR SURE work thanks to -ICE- my lord and savior :D" ENT.Category = "Dark's Custom Remnant Entities" ENT.Spawnable = true ENT.AdminSpawnable = true[/CODE] [editline]1st November 2017[/editline] Read closer silly :P[/QUOTE] Dude you are fucking jesus to me you don't even know, I am new to coding like I said so this much help really makes me happy af, without it idk what I would have had to do to make this work!
You're welcome :P I don't have time to explain what I did to fix it because I'm late to dinner with my girlfriend now and man she isn't happy xD
[QUOTE=-ICE-;52845475]You're welcome :P I don't have time to explain what I did to fix it because I'm late to dinner with my girlfriend now and man she isn't happy xD[/QUOTE] It okay, have a nice dinner and sorry for keeping you! Have fun!
[QUOTE=Moat;52845493]Instead of doing [lua] hook.Add("PostDrawOpaqueRenderables", "NpcTitle", function() for _, ent in pairs (ents.FindByClass("testnpc")) do --draw stuff end end) [/lua] Just do [lua] function ENT:Draw() -- draw stuff end [/lua] It is very very bad to use ents.FindByClass in any scenerio, as it loops through [B]every[/B] entity. Especially in a draw hook, it can lead to incredible inefficiency.[/QUOTE] Which part do I remove? That code is a bit out of order.
Sorry, you need to Log In to post a reply to this thread.