can anyone tell me if it is possible to modify the !help cmd of ptokax
QuoteOriginally posted by kunal
can anyone tell me if it is possible to modify the !help cmd of ptokax
Nop...unless u create a script with the cmd "!help" that can display a customized help.
This is my try...and its just an example
Bot = "yourbotname"
prefix = "!"
function Main()
frmHub:RegBot(Bot)
end
function ChatArrival(user, data)
data=string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find( data, "%b<>%s+(%S+)" )
if cmd == prefix.."help" then
SendToAll(Bot,"-------Help thing-----")
SendToAll(Bot,"!help - Displays the help cmds")
SendToAll(Bot,"-------End------------")
end
end
end
Cheers...
gd1
Well done markitos, but this :
if( string.sub(data, 1, 1) == "<" ) then
is not needed.
QuoteOriginally posted by Dessamator
Well done markitos, but this :
if( string.sub(data, 1, 1) == "<" ) then
is not needed.
Why?
Delete:
if( string.sub(data, 1, 1) == "<" ) then
and last
end
and work. C ya
QuoteOriginally posted by Markitos
QuoteOriginally posted by Dessamator
Well done markitos, but this :
if( string.sub(data, 1, 1) == "<" ) then
is not needed.
Why?
Well, because it was something used in the old ptokax to parse the arrivals manually, now there are split arrivals that do that, so its no longer needed . That was the equivilant of "Chatarrival"
I tried to modify the structure of the script and i get this error "new 1.lua:14: <eof> expected near `end'"
Bot = "Help"
function Main()
frmHub:RegBot(Bot)
end
function ChatArrival(user, data)
data=string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data, "%b<>%s+%!(%S+)")
if cmd and tCmds[cmd] then
return tCmds[cmd](user,data),1
end
end
end
end
ToArrival = ChatArrival
tCmds = {
["help"] =
function(user,data)
if user.sName then
user:SendToAll(Bot,"\r\n"..string.rep("---",150))
end
end
}
Help would be appreciated...
Bot = "Help"
function Main()
frmHub:RegBot(Bot)
end
function ChatArrival(user, data)
data = string.sub ( data, 1, -2 ) -- watch this tip ;)
local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
if cmd and tCmds[cmd] then
return tCmds[cmd](user,data),1
end
end
end
ToArrival = ChatArrival
tCmds = {
["help"] =
function ( user, data )
if user.sName then
user:SendToAll(Bot,"\r\n"..string.rep("---",150))
end
end
}
Try this ;)
Quote from: Herodes on 06 March, 2006, 20:07:35
Bot = "Help"
function Main()
frmHub:RegBot(Bot)
end
function ChatArrival(user, data)
data = string.sub ( data, 1, -2 ) -- watch this tip ;)
local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
if cmd and tCmds[cmd] then
return tCmds[cmd](user,data),1
end
end
end
ToArrival = ChatArrival
tCmds = {
["help"] =
function ( user, data )
if user.sName then
user:SendToAll(Bot,"\r\n"..string.rep("---",150))
end
end
}
Try this ;)
do it more like:
Bot = "Help"
function Main()
frmHub:RegBot(Bot)
end
function ChatArrival(user, data)
data = string.sub ( data, 1, -2 ) -- watch this tip ;)
local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
if cmd and tCmds[cmd] then
return tCmds[cmd](user,data),1
end
end
ToArrival = ChatArrival
tCmds = {
["help"] =
function ( user, data )
if user.sName then
user:SendToAll(Bot,"\r\n"..string.rep("---",150))
end
end
}
Quote from: Troubadour on 06 March, 2006, 20:18:26
do it more like:
function ChatArrival(user, data)
data = string.sub ( data, 1, -2 ) -- watch this tip ;)
local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
if cmd and tCmds[cmd] then
return tCmds[cmd](user,data),1
end
end
now that's bad tabbing ;)
Quote from: Mutor on 06 March, 2006, 22:37:32
You shouold only tab at control structures.
function ChatArrival(user, data)
data = string.sub ( data, 1, -2 ) -- watch this tip ;)
local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
if cmd and tCmds[cmd] then
return tCmds[cmd](user,data),1
end
end
Another question, why are tCmds a global var? Better to include that table in the function as a local.
I didnt understand ur point mutor. Could show me an example??
Quote from: Herodes on 06 March, 2006, 20:23:14
Quote from: Troubadour on 06 March, 2006, 20:18:26
do it more like:
function ChatArrival(user, data)
data = string.sub ( data, 1, -2 ) -- watch this tip ;)
local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
if cmd and tCmds[cmd] then
return tCmds[cmd](user,data),1
end
end
now that's bad tabbing ;)
yep, it looks nicer like this ;)
Sidenote: sometimes global variables are the only way, do not be afraid of them, they can be your friend. Sometimes you have to balance whether to use global or local. You have to review some code to get the point.
thanks all ;D
Quote from: bastya_elvtars on 07 March, 2006, 18:30:28
Sidenote: sometimes global variables are the only way, do not be afraid of them, they can be your friend. Sometimes you have to balance whether to use global or local. You have to review some code to get the point.
Is there a difference in bandwith usage in global or local variables or is it to few to mention?
Quote from: Troubadour on 07 March, 2006, 22:28:29
Quote from: bastya_elvtars on 07 March, 2006, 18:30:28
Sidenote: sometimes global variables are the only way, do not be afraid of them, they can be your friend. Sometimes you have to balance whether to use global or local. You have to review some code to get the point.
Is there a difference in bandwith usage in global or local variables or is it to few to mention?
No badnwirdth talk on this matter. ..
It is generally speaking stack ( memory ) issues [size, namespace-cleaness].
lol ... why so much discussion ... ? I think its the easiest thing a script can do ...
Bot = frmHub:GetHubBotName()
prefix = "!"
function ChatArrival(user,data)
data = string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data,"%s+(%S+)")
if (cmd == prefix.."help")
user:SendData(Bot,"\r\n\r\n\t-------H-e-L-P-------\r\n\r\n"..
"\t - Help thingie 1\r\n"..
"\t - Help thingie 2\r\n"..
"\t - Help thingie 3\r\n\r\n"..
"\t-------H-e-L-P-------\r\n")
return 1
end
end
What can be more easy than that? ;D
Quote from: Mutor on 10 June, 2006, 22:32:03
Quote from: Znupi on 10 June, 2006, 21:55:42
lol ... why so much discussion ... ? I think its the easiest thing a script can do ...
What can be more easy than that? ;D
What could be easier? Doing just that only better
- You're missing a 'then' on line 7
- This statement data = string.sub(data,1,string.len(data)-1) is meaningless
- Your string.find is weak
- You're using global vars when they should be local
- Should anyone care this script blocks the inbuilt help, drop the retun 1 to not do this
By 'How To" what's really intended here is 'How To Do It Well'.
Consider what's being said before sharing your amusement and broken code.
indeed a good point Mutor ..
Sorry :(
I think that string.sub thing is a matter of personal preference, and the criticism itself should be constructive - for instance instead of saying 'weak' one should say: 'dude, you ought to think of special characters that may confuse pattern matching' - even though the manner in which it has been posted is a bit annoying.