• Death Messages
    9 replies, posted
Hi, I've got this Dpanel that pops ups when you die, [code] function DrawDeathMessage() local DeathMessages = { "You have died, you forget everything that happened in the past.", "1. You may not return to your death postion for 10 minutes.", "2. You may not return to ask for your stuff back.", "3. You may not return to get your car back.", "By clicking accept, you agree to the NLR rule.", } local LDFrame = vgui.Create( "DFrame" ) LDFrame:SetPos( ScrW() / 2 - 250,ScrH() / 2 ) LDFrame:SetSize( 512, 128 ) LDFrame:SetTitle( "New Life Rule - NLR" ) LDFrame:SetVisible( true ) LDFrame:SetDraggable( true ) LDFrame:ShowCloseButton( false ) LDFrame:SetBackgroundBlur( true ) LDFrame:MakePopup() local PaintPanel = vgui.Create( "DPanel", LDFrame ) PaintPanel:SetPos( 5, 25 ) PaintPanel:SetSize( 490, 90 ) PaintPanel.Paint = function() surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, PaintPanel:GetWide(), PaintPanel:GetTall() ) --PaintPanel:SetCursor("hand"); end local Dlabel = vgui.Create("DLabel", PaintPanel); Dlabel:SetText(#DeathMessages); Dlabel:SetSize(490, 30); Dlabel:SetPos(10, 20); local OKButton = vgui.Create("DButton", PaintPanel); OKButton:SetText("Accept"); OKButton:SetSize(100, 30); OKButton:SetPos(10, 50); OKButton.DoClick = function() LDFrame:Close() RunConsoleCommand("dmspawn") end end --[[local OKButton = vgui.Create("DButton", PaintPanel); OKButton:SetText("Disaccept"); OKutton:SetSize(100, 30); OKButton:SetPos(10, 100); OKButton.DoClick = function() LDFrame:Close() RunConsoleCommand("disconnect") end--]] concommand.Add("DrawDeathMsg", DrawDeathMessage)[/code] But when I die only this pops up [img]https://steamuserimages-a.akamaihd.net/ugc/851594103035005324/125D9F91C8F414C7382C99603D3F85F5F048126C/[/img] Can someone help me on how to get all messages displayed?
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DLabel/SetText]DLabel:SetText[/url] takes a string as text, whereas [B]DeathMessages[/B] is a table. But what you supplied is [B]#DeathMessages[/B], which returns the amount of items in the table. Change [lua]local DeathMessages = { "You have died, you forget everything that happened in the past.", "1. You may not return to your death postion for 10 minutes.", "2. You may not return to ask for your stuff back.", "3. You may not return to get your car back.", "By clicking accept, you agree to the NLR rule.", }[/lua] to [lua]local DeathMessages = [[You have died, you forget everything that happened in the past. 1. You may not return to your death postion for 10 minutes. 2. You may not return to ask for your stuff back. 3. You may not return to get your car back." By clicking accept, you agree to the NLR rule.]][/lua] And change [B]#DeathMessages[/B] to [B]DeathMessages[/B] Also: You should probably make your function [URL="https://www.lua.org/pil/4.2.html"]local[/URL]
Alright, all the messages display right now. How do I make another button, I've tried Ctrl + c > ctrl + v but that doesn't seem to work
[QUOTE=HassanCohmdan;52434915]How do I make another button, I've tried Ctrl + c > ctrl + v but that doesn't seem to work[/QUOTE] Well... that's pretty much how it's done. What happens when you do that?
[code] [ERROR] gamemodes/darkrp/gamemode/modules/deathmsgs/cl_deathmsgs.lua:49: attempt to index global 'LDFrame' (a nil value) 1. DoClick - gamemodes/darkrp/gamemode/modules/deathmsgs/cl_deathmsgs.lua:49 2. unknown - lua/vgui/dlabel.lua:232 [/code]
[QUOTE=HassanCohmdan;52434925][code] [ERROR] gamemodes/darkrp/gamemode/modules/deathmsgs/cl_deathmsgs.lua:49: attempt to index global 'LDFrame' (a nil value) 1. DoClick - gamemodes/darkrp/gamemode/modules/deathmsgs/cl_deathmsgs.lua:49 2. unknown - lua/vgui/dlabel.lua:232 [/code][/QUOTE] What's the full code?
[code]function DrawDeathMessage() local DeathMessages = [[You have died, you forget everything that happened in the past. 1. You may not return to your death postion for 10 minutes. 2. You may not return to ask for your stuff back. 3. You may not return to get your car back." By clicking accept, you agree to the NLR rule.]] local LDFrame = vgui.Create( "DFrame" ) LDFrame:SetPos( ScrW() / 2 - 250,ScrH() / 2 ) LDFrame:SetSize( 512, 160 ) LDFrame:SetTitle( "New Life Rule - NLR" ) LDFrame:SetVisible( true ) LDFrame:SetDraggable( false ) LDFrame:ShowCloseButton( false ) LDFrame:SetBackgroundBlur( true ) LDFrame:MakePopup() local PaintPanel = vgui.Create( "DPanel", LDFrame ) PaintPanel:SetPos( 5, 25 ) PaintPanel:SetSize( 490, 120 ) PaintPanel.Paint = function() surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, PaintPanel:GetWide(), PaintPanel:GetTall() ) --PaintPanel:SetCursor("hand"); end local Dlabel = vgui.Create("DLabel", PaintPanel); Dlabel:SetText(DeathMessages); Dlabel:SetSize(490, 70); Dlabel:SetPos(10, 20); local OKButton = vgui.Create("DButton", PaintPanel); OKButton:SetText("Accept"); OKButton:SetSize(100, 30); OKButton:SetPos(10, 88); OKButton.DoClick = function() LDFrame:Close() RunConsoleCommand("dmspawn") end end local OKButton = vgui.Create("DButton", PaintPanel); OKButton:SetText("Accept"); OKButton:SetSize(100, 30); OKButton:SetPos(60, 88); OKButton.DoClick = function() LDFrame:Close() RunConsoleCommand("dmspawn") end end concommand.Add("DrawDeathMsg", DrawDeathMessage)[/code]
You'er definining the second button outside of the function
[QUOTE=HassanCohmdan;52434929][code]function DrawDeathMessage() local DeathMessages = [[You have died, you forget everything that happened in the past. 1. You may not return to your death postion for 10 minutes. 2. You may not return to ask for your stuff back. 3. You may not return to get your car back." By clicking accept, you agree to the NLR rule.]] local LDFrame = vgui.Create( "DFrame" ) LDFrame:SetPos( ScrW() / 2 - 250,ScrH() / 2 ) LDFrame:SetSize( 512, 160 ) LDFrame:SetTitle( "New Life Rule - NLR" ) LDFrame:SetVisible( true ) LDFrame:SetDraggable( false ) LDFrame:ShowCloseButton( false ) LDFrame:SetBackgroundBlur( true ) LDFrame:MakePopup() local PaintPanel = vgui.Create( "DPanel", LDFrame ) PaintPanel:SetPos( 5, 25 ) PaintPanel:SetSize( 490, 120 ) PaintPanel.Paint = function() surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, PaintPanel:GetWide(), PaintPanel:GetTall() ) --PaintPanel:SetCursor("hand"); end local Dlabel = vgui.Create("DLabel", PaintPanel); Dlabel:SetText(DeathMessages); Dlabel:SetSize(490, 70); Dlabel:SetPos(10, 20); local OKButton = vgui.Create("DButton", PaintPanel); OKButton:SetText("Accept"); OKButton:SetSize(100, 30); OKButton:SetPos(10, 88); OKButton.DoClick = function() LDFrame:Close() RunConsoleCommand("dmspawn") end end local OKButton = vgui.Create("DButton", PaintPanel); OKButton:SetText("Accept"); OKButton:SetSize(100, 30); OKButton:SetPos(60, 88); OKButton.DoClick = function() LDFrame:Close() RunConsoleCommand("dmspawn") end end concommand.Add("DrawDeathMsg", DrawDeathMessage)[/code][/QUOTE] I don't think he's closing the function off completely?
Solved, Thanks Jason
Sorry, you need to Log In to post a reply to this thread.