Results 1 to 14 of 14
  1. #1
    XviperGamingXVG's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    236

    Trouble with my lua derma menu!

    I want to make so that when you run the lua cheat and press insert the menu pops up once, not repeat, and then when i click insert again it closes, just like a toggle, and i also want the menu to be draggable too, why am i asking this when i could just put frame:SetDraggable(true), well because when i add a frame.Think function to the DrawMenu function it seems to remove the dragbase and its really frustrating! Basically what i just want is a menu where it toggles the menu open and closes it with insert and the menu to be draggable.

    Please help me and thank you for your help!

    Code:
    local function DrawMenu()
    	local frame = vgui.Create("DFrame")
    	frame:SetSize(1110, 650)
    	frame:Center()
    	frame:SetTitle("")
    	frame:MakePopup()
    	frame:SetVisible(true)
    	frame:ShowCloseButton(false)
    	frame:SetDraggable(true)
    	local button = vgui.Create("DButton", frame)
    	button:SetFont('marlett')
    	button:SetText('r')
    	button:SetColor(Color(20, 20, 20))
    	button:SetSize(15, 15)
    	button:SetDrawBackground(false)
    	button:SetPos(frame:GetWide() - 20, 5)
    	button.DoClick = function()
    		frame:Remove()
    	end
    end
    
    concommand.Add("derma_menu", DrawMenu)
    
    local function OpenMenu()
    	if input.IsKeyDown(KEY_INSERT) then
    		DrawMenu()
    	end
    end
    
    hook.Add("Think", "", OpenMenu)
    Last edited by XviperGamingXVG; 06-11-2017 at 12:23 PM.

  2. #2
    Cyaegha's Avatar
    Join Date
    Aug 2016
    Gender
    male
    Posts
    536
    Reputation
    17
    Thanks
    526
    Code:
    -- define the variables in the main chunk so we don't create a global
    local menuframe, menudown
    
    local ToggleMenu = function()
    	if (menuframe) then -- if menuframe exists then remove it
    		menuframe:Remove()
    		menuframe = nil
    		return -- stop any further code execution
    	end
    
    	-- you could just do menuframe = vgui.Create("DFrame"), I do it this way cos I think it looks neater.
    	local dframe = vgui.Create("DFrame")
    	dframe:SetSize(800, 400)
    	dframe:Center()
    
    	local oThink = dframe.Think -- cache the old dframe.Think
    	dframe.Think = function(self)
    		-- do stuff here
    
    		--https://******.com/Facepunch/garrysmod/blob/master/garrysmod/lua/vgui/dframe.lua#L137-L193
    		return oThink(self) -- return the old think so it runs all the shit.
    	end
    
    	menuframe = dframe 
    end
    
    hook.Add("Think", "you really should put an identifier here", function()
    	local down = input.IsButtonDown(KEY_INSERT)
    
    	if (down and !menudown)
    		ToggleMenu()
    	end
    
    	menudown = down
    end)

  3. #3
    XviperGamingXVG's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    236
    Quote Originally Posted by Cyaegha View Post
    Code:
    -- define the variables in the main chunk so we don't create a global
    local menuframe, menudown
    
    local ToggleMenu = function()
    	if (menuframe) then -- if menuframe exists then remove it
    		menuframe:Remove()
    		menuframe = nil
    		return -- stop any further code execution
    	end
    
    	-- you could just do menuframe = vgui.Create("DFrame"), I do it this way cos I think it looks neater.
    	local dframe = vgui.Create("DFrame")
    	dframe:SetSize(800, 400)
    	dframe:Center()
    
    	local oThink = dframe.Think -- cache the old dframe.Think
    	dframe.Think = function(self)
    		-- do stuff here
    
    		--https://******.com/Facepunch/garrysmod/blob/master/garrysmod/lua/vgui/dframe.lua#L137-L193
    		return oThink(self) -- return the old think so it runs all the shit.
    	end
    
    	menuframe = dframe 
    end
    
    hook.Add("Think", "you really should put an identifier here", function()
    	local down = input.IsButtonDown(KEY_INSERT)
    
    	if (down and !menudown)
    		ToggleMenu()
    	end
    
    	menudown = down
    end)
    Dude your freaking awesome, thank you so much!

    Is ok if i can ask you one more question?
    If so how would you make is so that when you click insert the menu opens and then you drag the menu to a certain position on your screen and then you press insert to close the menu and when you click insert again to open it the menu would be in the same place you dragged it to.
    Last edited by XviperGamingXVG; 06-11-2017 at 01:25 PM.

  4. #4
    Cyaegha's Avatar
    Join Date
    Aug 2016
    Gender
    male
    Posts
    536
    Reputation
    17
    Thanks
    526
    Use Panel:SetVisible and Panel:IsVisible instead of removing the DFrame.

  5. #5
    XviperGamingXVG's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    236
    Quote Originally Posted by Cyaegha View Post
    Use Panel:SetVisible and Panel:IsVisible instead of removing the DFrame.
    How would you do it for a dframe? Because when i switch Remove() to SetVisible() or IsVisible() it doesnt seem to work.
    Last edited by XviperGamingXVG; 06-11-2017 at 01:57 PM.

  6. #6
    bigcheatman's Avatar
    Join Date
    Jun 2017
    Gender
    female
    Posts
    1
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by XviperGamingXVG View Post
    How would you do it for a dframe?
    a dframe is a panel you dumb niBBa

  7. #7
    XviperGamingXVG's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    236
    Quote Originally Posted by bigcheatman View Post
    a dframe is a panel you dumb niBBa
    I know that, im just saying that Panel:SetVisible and Panel:IsVisible are not working.

  8. #8
    Cyaegha's Avatar
    Join Date
    Aug 2016
    Gender
    male
    Posts
    536
    Reputation
    17
    Thanks
    526
    Quote Originally Posted by XviperGamingXVG View Post
    I know that, im just saying that Panel:SetVisible and Panel:IsVisible are not working.
    Then you're doing it wrong.

  9. #9
    XviperGamingXVG's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    236
    Quote Originally Posted by Cyaegha View Post
    Then you're doing it wrong.
    I dont know what im doing wrong.
    Last edited by XviperGamingXVG; 06-11-2017 at 02:15 PM.

  10. #10
    Cyaegha's Avatar
    Join Date
    Aug 2016
    Gender
    male
    Posts
    536
    Reputation
    17
    Thanks
    526
    Quote Originally Posted by XviperGamingXVG View Post
    I dont know what im doing wrong.
    Then post what you're trying to do.

  11. #11
    XviperGamingXVG's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    236
    Quote Originally Posted by Cyaegha View Post
    Then post what you're trying to do.
    Make is so that when you click insert the menu opens and then you drag the menu to a certain position on your screen and then you press insert to close the menu and when you click insert again to open it the menu would be in the same place you dragged it to.

    Code:
    local menuframe, menudown
    
    local ToggleMenu = function()
    	if (menuframe) then
    		menuframe:SetVisible(false)
    		menuframe = nil
    		return
    	end
    
    	local dframe = vgui.Create("DFrame")
    	dframe:SetSize(800, 400)
    	dframe:Center()
    	dframe:MakePopup(true)
    	dframe:SetVisible(true)
    
    	local oThink = dframe.Think
    	dframe.Think = function(self)
    
    	local mousex = math.Clamp( gui.MouseX(), 1, ScrW() - 1 )
    		local mousey = math.Clamp( gui.MouseY(), 1, ScrH() - 1 )
    		if ( self.Dragging ) then
    			local x = mousex - self.Dragging[1]
    			local y = mousey - self.Dragging[2]
    			if ( self:GetScreenLock() ) then
    				x = math.Clamp( x, 0, ScrW() - self:GetWide() )
    				y = math.Clamp( y, 0, ScrH() - self:GetTall() )
    			end
    			self:SetPos( x, y )
    		end
    		if ( self.Hovered && self:GetDraggable() && mousey < ( self.y + 24 ) ) then
    			self:SetCursor( "arrow" )
    			return
    		end
    		self:SetCursor( "arrow" )
    		if ( self.y < 0 ) then
    			self:SetPos( self.x, 0 )
    		end
    		return oThink(self)
    	end
    	menuframe = dframe 
    end
    
    hook.Add("Think", "you really should put an identifier here", function()
    	local down = input.IsButtonDown(KEY_INSERT)
    
    	if (down and !menudown) then
    		ToggleMenu()
    	end
    
    	menudown = down
    end)
    Last edited by XviperGamingXVG; 06-11-2017 at 02:27 PM.

  12. #12
    Cyaegha's Avatar
    Join Date
    Aug 2016
    Gender
    male
    Posts
    536
    Reputation
    17
    Thanks
    526
    Use !menuframe:IsVisible() instead of false, remove menuframe = nil, and the entire point of oThink is so that you don't have to make your own dragging code.

  13. #13
    XviperGamingXVG's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    236
    Quote Originally Posted by Cyaegha View Post
    Use !menuframe:IsVisible() instead of false, remove menuframe = nil, and the entire point of oThink is so that you don't have to make your own dragging code.
    Thank you!

  14. #14
    negroid's Avatar
    Join Date
    Oct 2016
    Gender
    male
    Posts
    41
    Reputation
    10
    Thanks
    29
    Quote Originally Posted by Cyaegha View Post
    and the entire point of oThink is so that you don't have to make your own dragging code.
    but that was so much fun

Similar Threads

  1. [Help Request] Trouble with my lua derma menu!
    By XviperGamingXVG in forum Garry's Mod Discussions & Help
    Replies: 1
    Last Post: 06-24-2017, 12:37 AM
  2. [Help] Trouble with derma menu!
    By XviperGamingXVG in forum Garry's Mod Discussions & Help
    Replies: 3
    Last Post: 05-13-2017, 01:01 PM
  3. [Help Request] Trouble with derma menu!
    By XviperGamingXVG in forum Garry's Mod Discussions & Help
    Replies: 0
    Last Post: 05-02-2017, 05:58 PM
  4. Trouble with lua scripts
    By TakeTor in forum Garry's Mod Discussions & Help
    Replies: 3
    Last Post: 06-02-2013, 04:09 AM
  5. trouble with code
    By cool4345 in forum WarRock Korea Hacks
    Replies: 3
    Last Post: 05-28-2007, 11:36 AM