hello, i am back, and i need to ask how i would make a chat comand that would pick up arguments and stuff, the only reason i am posting here is that the example on the wiki doesnt work for me and i dont know alot todo with chat.
thanks in advance
hello, i am back, and i need to ask how i would make a chat comand that would pick up arguments and stuff, the only reason i am posting here is that the example on the wiki doesnt work for me and i dont know alot todo with chat.
thanks in advance
Can you give us an example that you want to do?
well i want to do it when someone says !slap meisno it does the command admin_slap meisno , meisno being an argument and stoof like that
In the PlayerSay hook search for the letters (!ban as an example) and then call the concommand with a prefix for it.
Say if you had a funciton called BanNoob() and added it as a concommand with the name “BanANoob” then if you found !ban you would run that concommand.
I would post my code but I believe it was you who moaned it was too messy or something so I wont bother.
[lua]local chatcommands = {
[“kill”] = function(pl,args)
pl:Kill()
end,
[“print”] = function(pl,args)
pl:ChatPrint(table.concat(args))
end,
}
local prefix = “/”
hook.Add(“PlayerSay”,“Chatcommands”,function(pl,text,toall)
local args = string.Explode(" ",text)
local cmd = string.Right(args[1],string.len(args[1]) - 1)
if string.Left(args[1]) == prefix and chatcommands[cmd] then
table.remove(args,1)
chatcommandscmd
end
end)[/lua]
Here’s a pretty easy way of doing it. Dunno if it works, but you get the idea. There’s probably a more efficient way of doing the strings.
[lua]
module( “chatcommand”, package.seeall )
local Commands = {}
function Add( name, func )
Commands[ name ] = func
end
function Call( name, pl, args )
local func = Commands[ name ]
if (func) then
local b, res = pcall( func, pl, name, args )
if (!b) then
Commands[ name ] = nil
ErrorNoHalt( res )
return false
end
return true
end
end
function FindPlayer( name )
for _, ply in pairs( player.GetAll() ) do
if (string.find( ply:Nick(), name ) || (name == ply:Nick())) then return ply end
end
end
local function PlayerSay( ply, text, toall)
local first = string.sub( text, 1, 1 )
if (first == "/") then
local str = string.sub( text, 2 )
local args = string.Explode( " ", str )
local com = args[1]
table.remove( args, 1 )
local b = Call( com, ply, args )
if (b) then return "" end
end
end
hook.Add( “PlayerSay”, “CHATCOMMANDS”, PlayerSay )
[/lua]
To use it:
[lua]
require(“chatcommand”)
chatcommand.Add(“help”, function(ply)
ply:ChatPrint(“How to play blah blah blah…”)
end)
[/lua]
Then ingame type: “/help” for that function to run.
where does your module go irzilla? does it go into lua / someplace/ includes?
You can put that module anywhere as long as you include it.
Or you can put it in: lua/includes/modules/ for it to get included automaticly.
do i need a complete restart of mah server? of a map change ( or reload )
[editline]03:24PM[/editline]
it doesnt work can someone make a simple lua function thats like chatcommand.add( command , function fallback ) ? because irzilla’s doesnt work
You need to tell us what you’ve tried and what exactly did not work.
well i placed the module irzilla in lua/includes/modules and i put the function he provided and linked it to my function but it gave me the error it couldnt find the module even though i had restart and everything but i dunno
Kid, commonsense is needed.
We can’t tell what the heck you’re saying.
ok, you know IRZilla gave me a module , well i put it in lua/includes/modules and i hooked up the example he gave me to my function and i tried to make it work and everything but iit gave me the error that it couldnt find the module . anyway, if i do a check if someone is admin, then i try to run the command in the rcon, it gives me an error, how do i make a command rcon compatible?
Dude its not normal… I French and I can spell better than you…