Problems That Don't Need Their Own Thread v2.0

http://cloud.dloaded.com/i/53ccffa59f8fa.png

Welcome to the PTDNT page !
Have a small problem and need help with it , but you don’t want to start a new
thread and ask about your problem then you’ve came to the right thread !

To keep it clean
-Post your problem (“Variable returns nil at some point”).
-Post the code that you think is necessary to solve this problem.
-Post the error that you are getting ("[ERROR] gamemodes/skeleton/gamemode/client/hud.lua:70").
-In Game pictures (when it comes to clientside).
-Wrap code tags around your code f.e[LUA]draw.RoundedBox(0, 0, 0, ScrW(), ScrH(), Color(35, 40, 44, 255))[/LUA]
[LUA] Your Code [!/LUA] (without explanation mark [!] ofc ; D)
-Don’t spam your problem (when you don’t get any response, it means that other people are not familliar with your problem)

Reminder
-Don’t come here with “Leaked Gamemode scripts”, Aslong as the code is a public or a script of your own it is accepted
-You might want to check the wiki’s first before asking a question that has already been responded to.
Official wiki / Maurits.tv / GLua Docs / Gmod Wiki / VGUI

Previous Thread : http://forum.facepunch.com/showthread.php?t=1348923

Perhaps you could include the wiki links too.

Also, people should look at the VGUI source code on github before asking basic questions about elements.

I have some issues with derma.




Msg(HUD_PRINTTALK, "started")

function loadPanel()
	local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself
	DermaPanel:SetPos( 289,300 ) -- Position on the players screen
	DermaPanel:SetSize( 450, 250 ) -- Size of the frame
	DermaPanel:SetTitle( "title" ) -- Title of the frame
	DermaPanel:SetVisible( true )
	DermaPanel:SetDraggable( true ) -- Draggable by mouse?
	DermaPanel:ShowCloseButton( true ) -- Show the close button?
	DermaPanel:MakePopup() -- Show the frame
end

function loadText()
	local wereKilled = vgui.Create("DLabel", DermaPanel)
	wereKilled:SetPos(35,35)
	wereKilled:SetColor(Color(255,255,255,255))
	wereKilled:SetFont("default")
	wereKilled:SetText("textline1")
	wereKilled:SizeToContents()

	local wasIt = vgui.Create("DLabel", DermaPanel)
	wasIt:SetPos(55,55) 
	wasIt:SetColor(Color(255,255,255,255))
	wasIt:SetFont("default")
	wasIt:SetText("textline2")
	wasIt:SizeToContents()
end

local DermaPanel = nil
loadText()
loadPanel()


This works pretty good and all except for the fact that the text displays under the box ingame. The text also doesn’t move with the box.

I looked here: https://github.com/garrynewman/garrysmod/tree/master/garrysmod/lua/vgui
But I didn’t know what I was looking for.

There aren’t any console errors.

@glasspopcorn

[LUA]function DrawEntireDermaPanel()
local DermaPanel = vgui.Create( “DFrame” ) – Creates the frame itself
DermaPanel:SetPos( 289,300 ) – Position on the players screen
DermaPanel:SetSize( 450, 250 ) – Size of the frame
DermaPanel:SetTitle( “title” ) – Title of the frame
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true ) – Draggable by mouse?
DermaPanel:ShowCloseButton( true ) – Show the close button?
DermaPanel:MakePopup() – Show the frame

local wereKilled = vgui.Create("DLabel", DermaPanel)
wereKilled:SetPos(35,35)
wereKilled:SetColor(Color(255,255,255,255))
wereKilled:SetFont("default")
wereKilled:SetText("textline1")
wereKilled:SizeToContents()

local wasIt = vgui.Create("DLabel", DermaPanel)
wasIt:SetPos(55,55) 
wasIt:SetColor(Color(255,255,255,255))
wasIt:SetFont("default")
wasIt:SetText("textline2")
wasIt:SizeToContents()

//The 2 labels had never heard about DermaPanel because it was a local element it should work now
//And i guess that you are trying to make something like this "You where killed by "..attacker.."" i would recommend sending the players attacker and victim via this serverside hook (PlayerHurt)

end[/LUA]

Code says it all
--PlayerHurthook

I tried something like that yesterday and it didn’t work…
Thank you.

Does it work now ? And how do you open the panel are you making adventage of usermessages ?

It works, but I’m getting an error (I added some code).
[ERROR] lua/testin.lua:5: attempt to index global ‘GM’ (a nil value)

  1. unknown - lua/testin.lua:5

Show us where the error is? I can’t see GM anywhere in your code.

EDIT: I guess you’re trying to do GM:PlayerDeath?
Do hook.Add( “PlayerDeath”, “uniqueName”, function ) instead

All I have that contains GM is this, and it’s right before the DrawEntireDermaPanel function.



function GM:PlayerDeath( victim, attacker )


I do call it later on, I use PlayerDeath.Attacker and PlayerDeath.Victim.

yeah well the issue is you are using GM so stop using it and use hook.Add like suggested.

Alright, thanks guys. All of that stuff works.
I’m getting this error after making a derma button.

I’ve been looking right here: http://wiki.garrysmod.com/page/VGUI/Elements/DButton
And I can’t seem to find anything wrong.



[ERROR] lua/testin.lua:34: bad argument #1 to 'SetSize' (Panel expected, got number)
  1. SetSize - [C]:-1
   2. DrawEntireDermaPanel - lua/testin.lua:34
    3. mainFunction - lua/testin.lua:60
     4. unknown - lua/testin.lua:65




		local yesWas = vgui.Create( "DButton" )
		yesWas:SetParent( DermaPanel )
		yesWas.SetSize( 180, 100 )
		yesWas.SetVisible( true )
		yesWas:SetText( "Yes" )
		yesWas:SetPos( 15, 150 )
		yesWas.DoClick = function()
			MSG(HUD_PRINTTALK, "Yes")
		end

		local noWas = vgui.Create( "DButton" )
		noWas:SetParent( DermaPanel )
		noWas:SetSize( 180, 100 )
		noWas:SetVisible( true )
		noWas:SetText( "No" )
		noWas:SetPos( 15, 200 )
		noWas.DoClick = function()
			MSG(HUD_PRINTTALK, "No")
		end


yesWas.SetSize should be yesWas:SetSize

Same with yesWas.SetVisible.

I don’t even know how I didn’t see it.
I seriously just started at it for 10 minutes.



		local yesWas = vgui.Create( "DButton" )
		yesWas:SetParent( DermaPanel )
		yesWas:SetParent( DermaPanel )
		yesWas:SetText( "Yes" )
		yesWas:SetPos( 30, 150 )
		yesWas:SetSize( 180, 100 )
		yesWas.DoClick = function()
			MSG(HUD_PRINTTALK, "Yes")
		end

		local noWas = vgui.Create( "DButton" )
		noWas:SetParent( DermaPanel )
		noWas:SetText( "No" )
		noWas:SetPos( 210, 150 )
		noWas:SetSize( 180, 100 )
		noWas.DoClick = function()
			MSG(HUD_PRINTTALK, "No")
		end


[editline]21st July 2014[/editline]

This has nothing to do with above.

[ERROR] lua/testin.lua:22: attempt to index global ‘PlayerDeath’ (a nil value)

  1. DrawEntireDermaPanel - lua/testin.lua:22
  2. mainFunction - lua/testin.lua:51
    3. unknown - lua/testin.lua:54

I don’t understand why I’m getting this error.
At the end of the script I have this:



mainFunction()
hook.Add("PlayerDeath", "RDM Checker", mainFunction)


That’s my hook, right?
This is how my functions are nested:
mainFunction
DrawEntireDermaPanel
In the middle of the program (DrawEntireDermaPanel) I have



                //This is in a DLabel
		wereKilled:SetText(PlayerDeath.Victim .. " died")


This is my function mainFunction:



function mainFunction( victim, attacker )


Also just a side question:
How would I make it where other people can use my script?
Another question:
What would I need to do to put a script on a coderhire (I’m not going to upload one yet, I’m new to lua so yea)?

Are you calling that hook on the server or the client? Its a server side hook only so calling it on the client would produce that error.

What would I do?
I’m running this with lua_openscript_cl because the Derma stuff is client side.

-snip-

Depends on what your trying to do.
If you want it to popup when the player dies you can use a net message(or usermessage) sending it to the player who was killed. Depending on what you use you’ll need to tweak your popup so it reads the name of the killer(you’ll have to send this in the message you use to open the menu).

To make it so your script load without you having to use lua_run, place it in lua/autorun. Then add some checks to your script to see if its on the server or client.
Like this:
[lua] if (SERVER) then
– Put your player death hook here–

else
–the client side derma stuff goes here–
end

[/lua]

I don’t understand, though.
If (SERVER)- so if I was running it on my server, everyone would get the death hook.
If (SERVER) is false everyone will get the derma stuff.

I need the player death hook and the derma stuff to be together… I don’t get it.

The server script is supposed to work for everyone.

How can I close this with a button?:


local richselect = vgui.Create( "DButton" )   -- Create a button displaying a position on the map
richselect:SetParent( LifeFrame )            
richselect:SetText( "" )             
richselect:SetPos( 100, 300 )                 
richselect:SetSize( 140, 20 )  
richselect.DoClick = function()
	GetRenderTarget( "OriginCam", 64, 64, true ) 

	local function OriginCam()
	local CamData = {}
	CamData.angles = Angle(17.46, -46.54, 0.00)
	CamData.origin = Vector(-2822.26,-5089.96,350.49)
	CamData.x = 0
	CamData.y = 0
	CamData.w = ScrW() / 3
	CamData.h = ScrH() / 3
	render.RenderView( CamData )
end
hook.Add("HUDPaint", "OriginCam", OriginCam)
end 

It draws a camera at the top left of the screen but now I want to remove it when a user clicks a button but I have no idea how?