Derma Menu

I made this Derma Menu and for some reason it isn’t working.

[lua] function GunMenu()

local ply = LocalPlayer()

MayorFrame = vgui.Create(‘DFrame’)
MayorFrame:SetSize(372, 394)
MayorFrame:Center()
MayorFrame:SetTitle(‘Mayor’)
MayorFrame:SetSizable(true)
MayorFrame:SetDeleteOnClose(false)
MayorFrame:MakePopup()

for k, v in paris(Player.GetAll()) do
local DMultiChoice1 = vgui.Create(‘DMultiChoice’, MayorFrame)
DMultiChoice1:SetPos(252, 134)
DMultiChoice1.OnMousePressed = function() end
function DMultiChoice1:OnSelect(Index, Value, Data) end

DMultiChoice1:AddChoice( v:GetNick() )

local MayorButton = vgui.Create(‘DButton’, MayorFrame)
MayorButton:SetSize(97, 42)
MayorButton:SetPos(257, 252)
MayorButton:SetText(‘Fire’)
MayorButton.DoClick = function()

LocalPlayer():ConCommand("say /fire "… tostring(ply:UserID())

local MayorButton2 MayorButton2 = vgui.Create(‘DButton’, MayorFrame)
MayorButton2:SetSize(101, 45)
MayorButton2:SetPos(254, 352)
MayorButton2:SetText(‘Promote’)
MayorButton2.DoClick = LocalPlayer():ConCommand("say /promote "… tostring(ply:UserID()) [/lua]

for k, v in paris(Player.GetAll()) do

in paris should be in pairs, and there’s no end to the loop

lol, in paris C: - But it also seems like you missed to end the function, and the loop? Or didn’t you put it in the post.

[lua]function GunMenu()

local ply = LocalPlayer()
local ID = ID or 0

MayorFrame = vgui.Create(‘DFrame’)
MayorFrame:SetSize(372, 394)
MayorFrame:Center()
MayorFrame:SetTitle(‘Mayor’)
MayorFrame:SetSizable(true)
MayorFrame:SetDeleteOnClose(false)
MayorFrame:MakePopup()

local DMultiChoice1 = vgui.Create(‘DMultiChoice’, MayorFrame)
DMultiChoice1:SetPos(252, 134)
DMultiChoice1.OnMousePressed = function() end
function DMultiChoice1:OnSelect(num)
ID = Entity(num):UserID()
end

for k, v in pairs(player.GetAll()) do
DMultiChoice1:AddChoice( v:Nick() )
end

local MayorButton = vgui.Create(‘DButton’, MayorFrame)
MayorButton:SetSize(97, 42)
MayorButton:SetPos(257, 252)
MayorButton:SetText(‘Fire’)
MayorButton.DoClick = function()
LocalPlayer():ConCommand("say /fire " … tostring(ID))
end

local MayorButton2 = vgui.Create(‘DButton’, MayorFrame)
MayorButton2:SetSize(101, 45)
MayorButton2:SetPos(254, 352)
MayorButton2:SetText(‘Promote’)
MayorButton2.DoClick = function()
LocalPlayer():ConCommand("say /promote " … tostring(ID))
end

end[/lua]

Fixed.

Thank you, where would I put that in Darkrp? Would I put it in CL init or in the lua/autorun/server folder, also how would I make it so you needed a chat command to open it, also how would you restrict to so only the Mayor can open it, this is the problem I have with Derma things, how to set it too open on the /chatcommand function.

I think DarkRP has something like AddChatCommand(“Test”, FUNCTION NAME)

Yeah I tried that, but I got a Nil Value.

Also ReTurtl3, I tried it but it didn’t work.

Works fine for me you just don’t have any chat command for /promote id or /fire id

show me your serverside code for /promote

[editline]20th January 2012[/editline]

for server side should be something like

[lua]AddChatCommand("/promote", function(ply,txt)
if ply:Team() == TEAM_MAYOR then
if string.gsub(tonumber(txt),"/promote “,”") == Entity(string.gsub(tonumber(txt),"/promote “,”")):UserID() then
Entity(string.gsub(tonumber(txt),"/promote “,”")):SetTeam(TEAM_MAYOR)
ply:SetTeam(TEAM_CITIZEN)
end
end
end)[/lua]

try that I haven’t used it do I dunno if it will work or not.

[lua]local function cmdPromotePlayer(client, arguments)
if (client:Team() == TEAM_MAYOR) then
if (arguments[1] and arguments[1] != “”) then
for k, v in pairs( player.GetAll() ) do
if (string.find(v:Nick(),arguments[1])) then
if v:Team() == TEAM_POLICE then
v:ChangeTeam(TEAM_CHIEF, true);
Notify(v, 1, 4, “You have been promoted to Police Chief.”)
break
end;
end;
end;
end;
end;
return “”
end;

AddChatCommand("/promote", cmdPromotePlayer);[/lua]

How would I make it so you had to be Mayor and had to use a chat command to open the menu?

The same thing you did on serverside but
[lua]
if !LocalPlayer():Team() == TEAM_MAYOR then return end // only mayors can open the vgui
[/lua]

Also if you’re going to use nick for setting them to mayor I suggest you change
[lua]local ID = ID or “”

ID = Entity(num):UserID()
[/lua]
To
[lua]
local ID = ID or “”

ID = Entity(num):Nick()
[/lua]

Thanks, how would I add a chat command function to open the menu.

Also, when I put the file in /autorun/server (my srcds server), I keep getting either Localplayer is a nil value or vgui.create is a nil value.

It goes in cl_init.laa if you want it to run, but it should go with what ever menu you used last time.