• Print

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

0 Members and 1 Guest are viewing this topic.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: I need help with a derma
« Reply #15 on: November 22, 2014, 08:25:48 am »
This is working for me, I just tested it
It goes in lua/autorun/
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() .. ", your health is now: " .. ply:Health() )end )
  6.         end )
  7. end
  8.  
  9. if (CLIENT) then
  10.         local midW, midH = ScrW() / 2, ScrH() / 2
  11.         local function OpenMyDerma()
  12.                 local MyDerma = vgui.Create( "DFrame" )
  13.                 MyDerma:SetSize( 250, 250 )
  14.                 MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - ( MyDerma:GetTall() / 2) )
  15.                 MyDerma:SetTitle( "Best DermaPanel EVAR" )
  16.                 MyDerma:ShowCloseButton( false )
  17.                
  18.                 local MyLabel = vgui.Create( "DLabel", MyDerma )
  19.                 MyLabel:SetPos( 90, 30 )
  20.                 MyLabel:SetSize( 180, 20 )
  21.                 MyLabel:SetText( "This is my awesome label" )
  22.                
  23.                 local MyButton = vgui.Create( "DButton", MyDerma )
  24.                 MyButton:SetText( "Click to be set on fire" )
  25.                 MyButton:SetPos( 110, 60 )
  26.                 MyButton.DoClick = function()
  27.                         net.Start( "SetHimOnFire" )
  28.                                 net.WriteEntity( LocalPlayer() )
  29.                         net.SendToServer()
  30.                         MyDerma:Close()
  31.                 end
  32.                
  33.                 MyDerma.Paint = function()
  34.                         draw.RoundedBox( 8, 0, 0, MyDerma:GetWide(), MyDerma:GetTall(), Color( 0, 153, 153, 255 ) )
  35.                 end
  36.         end
  37.         concommand.Add( "openderma", OpenMyDerma )
  38. end

Offline FunnyCop

  • Newbie
  • *
  • Posts: 7
  • Karma: 1
Re: I need help with a derma
« Reply #16 on: November 22, 2014, 08:57:01 am »
Get rid of the if (CLIENT) then and the corresponding end that comes with it.

[Edit]
The best way to use concommand.Add() is by putting it at the complete end of your script. Some times if you don't the script will need to be ran twice in order for the command to be created.
« Last Edit: November 22, 2014, 12:20:23 pm by FunnyCop »

Offline FunnyCop

  • Newbie
  • *
  • Posts: 7
  • Karma: 1
Re: I need help with a derma
« Reply #17 on: November 22, 2014, 12:44:42 pm »
Sorry for the double post, I wanted a different place to put this code.

This is what I've gotten to work and after looking at it, it is basically Zmaster's script but with
Code: Lua
  1. MyDerma:MakePopup()
Added to the frame so that you can actually press the button.

Put it inside "/garrysmod/garysmod/lua/autorun"
If you put it in "/garrysmod/garysmod/lua" and try to run it with the console it won't work.

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() .. ", your health is now: " .. ply:Health() )end )
  6.         end )
  7. end
  8.  
  9. if (CLIENT) then
  10.         local midW, midH = ScrW() / 2, ScrH() / 2
  11.         local function OpenMyDerma()
  12.                 local MyDerma = vgui.Create( "DFrame" )
  13.                         MyDerma:SetSize( 250, 250 )
  14.                         MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - ( MyDerma:GetTall() / 2) )
  15.                         MyDerma:SetTitle( "Best DermaPanel EVAR" )
  16.                         MyDerma:ShowCloseButton( false )
  17.                         MyDerma:MakePopup()
  18.  
  19.                 local MyLabel = vgui.Create( "DLabel", MyDerma )
  20.                         MyLabel:SetPos( 90, 30 )
  21.                         MyLabel:SetSize( 180, 20 )
  22.                         MyLabel:SetText( "This is my awesome label" )
  23.  
  24.                 local MyButton = vgui.Create( "DButton", MyDerma )
  25.                         MyButton:SetText( "Click to be set on fire" )
  26.                         MyButton:SetPos( 110, 60 )
  27.                         MyButton.DoClick = function()
  28.                                 net.Start( "SetHimOnFire" )
  29.                                 net.WriteEntity( LocalPlayer() )
  30.                                 net.SendToServer()
  31.                                 MyDerma:Close()
  32.                         end
  33.  
  34.                         MyDerma.Paint = function()
  35.                                 draw.RoundedBox( 8, 0, 0, MyDerma:GetWide(), MyDerma:GetTall(), Color( 0, 153, 153, 255 ) )
  36.                         end
  37.         end
  38. concommand.Add( "openderma", OpenMyDerma )
  39. end
« Last Edit: November 22, 2014, 12:47:08 pm by FunnyCop »

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #18 on: November 22, 2014, 02:10:51 pm »
All is good now! the only thing is i need to know how to make a command that opens it with ULX like !openderma and it opens that and how would i stitch the kill to give a weapon like a physgun/m9k knife m9k_knife is the name for the knife so if you could help me with that that would be AWESOME!!! thx!

Offline FunnyCop

  • Newbie
  • *
  • Posts: 7
  • Karma: 1
Re: I need help with a derma
« Reply #19 on: November 22, 2014, 07:49:39 pm »
Why would you want a chat command for it when console commands are much simpler?

I can't help you with chat commands but I guess it would look something like this:

Code: Lua
  1. hook.Add( "PlayerSay", "openmyderma", function( ply, text, public )
  2.         text = string.lower( text )
  3.         if ( string.sub( text, 1, 10 ) == "!openderma" ) then
  4.                 RunConsoleCommand( "openderma" )
  5.         end
  6. end )

Start using the wiki instead of the ulx forum for lua help, it will get work done a lot faster.
http://wiki.garrysmod.com/

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: I need help with a derma
« Reply #20 on: November 22, 2014, 11:20:54 pm »
ULX command sorta kinda tutorial.
See [NEW STUFF] section in first post.
/index.php/topic,4464.0.html#msg17838

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #21 on: November 23, 2014, 11:19:58 am »
When i use the command

Ply:Give( "m9k_knife" )

it gives me the error....

[ERROR] addons/the derma/lua/autorun/sh.lua:54: attempt to call method 'Give' (a nil value)
  1. DoClick - addons/the derma/lua/autorun/sh.lua:54
   2. unknown - lua/vgui/dlabel.lua:206



Please help me!

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: I need help with a derma
« Reply #22 on: November 23, 2014, 02:36:06 pm »
Can you show your code that gives that error please

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #23 on: November 23, 2014, 03:46:06 pm »
the thing thats causing it is the ply:Give( "m9k_knife" ) Does that just not work on darkRP???

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: I need help with a derma
« Reply #24 on: November 23, 2014, 05:12:42 pm »
According to the creator of M9K:
"This addon was not made for TTT or DarkRP. Sorry guys."

You would have to edit it to work with DarkRP

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #25 on: November 23, 2014, 05:23:14 pm »
ok well i will try with darkrp weapons

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #26 on: November 23, 2014, 05:29:36 pm »
This is the error


[ERROR] addons/the derma/lua/autorun/sh.lua:22: attempt to call method 'Give' (a nil value)
  1. DoClick - addons/the derma/lua/autorun/sh.lua:22
   2. unknown - lua/vgui/dlabel.lua:206

This is the code the part that did it is under  the RunColsoleCommand( "kill" )

Code: Lua
  1. if (CLIENT) then
  2.         local midW, midH = ScrW() / 2, ScrH() / 2
  3.         local function OpenMyDerma()
  4.                 local MyDerma = vgui.Create( "DFrame" )
  5.                         MyDerma:SetSize( 300, 300 )
  6.                         MyDerma:SetPos( midW - ( MyDerma:GetWide() / 2 ), midH - ( MyDerma:GetTall() / 2) )
  7.                         MyDerma:SetTitle( "Server commands" )
  8.                         MyDerma:ShowCloseButton( false )
  9.                         MyDerma:MakePopup()
  10.  
  11.                 local MyLabel = vgui.Create( "DLabel", MyDerma )
  12.                         MyLabel:SetPos( 20, 35 )
  13.                         MyLabel:SetSize( 180, 20 )
  14.                         MyLabel:SetText( "• To kill" )
  15.  
  16.                 local MyButton = vgui.Create( "DButton", MyDerma )
  17.                         MyButton:SetText( "Click Here" )
  18.                         MyButton:SetPos( 20, 60 )
  19.                         MyButton.DoClick = function()
  20.                         RunConsoleCommand( "kill" )
  21.                         local ply = LocalPlayer()
  22.                         ply:Give( "weapon_ak47custom" )
  23.                         end
  24.                                 local MyLabel2 = vgui.Create( "DLabel", MyDerma )
  25.                                         MyLabel2:SetPos( 20, 80 )
  26.                                         MyLabel2:SetSize( 180, 20)
  27.                                         MyLabel2:SetText( "• To See Your Current Weapon" )
  28.                                
  29.                                 local MyButton2 = vgui.Create( "DButton", MyDerma )
  30.                                 MyButton2:SetText( "Click Here" )
  31.                                 MyButton2:SetPos( 20,100 )
  32.                                 MyButton2.DoClick = function()
  33.                                 local ply = LocalPlayer()
  34. chat.AddText( Color( 100, 100, 255 ), ply, ", you are holding ", Color( 100, 255, 100 ), ply:GetActiveWeapon():GetClass() )
  35.                                 end    
  36.                                
  37.                                         local MyLabel3 = vgui.Create( "DLabel" , MyDerma )
  38.                                         MyLabel3:SetPos( 20, 120 )
  39.                                         MyLabel3:SetSize( 180, 20 )
  40.                                         MyLabel3:SetText( "• To see your health and armor" )
  41.                                         local MyButton3 = vgui.Create( "DButton", MyDerma )
  42.                                         MyButton3:SetText( "Click Here" )
  43.                                         MyButton3:SetPos( 20, 140 )
  44.                                         MyButton3.DoClick = function()
  45.                                         local ply = LocalPlayer()
  46.                                         chat.AddText( Color( 100, 100, 255 ), ply, ", your health is at ", Color( 100, 255, 100 ), ply:Health() .. " and your armor is at ", Color(100, 255, 100), ply:Armor() )
  47.                                         end
  48.                                        
  49.                                                 local MyButton3 = vgui.Create( "DButton", MyDerma )
  50.                                                 MyButton3:SetPos( 125, 270 )
  51.                                                 MyButton3:SetText( "Close" )
  52.                                                 MyButton3.DoClick = function()
  53.                                                 local ply = LocalPlayer()
  54. chat.AddText( Color( 100, 100, 255 ), ply, ", you have closed the panel" )
  55.                                                 local ply = LocalPlayer()
  56.                                                 --ply:Give( "m9k_knife" )
  57.                                                 MyDerma:Close()
  58.                                                 end
  59.                                
  60.                         MyDerma.Paint = function()
  61.                                 draw.RoundedBox( 8, 0, 0, MyDerma:GetWide(), MyDerma:GetTall(), Color( 255, 50, 50, 255 ) )
  62.                         end
  63.         end
  64. concommand.Add( "opencommand", OpenMyDerma )
  65. end

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: I need help with a derma
« Reply #27 on: November 24, 2014, 04:25:02 am »
Oh
Also, ply:Give() is server side code
Create another networkmessage that gives the player the weapon

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: I need help with a derma
« Reply #28 on: November 24, 2014, 01:03:09 pm »
So what would i do in the

if (SERVER) then

end

???

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: I need help with a derma
« Reply #29 on: November 24, 2014, 01:37:53 pm »
create another network message
util.AddNetworkString()
When the button is clicked on your drama panel, start the message and send the server your LocalPlayer()

Receive the message on server side, then do what you did with the ply:Ignite() but without the timer and replace ignite with give

  • Print