Problem with visual information script i am making

hello, i return to present to you enougher script that failed in the making. I am making a script that when you do a cmd, then you put your text, say mahcmd “lololol” , it would print to the screenz of all “ADMIN: lololol” . so far, that fails cause when i do mahcmd “lololol” it prints to the middle of my screen "ADMIN: nil "

here is the script so far:

function advertising( pl, args )
if pl:IsPlayer() && pl:IsAdmin() then
		PrintMessage( HUD_PRINTCENTER, "ADMIN: " ..tostring(args[1]) )

concommand.Add( "advertisment", advertising)

any ideas?

function advertising( pl, cmd, args )
	if pl:IsPlayer() and pl:IsAdmin() then
		PrintMessage( HUD_PRINTCENTER, "ADMIN: " ..tostring(args[1]))
concommand.Add( "advertisment", advertising)

concommand.Add callbacks take 3 arguments, ply, cmd, arg.

can you explaon the cmd arg to me, i never really understood it, but if you dont want to, can you please point me in the right dierction?

First of all you have to put all the parameters of the function in, you can’t skip any. So it would be
local function adversising(pl, cmd, args).
However if that were the only problem then you’d get a different error, from trying to index a string. Are you sure you’re giving us all the errors you got.
Are you testing this script by doing advertisment lolol in the console or is it through a chat command. If it’s through a chat command then I’d have to know more about the mechanism before I could help you.


cmd is just the name of the console command used, in your case it would always be advertisment, however it is required to be included because parameters need to be in order.

its a concommand and it works now, but can you explain to me what the cmd argument does?


edit, nvm, the guy aboce me explained

He told you. It’s the name of the command.

so i could do

if cmd = “advertisment” then
blah blah

so i could protect my scripts or something?

There wouldn’t be much of a point as the function is likely only called from that console command. You could supply the same function to multiple commands, in which case the cmd argument could be different, however with standard usage this parameter is never used.
If you feel like it you could try this
[lua]for i=65, 90 do
concommand.Add(sting.char(i), print)
Then enter A-Z in the console.
It will print the player, then the letter you entered, then the table of parameters.