[IMG]http://cloud.dloaded.com/i/53ccffa59f8fa.png[/IMG]
[B]Welcome to the PTDNT page ![/B]
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 !
[B]To keep it clean[/B]
-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)
[B]Reminder[/B]
-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.
[URL="http://wiki.garrysmod.com/page/Main_Page"]Official wiki[/URL] / [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4875.html"]Maurits.tv[/URL] / [URL="http://samuelmaddock.github.io/glua-docs/"]GLua Docs[/URL] / [URL="http://gmodwiki.net/Main_Page"]Gmod Wiki[/URL] / [URL="https://github.com/garrynewman/garrysmod/tree/master/garrysmod/lua/vgui"]VGUI[/URL]
[B]Previous Thread[/B] : [url]http://facepunch.com/showthread.php?t=1348923[/url]
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.
[code]
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()
[/code]
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: [url]https://github.com/garrynewman/garrysmod/tree/master/garrysmod/lua/vgui[/url]
But I didn't know what I was looking for.
There aren't any console errors.
[IMG]http://i.imgur.com/kTATj8Q.png[/IMG]
@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
-[URL="http://wiki.garrysmod.com/page/GM/PlayerHurt"]-PlayerHurthook[/URL]
[QUOTE=sm69baller;45454540]@glasspopcorn
-snip-
[URL="http://wiki.garrysmod.com/page/GM/PlayerHurt"]-PlayerHurthook[/URL][/QUOTE]
I tried something like that yesterday and it didn't work...
Thank you.
[QUOTE=glasspopcorn;45454567]I tried something like that yesterday and it didn't work...
Thank you.[/QUOTE]
Does it work now ? And how do you open the panel are you making adventage of usermessages ?
[QUOTE=sm69baller;45454574]Does it work now ? And how do you open the panel are you making adventage of usermessages ?[/QUOTE]
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
[QUOTE=glasspopcorn;45454604]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[/QUOTE]
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.
[code]
function GM:PlayerDeath( victim, attacker )
[/code]
I do call it later on, I use PlayerDeath.Attacker and PlayerDeath.Victim.
Alright, thanks guys. All of that stuff works.
I'm getting this error after making a derma button.
I've been looking right here: [url]http://wiki.garrysmod.com/page/VGUI/Elements/DButton[/url]
And I can't seem to find anything wrong.
[code]
[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
[/code]
[code]
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
[/code]
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.
[code]
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
[/code]
[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:
[code]
mainFunction()
hook.Add("PlayerDeath", "RDM Checker", mainFunction)
[/code]
That's my hook, right?
This is how my functions are nested:
mainFunction
DrawEntireDermaPanel
In the middle of the program (DrawEntireDermaPanel) I have
[code]
//This is in a DLabel
wereKilled:SetText(PlayerDeath.Victim .. " died")
[/code]
This is my function mainFunction:
[code]
function mainFunction( victim, attacker )
[/code]
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)?
[QUOTE=glasspopcorn;45454800]I don't even know how I didn't see it.
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:
[code]
mainFunction()
hook.Add("PlayerDeath", "RDM Checker", mainFunction)
[/code]
That's my hook, right?
This is how my functions are nested:
mainFunction
DrawEntireDermaPanel
In the middle of the program (DrawEntireDermaPanel) I have
[code]
//This is in a DLabel
wereKilled:SetText(PlayerDeath.Victim .. " died")
[/code]
This is my function mainFunction:
[code]
function mainFunction( victim, attacker )
[/code]
[/QUOTE]
Are you calling that hook on the server or the client? Its a [URL="http://wiki.garrysmod.com/page/GM/PlayerDeath"]server side hook[/URL] 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-
[QUOTE=glasspopcorn;45455160]What would I do?
I'm running this with lua_openscript_cl because the Derma stuff is client side.[/QUOTE]
Depends on what your trying to do.
If you want it to popup when the player dies you can use a [URL="http://wiki.garrysmod.com/page/Category:net"]net message[/URL](or [URL="http://wiki.garrysmod.com/page/Category:umsg"]usermessage[/URL]) 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]
[QUOTE=TheEmp;45455573]Depends on what your trying to do.
If you want it to popup when the player dies you can use a [URL="http://wiki.garrysmod.com/page/Category:net"]net message[/URL](or [URL="http://wiki.garrysmod.com/page/Category:umsg"]usermessage[/URL]) 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][/QUOTE]
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?:
[CODE]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 [/CODE]
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?
[QUOTE=glasspopcorn;45455662]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.[/QUOTE]
If SERVER doesn't mean that just the server will get it. It means that any code you run inside that will be called on the server sphere and since the PlayerDeath hook is server side the only place you can call it is on the server. Thats why we have net/messages. You can use either to send a message to the player that was killed opening your RDM menu.
See if [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]this[/URL] guide on using net messages helps.
Edit:
[QUOTE=Skate;45455714]How can I close this with a button?:
[CODE]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 [/CODE]
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?[/QUOTE]
Not sure if this is what you want but you can always use [URL="http://wiki.garrysmod.com/page/hook/Remove"]hook.Remove[/URL] to remove that hudpaint hook when the menu closes.
Skate, you can do Panel:Remove()
Panel would be replaced with your panel name.
[QUOTE=Skate;45455714]How can I close this with a button?:
[CODE]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 [/CODE]
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?[/QUOTE]
I'm not a fan of adding/removing hooks very often, but if that's how you choose to do it, remove the hook with
[lua]hook.Remove("HUDPaint", "OriginCam")[/lua]
[QUOTE=TheEmp;45455743]If SERVER doesn't mean that just the server will get it. It means that any code you run inside that will be called on the server sphere and since the PlayerDeath hook is server side the only place you can call it is on the server. Thats why we have net/messages. You can use either to send a message to the player that was killed opening your RDM menu.
See if [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]this[/URL] guide on using net messages helps. [/QUOTE]
Where do I put the .lua file?
Btw this is how it's nested:
[code]
if (SERVER) then
hook.Add("PlayerDeath", "deathaddon", mainFunction)
else
function mainFunction( victim, attacker )
function DrawDermaPanel()
derma stuff goes here
end
DrawDermaPanel()
end
mainFunction()
end
[/code]
Alright I put it in the server autorun but the Derma panel doesn't show up
[lua]if (SERVER) then
util.AddNetworkString( "RDMPopUp" )
function mainFunction( victim, attacker )
if IsValid(attacker) and attacker:IsPlayer() then
net.Start("RDMPopUp")
net.WriteString(attacker:Name())
net.Send(victim)
end
end
hook.Add("PlayerDeath", "deathaddon", mainFunction)
else
net.Receive("RDMPopUp", function(l,c)
local Killer = net.ReadString()
--Rest of your derma code here--
end)
end[/lua]
Not sure how complete the syntax of that will be, I'm on my phone and it can be difficult to code on that. :P
[QUOTE=TheEmp;45455960][lua]if (SERVER) then
util.AddNetworkString( "RDMPopUp" )
function mainFunction( victim, attacker )
if IsValid(attacker) and attacker:IsPlayer() then
net.Start("RDMPopUp")
net.WriteString(attacker:Name())
net.Send(victim)
end
end
hook.Add("PlayerDeath", "deathaddon", mainFunction)
else
net.Receive("RDMPopUp", function(l,c)
local Killer = net.ReadString()
--Rest of your derma code here--
end)
end[/lua]
Not sure how complete the syntax of that will be, I'm on my phone and it can be difficult to code on that. :P[/QUOTE]
Thanks, man.
I wrote everything out and it should work, I just don't have anyone to test it with.
[QUOTE=glasspopcorn;45455865]Where do I put the .lua file?
Btw this is how it's nested:
[code]
if (SERVER) then
hook.Add("PlayerDeath", "deathaddon", mainFunction)
else
function mainFunction( victim, attacker )
function DrawDermaPanel()
derma stuff goes here
end
DrawDermaPanel()
end
mainFunction()
end
[/code][/QUOTE]
You might want to make your own gamemode instead of loading them into the root lua files. [URL="https://www.youtube.com/playlist?list=PLoc3UuPmH6DknS66yYDcGh5S09IAEyLtx"]These [/URL]videos will explain you how to make your own gamemode.
I think you also have a little problem with hooks so once again
What a hook does is , It basicly tells the function when to run something the function parameters(arguments i'd like to call them) could be used in the function cause the hook is Hooked to the function
I'm making a simple map voting script, could someone tell me why the startvote function doesn't get called even though the timer hits 0?
[code]--Global Variables
defaultTime = 0.1
mapList = file.Read("maplist.txt", "DATA")
timeLeft = defaultTime * 60
--Timer
timer.Create("VoteTimer", 1, timeLeft, function() timeLeft = timeLeft - 1 print(timeLeft) end)
timer.Start("VoteTimer")
if(timeLeft == 0) then
StartVote()
end
function StartVote()
mapListTable = string.Explode(" ", mapList)
PrintTable(mapListTable)
print("End")
end[/code]
Because you're only checking timeLeft once, when the file is loaded.
Either put it in your timer, or just call StartVote() with a timer like this:
[lua]timer.Create( "VoteTimer", timeLeft, 1, function() StartVote() end )[/lua]
So it'll call the function after the time is over, which is much easier.
Also, you don't need to timer.Start() after creating a timer, it starts automatically.
[QUOTE=sm69baller;45456075]You might want to make your own gamemode instead of loading them into the root lua files. [URL="https://www.youtube.com/playlist?list=PLoc3UuPmH6DknS66yYDcGh5S09IAEyLtx"]These [/URL]videos will explain you how to make your own gamemode.
I think you also have a little problem with hooks so once again
What a hook does is , It basicly tells the function when to run something the function parameters(arguments i'd like to call them) could be used in the function cause the hook is Hooked to the function[/QUOTE]
I'm making a script though, I want to use it on my DarkRP server.
[QUOTE=glasspopcorn;45456973]I'm making a script though, I want to use it on my DarkRP server.[/QUOTE]
I Find that these tutorials are additional info to this page : [url]http://www.lua.org/manual/5.1/manual.html[/url]
Sorry, you need to Log In to post a reply to this thread.