Make a derma skin

I’m trying to make a simple little popup menu that will run some commands.

function godon()
player.GetByID( 1 ):GodEnable()

function godoff()
player.GetByID( 1 ):GodDisable()

function smg_ammo()
player.GetByID( 1 ):GiveAmmo(5, “SMG1_Grenade”)

concommand.Add(“godon”, godon)
concommand.Add(“godoff”, godoff)
concommand.Add(“rifle_grenade”, smg_ammo)

I’ve already got that working, but now I need to know how to make a derma skin with corresponding buttons. The script that I currently have is in the server folder, and I know that derma can only be run on the client, so it needs to be put in the client folder.

function useful_menu()
local frame1 = vgui.Create(“DFrame”)

    frame1:SetTitle("Ivan's Useful Menu")

local button = vgui.Create(“DButton”, frame1);
button:SetSize(100, 30);
button:SetPos(50, 30);
button:SetText(“5 SMG Grenades”);
button.DoClick = function (button)

Is this derma correct? If so, where do I put it to make it work?


I got the derma working, and it pops up with the button on it, but whenever I click on it it gives an error.

autorun/client/panel.lua:14: attempt to call global 'smg_ammo' (a nil value)

How do I use a button to call a function server-side? (or call any server-side function from the client for that matter)

you have to use console commands

Or he can read the tutorials and find out the difference between server & client instances?


-snip wrong thread -

I understand the concept of client/server/shared, but I don’t understand how the client and server tell each other to do stuff. I know that the functions GodEnable(), GodDisable() and GiveAmmo() are server only. But how would the client tell the server to invoke those functions?

Apply a concommand on the server to them using:

And then on the client use: to call them.

So then it’s the server’s responsibility to make sure that the client is allowed to run the command?

Of course otherwise the client will be able to exploit loads of crap.

Ok, I’ve got all three commands working with a nice little gui to boot.

The problem is that it will only work for player 1, not the player that types the command. How would you get the ID of the player that uses the command?

Concommands by default return a number of things, the first being the player that entered it, the second being the name of the command, the third being the arguments passed to the command.

So, for example, in your ammo function, you could have

function smg_ammo(ply, command, arguments)
local amount = arguments[1] – The first value in the arguments
ply:GiveAmmo(amount, ‘SMG1_Grenade’)

So if you were to do rifle_grenade 10, you’d get 10 smg grenades.

If you want to incorporate this into your HUD, look up DNumSlider on the wiki.

How would you find the player that ran the command. (I don’t want people to be able to turn god mode on and off on other people, just themselves)

ply is the player that runs the command. It won’t get turned on for anybody else.

Oh, so that’s what it means. I kept seeing it over and over but I never knew what it meant.

ply and pl are 2 commonly used names used to abbreviate player.

But never use “player” to define it as it’s already a table: