• NPC Shop Panel
    2 replies, posted
Hi, I need some help , i hope someone can help me! Problem : If i open the Menu its showing all players the menu! shared : [QUOTE] ENT.Base = "base_ai" ENT.Type = "ai" ENT.AutomaticFrameAdvance = true ENT.PrintName = "RPG SELLER" ENT.Author = "Synix28" ENT.Category = "RPG" ENT.Spawnable = true ENT.AdminSpawnable = true ENT.Model = "models/Humans/Group02/male_09.mdl" [/QUOTE] Init : [QUOTE] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) function ENT:Initialize() self:SetModel( "models/Humans/Group02/male_09.mdl" ) self:SetHullType( HULL_HUMAN ) self:SetHullSizeNormal( ) self:SetNPCState( NPC_STATE_SCRIPT ) self:SetSolid( SOLID_BBOX ) self:CapabilitiesAdd( CAP_ANIMATEDFACE ) self:SetUseType( SIMPLE_USE ) self:DropToFloor() self:SetMaxYawSpeed( 180 ) end function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local ent = ents.Create( "npc_seller" ) ent:SetPos( tr.HitPos + tr.HitNormal * 16 ) ent:Spawn() ent:Activate() return ent end util.AddNetworkString("FMenu") function ENT:AcceptInput( Name, Activator, Caller ) if Name == "Use" and Caller:IsPlayer() then net.Start("FMenu") net.Broadcast() end end function ENT:PhysgunPickup(ply) if ply:IsAdmin(ply) then return true else return false end end function ENT:CanTool(ply, trace, mode) if ply:IsAdmin(ply) then return true else return false end end function buyEntity(ply, cmd, args) local ent = ents.Create(args[1]) local tr = ply:GetEyeTrace() local balance = ply:GetNWInt("MONEY") if (ent:IsValid()) then local ClassName = ent:GetClass() if (!tr.Hit) then return end local SpawnPos = ply:GetShootPos() + ply:GetForward() * 80 ent:SetPos(SpawnPos) ent:Spawn() end end concommand.Add("buy_entity", buyEntity) [/QUOTE] cl_init : [QUOTE] include('shared.lua') entsArr = { {"m9k_ammo_ar2", "models/items/ammocrates/crate40mm.mdl",100}, {"m9k_ammo_357", "models/items/ammocrates/crate40mm.mdl",100}, {"m9k_ammo_buckshot", "models/items/ammocrates/crate40mm.mdl",100}, {"m9k_ammo_pistol", "models/items/ammocrates/crate40mm.mdl",100}, {"m9k_ammo_40mm_single", "models/items/ammocrates/crate40mm.mdl",100}, {"m9k_ammo_smg", "models/items/ammocrates/crate40mm.mdl",100}, {"m9k_ammo_winchester", "models/items/ammocrates/crate40mm.mdl",100}, {"item_ammo_357", "models/items/ammocrates/crate40mm.mdl",100}, {"item_ammo_ar2", "models/items/ammocrates/crate40mm.mdl",100}, } net.Receive("FMenu", function() local Menu = vgui.Create("DFrame") Menu:SetSize(750,500) Menu:SetPos(ScrW() / 2 - 375, ScrH() / 2 - 250) Menu:SetTitle("") Menu:SetDraggable(false) Menu:ShowCloseButton(true) Menu:MakePopup() Menu.Paint = function() surface.SetDrawColor(60,60,60,255) surface.DrawRect(0,0,Menu:GetWide(),Menu:GetTall()) surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,24,Menu:GetWide(), 1) end addButtons(Menu) end) function addButtons(Menu) local ShopButton = vgui.Create("DButton") ShopButton:SetParent(Menu) ShopButton:SetText("") ShopButton:SetSize(100,50) ShopButton:SetPos(0,25) ShopButton.Paint = function() surface.SetDrawColor(50,50,50,255) surface.DrawRect(0,0,ShopButton:GetWide(),ShopButton:GetTall()) surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,49,ShopButton:GetWide(),1) surface.DrawRect(99,0,1,ShopButton:GetTall()) draw.DrawText("Shop","DermaDefaultBold",ShopButton:GetWide() / 2, 17, Color(255, 255, 255 ,255), 1) end ShopButton.DoClick = function(ShopButton) local ShopPanel = Menu:Add("ShopPanel") local iconList = vgui.Create("DIconLayout", ShopPanel) iconList:SetPos(15,0) iconList:SetSize(ShopPanel:GetWide(),ShopPanel:GetTall()) iconList:SetSpaceY(5) iconList:SetSpaceX(5) for k, v in pairs(entsArr) do local icon = vgui.Create("SpawnIcon", iconList) icon:SetModel(v[2]) icon:SetToolTip(v["PrintName"]) iconList:Add(icon) icon.DoClick = function(icon) LocalPlayer():ConCommand("buy_entity "..v[1]) end end end local SellButton = vgui.Create("DButton") SellButton:SetParent(Menu) SellButton:SetText("") SellButton:SetSize(100,50) SellButton:SetPos(0,75) SellButton.Paint = function() surface.SetDrawColor(50,50,50,255) surface.DrawRect(0,0,SellButton:GetWide(),SellButton:GetTall()) surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,49,SellButton:GetWide(),1) surface.DrawRect(99,0,1,SellButton:GetTall()) draw.DrawText("Sell","DermaDefaultBold",SellButton:GetWide() / 2, 17, Color(255, 255, 255 ,255), 1) end SellButton.DoClick = function(SellButton) local SellPanel = Menu:Add("SellPanel") end end PANEL = {} function PANEL:Init() self:SetSize(650,475) self:SetPos(100,25) end function PANEL:Paint(w, h) draw.RoundedBox(0,0,0,w,h, Color(50,50,50,255)) end vgui.Register("ShopPanel",PANEL,"Panel") PANEL = {} function PANEL:Init() self:SetSize(650,475) self:SetPos(100,25) end function PANEL:Paint(w, h) draw.RoundedBox(0,0,0,w,h, Color(50,50,50,255)) end vgui.Register("SellPanel",PANEL,"Panel")[/QUOTE]
Next time, use [code]. You are doing net.Broadcast() which reaches all players. Use net.Send(activator) instead, which will send the data to that specific player and not to everyone. You can read about the net library in the wiki.
Got it work Thx!
Sorry, you need to Log In to post a reply to this thread.