So basically, I am having problems creating a menu when a player presses 'e' on an entity that is unique to that entity. What I have so far:
init.lua
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/unconid/pc_models/monitors/lcd_acer_16x9.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
end
util.AddNetworkString( "pc_menu_open" )
function ENT:Use( activator, caller )
net.Start( "pc_menu_open" )
net.WriteEntity( self )
net.Send( caller )
end
function ENT:Think()
end
cl_init.lua
include("shared.lua")
function ENT:Initialize()
end
function ENT:Draw()
self:DrawModel()
local Pos = self:GetPos()
local Ang = self:GetAngles()
Ang:RotateAroundAxis(Ang:Up(), 90)
Ang:RotateAroundAxis(Ang:Forward(), 90)
cam.Start3D2D(Pos + Ang:Up() * 1.7, Ang, 0.11)
draw.SimpleText( tostring( self ), "DermaDefault", 0, -140+(115/2)-30, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
cam.End3D2D()
end
function ENT:Think()
net.Receive("pc_menu_open",function()
self.RecievedEnt = net.ReadEntity()
if( self == self.RecievedEnt ) then
if( !IsValid(self.DermaPanel) ) then
self.DermaPanel = vgui.Create( "DFrame" )
self.DermaPanel:SetSize( 300, 200 )
self.DermaPanel:Center()
self.DermaPanel:SetTitle( tostring(self) )
self.DermaPanel:SetDraggable( true )
self.DermaPanel:MakePopup()
else
self.DermaPanel:SetVisible( true )
end
end
end)
end
shared.lua
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Custom PC"
ENT.Author = "Brick Wall"
ENT.Spawnable = true
ENT.AdminSpawnable = true
Unfortunately, this doesn't work, it will create 1 menu for the first entity used, but then for any other ones, a menu will not be created.
net.Recieve should not be in anything for that matter except for your case where you want to enclose it inside of an “if CLIENT then end”
You also want to be careful sending net messages in predicted hooks because net messages might act strangely.
Yeah, thanks for the help, I have already done that as I only had it in the think so that I could access self, but I have now moved it out. Thanks!
Sorry, you need to Log In to post a reply to this thread.