Is it possible to create a console command which takes arguments? I would like to modify the following script with it so that the command can change who speaks and what they say.
[lua] [/lua]
function imnoob (player) -- creates function
player:ConCommand("say I'm a noob") -- says I'm a noob
end
concommand.Add("inoob", imnoob)
Script:
[lua]concommand.Add("Blahblah", function(ply, cmd, args)
local Name = args[1] or "(No Name)"
print(Name..", is a noob.")
end)[/lua]
Output:
[code]] Blahblah cow
cow, is a noob.
] Blahblah
(No Name), is a noob.[/code]If you type a name it prints that name with ", is a noob." on it. If you don't enter a name then it'll use "(No Name)" for the name.
I think he wants to make a serverside console command to make players say "I'm a noob". In that case:
[lua]concommand.Add( "SayNoob", function( ply, com, args )
if ( !args[1] ) then return end
for _, pl in pairs( player.GetAll() ) do
if ( string.find( pl:Nick(), args[1] ) ) then
pl:ConCommand( "say I'm a noob!" )
return
end
end
end )[/lua]
Usage:
[code]SayNoob cow[/code]
Ok. I guess that I am making a lot of threads :D
Btw what does the "for _" mean?
and waht does the "!" do before "args[1]"
After this I guess I should stop filling up the forums :)
[QUOTE=sintwins;19535540]Ok. I guess that I am making a lot of threads :D
Btw what does the "for _" mean?
and waht does the "!" do before "args[1]"
After this I guess I should stop filling up the forums :)[/QUOTE]
It would be "for key, value", but I replaced key with _, because I'm not using that. The ! means "not", e.g.:
[lua]x = true
if ( !x ) then
print( "x is false!" )
else
print( "x is true!" )
end[/lua]
Ah so you don't need the key so u just put "_" instead of "k"?
And the if "( !args[1] )" means if there isn't a first argument?
You can name the key whatever you want. Coders use "_" because you would never use a variable called "_". You could say "for borscht, soup in pairs( russia ) do".
And yes. ! <something> will be true if <something> is false or nil. Nil means it doesn't exist, and if they don't supply an argument then it doesn't exist.
Sorry, you need to Log In to post a reply to this thread.