Hi,
I would try make a own script that can greet.
This is the first version:
-- Simple Greet BOT
-- Made: 25-9-2005
-- Version: 1.0
bot = "[BOT]Nieuwslezer"
prefix = "+"
PM = 1 -- Send message also by PM or only MAIN chat? 1 = on, 0 = off.
cmd1 = "morning"
cmd2 = "reboot"
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 cmd == (prefix..cmd1) then
SendToAll(bot,""..user.sName.." wishes everyone a good morning")
return 1
elseif
cmd and cmd == (prefix..cmd2) then
SendToAll(bot,"\r\n\r\n'The hub wil close in some minutes,\t it will be online a few minutes later'\r\n")
if PM == "1" then
SendPmToAll(bot,"\r\n\r\n'The hub wil close in some minutes,\t it will be online a few minutes later'\r\n")
end
return 1
end
end
But if I add more options there will be a lot of "elseif"
So I want make this in a table.
this is the result :
-- Simple Greet BOT
-- Made: 5-10-2005
-- version: 1.1
--
--
--
-- Commands:
-- !morning - Wish people a good morning
--
-- VARIABLES --
sBot = "[BOT]Nieuwslezer" -- name of the bot.
sPrefix = "!"; -- Command Prefix
--
-- END --
function Main()
frmHub:RegBot(sBot);
end
function ChatArrival(curUser, data)
local data = string.sub(data,-1)
local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd then
local tCmds = {
["morning"] = function(user,data)
local s,e,arg = string.find(data,"%b<>%s+(%S+)")
if not arg then
SendToAll(sbot,""..user.sName.." wishes everyone a good morning")
return 1
end
end,
}
if tCmds[cmd] then
return tCmds[cmd](curUser, data)
end
end
end
But it won't work......
Can anybody say whate I do wrong??
In you script I read
sPrefix = "!"; -- Command Prefix
but you not use it in you ChatArrival function. Why?
here's a nice and small standard template, easy to build on..
added option for multi prefix also
Typhoon?
-- Simple Greet BOT
-- Made: 5-10-2005
-- version: 1.1
-- Quickie template by Typhoon? , easy to add commands this way and still keep a very readable script
-- Commands:
-- !showip -- shows the victims ip
-- VARIABLES --
tSetup = {
sBot = "[BOT]Nieuwslezer", -- name of the bot.
sPrefix = {
["-"] = 1,
["+"] = 1,
["/"] = 1,
["!"] = 1,
},
}
-- END --
-- globale table for commands
local tCmds = {}
function Main()
frmHub:RegBot(tSetup.sBot)
end
function ChatArrival(user,data)
local _,_,Arg = string.find(data, "%b<>%s+(.*)%|")
local _,_,prefix,cmd,arg = string.find(Arg, "(%S)(%S+)%s*(.*)")
if prefix and cmd and tSetup.sPrefix[prefix] then
if tCmds[string.lower(cmd)] then
return tCmds[string.lower(cmd)](user,arg,data)
else
user:SendData(tSetup.sBot, "*** Command don't exist!")
return 1
end
end
end
-- commands table
tCmds["showip"] = function(user,Arg,data)
local s,e,Name = string.find(Arg, "(.+)" )
local victim = GetItemByName(Name)
if victim ~= nil then
user:SendData(tSetup.sBot, "The user "..victim.sName.." has the IP: "..victim.sIP)
else
user:SendData(tSetup.sBot,"*** No such nick in the userlist !! ***")
end
return 1
end
Very good Typ very nice script :)
Thnx a lot !!! you all :D
This is what i need !!!!