• Print

Author Topic: I need help with a derma  (Read 15190 times)

0 Members and 1 Guest are viewing this topic.

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
I need help with a derma
« on: November 20, 2014, 01:57:25 pm »
So far im just making the frame and the command but its not working ;( please someone help!!!

Code: Lua
  1. if (SERVER) then
  2.  
  3. end
  4.  
  5. if (CLIENT) then
  6.         local midx, midH = ScrW() / 2, ScrH() / 2
  7.         local function OpenMyDerma()
  8.                 local MyDerma = vgui.Create( "DFrame" )
  9.                 MyDerma:SetSize(250, 250)
  10.                 MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall
  11.                 () / 2) )
  12.                 MyDerma:SetTitle( "Best Derma EVER" )
  13.                
  14.                 local MyLabel = vgui.Create( "DLabel", MyDerma
  15.                 MyLabel:SetPos( 175, 20 )
  16.                 MyLabel:SetText( "This is my awesome label" )
  17.        
  18.                 local MyButton = vgui.Create( "DButton", MyDerma )
  19.                 MyButton:SetText:( "Click to die" )
  20.                 MyButton:SetPos( 90, 60 )
  21.                 MyButton.DoClick = function()
  22.                         RunConsoleCommand( "kill" )
  23.                 end
  24.         end
  25.         concommand.Add( "openmyderma", OpenMyDerma )
  26. end
  27.  

Thanks in advance!!!

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: I need help with a derma
« Reply #1 on: November 20, 2014, 03:26:09 pm »
What's the error you get

Edit:
Nevermind, I see it
On line 14 of the code you posted here, you're missing a ) at the end of the line
It should read
local MyLabel = vgui.Create( "DLabel", MyDerma )
but you have
local MyLabel = vgui.Create( "DLabel", MyDerma

Edit2:
You're also missing some things on line 10, give me a second to fix it
Working line (untested): MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() )
« Last Edit: November 20, 2014, 03:28:43 pm by Zmaster »

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #2 on: November 20, 2014, 04:48:38 pm »
For somereason its not workign can you please test it? maybe its just me? idk

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: I need help with a derma
« Reply #3 on: November 20, 2014, 05:01:19 pm »
what's the error you're getting

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #4 on: November 20, 2014, 05:34:31 pm »
Im gonna get off for now but im be on tomorrow so please watch this thred ;( thanks!

Offline FunnyCop

  • Newbie
  • *
  • Posts: 7
  • Karma: 1
Re: I need help with a derma
« Reply #5 on: November 20, 2014, 07:33:36 pm »
After Zmaster's edits these are the things you need to correct.

Remove the "local" in line 7
Code: Lua
  1. function OpenMyDerma()

Zmaster's correction for line 10 is incorrect, the code on line 11 needs to be on line 10
Code: Lua
  1. MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )

You also have a nil value "midW" on line 10 and probably should be "midx" instead
Code: Lua
  1. MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )

Like Zmaster said, line 14 should be
Code: Lua
  1. local MyLabel = vgui.Create( "DLabel", MyDerma )

There was a ":" on line 18 that isn't supposed to be there.
Code: Lua
  1. MyButton:SetText( "Click to die" )

The corrected script should be

Code: Lua
  1. if (SERVER) then
  2.  
  3. end
  4.  
  5. if (CLIENT) then
  6.         local midx, midH = ScrW() / 2, ScrH() / 2
  7.         function OpenMyDerma()
  8.                 local MyDerma = vgui.Create( "DFrame" )
  9.                 MyDerma:SetSize(250, 250)
  10.                 MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
  11.                 MyDerma:SetTitle( "Best Derma EVER" )
  12.  
  13.                 local MyLabel = vgui.Create( "DLabel", MyDerma )
  14.                 MyLabel:SetPos( 175, 20 )
  15.                 MyLabel:SetText( "This is my awesome label" )
  16.  
  17.                 local MyButton = vgui.Create( "DButton", MyDerma )
  18.                 MyButton:SetText( "Click to die" )
  19.                 MyButton:SetPos( 90, 60 )
  20.                 MyButton.DoClick = function()
  21.                         RunConsoleCommand( "kill" )
  22.                 end
  23.         end
  24.         concommand.Add( "openmyderma", OpenMyDerma )
  25. end

Now that your code is able to be ran there are some things that need to be added in order for the GUI to be used.

Add this below line 11
Code: Lua
  1. MyDerma:SetVisible( true )
  2. MyDerma:MakePopup()

Without that you can't click the button you have.

The final code should be

Code: Lua
  1. if (SERVER) then
  2.  
  3. end
  4.  
  5. if (CLIENT) then
  6.         local midx, midH = ScrW() / 2, ScrH() / 2
  7.         function OpenMyDerma()
  8.                 local MyDerma = vgui.Create( "DFrame" )
  9.                 MyDerma:SetSize(250, 250)
  10.                 MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
  11.                 MyDerma:SetTitle( "Best Derma EVER" )
  12.                 MyDerma:SetVisible( true )
  13.                 MyDerma:MakePopup()
  14.  
  15.                 local MyLabel = vgui.Create( "DLabel", MyDerma )
  16.                 MyLabel:SetPos( 175, 20 )
  17.                 MyLabel:SetText( "This is my awesome label" )
  18.  
  19.                 local MyButton = vgui.Create( "DButton", MyDerma )
  20.                 MyButton:SetText( "Click to die" )
  21.                 MyButton:SetPos( 90, 60 )
  22.                 MyButton.DoClick = function()
  23.                         RunConsoleCommand( "kill" )
  24.                 end
  25.         end
  26.         concommand.Add( "openmyderma", OpenMyDerma )
  27. end
« Last Edit: November 20, 2014, 08:08:15 pm by FunnyCop »

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #6 on: November 21, 2014, 03:42:23 am »
Thank you so much!!! I will try that out!!!

Please keep watch on this tho just incase!!!

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: I need help with a derma
« Reply #7 on: November 21, 2014, 05:52:01 am »
I thought that this was true by default so you don't have to use it?
MyDerma:SetVisible( true )

Offline FunnyCop

  • Newbie
  • *
  • Posts: 7
  • Karma: 1
Re: I need help with a derma
« Reply #8 on: November 21, 2014, 12:24:04 pm »
You're right, it is set by default but I had LMM add it as a precautionary measure in case something he/she adds causes a problem with the frame popping up.

Also you can remove

Code: Lua
  1. if (SERVER) then
  2.  
  3. end

And

Code: Lua
  1. if (CLIENT) then
  2.  
  3. end

It will add "openmyderma" as a concommand on the server itself instead of making it be just a client-side command. This way if you end up putting a script like this on your server the clients won't have to have the script installed.
« Last Edit: November 21, 2014, 12:43:09 pm by FunnyCop »

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #9 on: November 21, 2014, 02:17:08 pm »
I dont know why but it wont come up?!? it says unknown command but there are no errors?!? its annoying!!! please help!!!!!!!!!!!!

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #10 on: November 21, 2014, 04:30:56 pm »
This is the error that i get...

[ERROR] addons/mynewderm/lua/autorun/sh.lua:22: '<eof>' expeted near 'end'
1. unknown - addons/mynewderm/lua/autorun/sh.lua:0

Offline FunnyCop

  • Newbie
  • *
  • Posts: 7
  • Karma: 1
Re: I need help with a derma
« Reply #11 on: November 21, 2014, 04:34:20 pm »
Don't put it in your addons folder.

If you're running a dedicated server put it in
/gmod/garrysmod/lua/autorun

If you're running a listen server (by pressing start new game) put it in
/garrysmod/garysmod/lua/autorun

If you're just using your game client put it in
/garrysmod/garysmod/lua

This script is just a script, not an addon. I ran it without any issues.

[Edit]
I attached the lua file I edited and ran without issues.

Code: Lua
  1. local midx, midH = ScrW() / 2, ScrH() / 2
  2.         function OpenMyDerma()
  3.                 local MyDerma = vgui.Create( "DFrame" )
  4.                 MyDerma:SetSize(250, 250)
  5.                 MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
  6.                 MyDerma:SetTitle( "Best Derma EVER" )
  7.                 MyDerma:SetVisible( true )
  8.                 MyDerma:MakePopup()
  9.  
  10.                 local MyLabel = vgui.Create( "DLabel", MyDerma )
  11.                 MyLabel:SetPos( 175, 20 )
  12.                 MyLabel:SetText( "This is my awesome label" )
  13.  
  14.                 local MyButton = vgui.Create( "DButton", MyDerma )
  15.                 MyButton:SetText( "Click to die" )
  16.                 MyButton:SetPos( 90, 60 )
  17.                 MyButton.DoClick = function()
  18.                         RunConsoleCommand( "kill" )
  19.                 end
  20.         end
  21. concommand.Add( "openmyderma", OpenMyDerma )
« Last Edit: November 21, 2014, 05:12:36 pm by FunnyCop »

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #12 on: November 22, 2014, 07:10:43 am »
I put it in the right folder and its not working!!!

Do i type openmyderma in the console because thats what im doing and its not working!!!!!

no errors just says unknown command

This is the code....

Code: Lua
  1. local midx, midH = ScrW() / 2, ScrH() / 2
  2.         function OpenMyDerma()
  3.                 local MyDerma = vgui.Create( "DFrame" )
  4.                 MyDerma:SetSize(250, 250)
  5.                 MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
  6.                 MyDerma:SetTitle( "Best Derma EVER" )
  7.                 MyDerma:SetVisible( true )
  8.                 MyDerma:MakePopup()
  9.  
  10.                 local MyLabel = vgui.Create( "DLabel", MyDerma )
  11.                 MyLabel:SetPos( 175, 20 )
  12.                 MyLabel:SetText( "This is my awesome label" )
  13.  
  14.                 local MyButton = vgui.Create( "DButton", MyDerma )
  15.                 MyButton:SetText( "Click to die" )
  16.                 MyButton:SetPos( 90, 60 )
  17.                 MyButton.DoClick = function()
  18.                         RunConsoleCommand( "kill" )
  19.                 end
  20.         end
  21. concommand.Add( "openmyderma", OpenMyDerma )


Thanks

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #13 on: November 22, 2014, 07:12:56 am »
Wait no i got it! thanks for everything!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #14 on: November 22, 2014, 07:42:33 am »
This is what im trying to do! ill post the code and my error!

https://www.youtube.com/watch?v=V6lVSFjAlVg&index=32&list=PLn-akFzjAR18zF2hQO_Wlz-fqWqfp9w8B

Code: Lua
  1. if (SERVER) then
  2.         util.AddNetworkString( "SetHimOnFire" )
  3.         net.Receive( "SetHimOnFire", function( len, ply )
  4.                 ply:Ignite( 5, 5 )
  5.                 timer.Simple( 5.2, function() Printmessage( HUD_PRINTTALK, ply:Name
  6.                 () .. ", your health is now: " .. ply:Health() )end )
  7.         end )
  8. end
  9.                
  10. if (CLIENT) then
  11.         local midx, midH = ScrW() / 2, ScrH() / 2
  12.         function OpenMyDerma()
  13.                 local MyDerma = vgui.Create( "DFrame" )
  14.                 MyDerma:SetSize(250, 250)
  15.                 MyDerma:SetPos( midx - ( MyDerma:GetWide() / 2 ), midH - (MyDerma:GetTall() / 2) )
  16.                 MyDerma:SetTitle( "Starlight DarkRP" )
  17.                 MyDerma:SetVisible( true )
  18.                 MyDerma:MakePopup()
  19.  
  20.                 local MyLabel = vgui.Create( "DLabel", MyDerma )
  21.                 MyLabel:SetPos( 90, 30 )
  22.                 MyLabel:SetSize( 150, 20 )
  23.                 MyLabel:SetText( "Server console" )
  24.                 MyDerma:ShowCloseButton( false )
  25.                
  26.                 local MyButton = vgui.Create( "DButton", MyDerma )
  27.                 MyButton:SetText( "Click to die" )
  28.                 MyButton:SetPos( 90, 60 )
  29.                 MyButton.DoClick = function()
  30.                         net.Start( "SetHimOnFire" )
  31.                                 net.WriteEntity( LocalPlayer() )
  32.                         net.SendToServer()
  33.                 end
  34.         end
  35. concommand.Add( "openmyderma", OpenMyDerma )
  36. end

My error says:


[ERROR] lua/autorun/sh.lua:6: ambiguous syntax (function call x new statement) near '('
  1. unknown - lua/autorun/sh.lua:0

i dont understand whats wrong?!?!?!?? HELP!!!!

  • Print