• Entity Networking Issue
    3 replies, posted
Hey, so I created an entity, everything seemed to be working perfectly until I found a bug which I do not know how to fix, basically when the entity is interacted with a vgui menu is supposed to popup for the player who used it, however when any player interacts with it they do not get a vgui menu popup, instead the vgui menu shows up on my screen, I've been trying the figure out why this happens but made literally no progress towards solving it. init.lua (Networking section) [CODE]util.AddNetworkString("fieldAgentDisguise") util.AddNetworkString("ertDisguise") util.AddNetworkString("troDisguise") util.AddNetworkString("mtfDisguise") util.AddNetworkString("interacted") function ENT:Use(a,c) for k, v in pairs (whiteList) do if a:Team() == v then net.Start("interacted") net.Send(Entity(1))[/CODE] cl_init.lua [CODE] include("shared.lua") function ENT:Draw() self:DrawModel() end net.Receive("interacted", function(len, ply) print("Client Running!") local disguiseUI = vgui.Create("DFrame") disguiseUI:SetSize(310,200) disguiseUI:SetVisible(true) disguiseUI:Center() disguiseUI:MakePopup() disguiseUI:SetTitle("Disguise Kit") disguiseUI.Paint = function(s, w, h) draw.RoundedBox(5,0,0,w,h,Color(0,0,0)) draw.RoundedBox(5,4,4,w-8,h-8,Color(255,255,255)) end[/CODE]
It's because you're sending the net message to Entity( 1 ) rather than the player who "activated" the entity. I'm also assuming that's a snippet of your ENT.Use function, otherwise, there are errors. So, rather than sending it to Entity( 1 ), send it to "a", which is what you've named the Entity Activator.
[QUOTE=McDunkable;49867374]It's because you're sending the net message to Entity( 1 ) rather than the player who "activated" the entity. I'm also assuming that's a snippet of your ENT.Use function, otherwise, there are errors. So, rather than sending it to Entity( 1 ), send it to "a", which is what you've named the Entity Activator.[/QUOTE] This causes an error :/ "[ERROR] lua/entities/disguise_kit/init.lua:57: bad argument #1 to 'Entity' (number expected, got userdata)"
Stop calling the function Entity. Just do: net.Send( a ) where a is your activator, which comes straight from the function ENT.Use itself. Have a look at these pages: [URL]http://wiki.garrysmod.com/page/Global/Entity[/URL] [URL]http://wiki.garrysmod.com/page/net/Send[/URL] [URL]http://wiki.garrysmod.com/page/ENTITY/Use[/URL]
Sorry, you need to Log In to post a reply to this thread.