I have been trying to some stuff for my gamemode and I started making something. I made a button and when you press it, a optionsmenu pops up. The options are all the players alive and in team 2. Now how would I give the person I clicked the name of and the local player a pistol? This is my code atm:
[CODE]local function lastre()
local Menu = vgui.Create("DFrame")
Menu:SetPos(ScrW() / 2 - 200, ScrH() / 2 - 150)
Menu:SetSize(400, 300)
Menu:SetTitle("My Menu")
Menu:SetDraggable(false)
Menu:ShowCloseButton(true)
Menu:MakePopup()
local Butt = Menu:Add("DButton",Menu)
Butt:SetText( "Test" )
Butt:SetPos(50, 90 )
Butt:SetSize( 300, 100 )
Butt.DoClick = function( ply )
local MenuButtonOptions = DermaMenu()
for k,v in pairs(team.GetPlayers(2)) do
if v:Alive() then
MenuButtonOptions:AddOption(v:Nick(), function()
v:Give("weapon_deagle")
LocalPlayer():Give("weapon_deagle")
end)
end
end
MenuButtonOptions:Open()
end
end[/CODE]
Give obviously doesn't work because it is clientside and needs to be serverside as far as I know. Also little second question. What function do I use to draw a kill feed/ Death notify?
For the v:Give('weapon_name') you could create a net message.
I don't know what todo with the killfeed, Sorry.
This should work. I am assuming that v was the person you clicked on.
[editline]k[/editline]
I was an idiot and made a mistake.
Client code
[code]local function lastre()
util.AddNetworkString("GiveWeapons")
local Menu = vgui.Create("DFrame")
Menu:SetPos(ScrW() / 2 - 200, ScrH() / 2 - 150)
Menu:SetSize(400, 300)
Menu:SetTitle("My Menu")
Menu:SetDraggable(false)
Menu:ShowCloseButton(true)
Menu:MakePopup()
local Butt = Menu:Add("DButton",Menu)
Butt:SetText( "Test" )
Butt:SetPos(50, 90 )
Butt:SetSize( 300, 100 )
Butt.DoClick = function( ply )
local MenuButtonOptions = DermaMenu()
for k,v in pairs(team.GetPlayers(2)) do
if v:Alive() then
MenuButtonOptions:AddOption(v:Nick(), function()
net.Start("GiveWeapons")
net.WriteString(v)
net.SendToServer()
end)
end
end
MenuButtonOptions:Open()
end
end[/code]
Server Code
[code]net.Receive("GiveWeapons", function(len)
ply = net.ReadString()
ply:Give("weapon_deagle") end)[/code]
This should work.
Sorry, you need to Log In to post a reply to this thread.