Client running a server function.

I have a derma window in place…simple little derma window with a dbutton. When the player clicks said button, it will assign a networked string to the player, and give them weapons. However, the giving the weapons part here is the issue. I tried putting it in a shared.lua file in my gamemode, to where it looked similar to this:



if CLIENT then
  //derma that calls function
end
if SERVER then
  // the aactual function
end


However the client still can’t call that function. I tried a console command, no go. I am trying to avoid using datastream here, as, to me, it seems a bit impractical to use datastream to call a single function…things as elemental as this shouldn’t be so difficult in GMod :v:

Use console commands to call a serverside function

A shared file does not run in the same instance serverside and clientside.

The only way to call a serverside function from the client is through console commands.

How might I add arguments to console commands?


function AConCommand(ply , cmd , args)
	print("Argument 1 was "..args[1])
end
concommand.Add("MyConCommand" , AConCommand)

You can also use datastream. :eng101:

Edit:

Woops I didn’t read the thread. :frowning:

Thanks for that.

I needed it for a class system for a gamemode. A friend of mine has just recently picked up Lua. He was trying to make a teams and class system. Teams worked great, classes not so much. Basically, when the player clicks the button, it will give you the weapons associated with that class.

for this code:



function AConCommand(ply , cmd , args)
	print("Argument 1 was "..args[1])
end
concommand.Add("MyConCommand" , AConCommand)


in console, I would type “MyConCommand ‘print me’” correct?

I never messed with console commands that much :v:

If you type “MyConCommand LAWLALWLALW” it will say.
Argument 1 was LAWLALWlALW

-snip- Ninja’d.