PtokaX forum

Development Section => Your Developing Problems => Topic started by: lynyrd on 23 February, 2004, 14:55:44

Title: mainchat command
Post by: lynyrd on 23 February, 2004, 14:55:44
hi im trying to learn lua
i hope this is the right place to write..
i would like to know how i get a bot to recieve a command thru mainchat instead of a pm
i really tried to but failed so please help a noob =)

i beleive it's the "$To: i have to change??

code:
------------------------------------------------------------------------
function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then  
data=strsub(data,1,strlen(data)-1)  
s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")  
if (whoTo == botname) then
if nick[user.sName] ~= nil then
nick[user.sName] = nil
SaveToFile(user.sName,fname,nick)
PmToAStupidTablesGrrrButIAmStartingToLikeThemLOL(msg,from,user.sName)
nick[user.sName]=user.sName
SaveToFile(user.sName,fname,nick)
else
user:SendPM(botname,"Du har inte tilltr?de till detta rum!!!")
end
end
end
end
------------------------------------------------------------------------
Title:
Post by: RobinHood on 23 February, 2004, 15:05:29
Try this :-)

code:

function DataArrival(user,data)
   if (strsub(data, 1, 1) == "<") then
      data = strsub(data,1,strlen(data)-1)
      s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s(.*)")
      if (arg==nil) then
         s,e,cmd = strfind(data, "%b<>%s+(%S+)%s*")
      end
      if (cmd=="!command") then
         SendToAll(botname, "test")
      end
   end
end
Title:
Post by: lynyrd on 23 February, 2004, 15:30:30
thanks robin hood im starting to get somewhere =)
i did this

code:
------------------------------------------------------------------------
function DataArrival(user,data)
if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s(.*)")
if (arg==nil) then
s,e,cmd = strfind(data, "%b<>%s+(%S+)%s*")
end
if (cmd=="!itchat") then
user:SendPM(botname, "hi this is the it-chat room.begin chat now")
end
end
end
------------------------------------------------------------------------
end of code..

im trying to get the vipchat made by piglja the script godess =))
to popup in pm by a main command but now i can't get it to work...any ideas why?
and another thing the command is visible to all i would like it not to show others in mainchat
Title:
Post by: lynyrd on 23 February, 2004, 16:50:10
now i tried a different way..
but it still not works
is it close or way off?
please give me a little help

code:
------------------------------------------------------------------------
function DataArrival(user, data)
if (strsub(data, 1, 1) == "<") then
data=strsub(data,1,strlen(data)-1)  
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s(.*)")
if (cmd=="!itchat") then
if (whoTo == botname) then
if nick[user.sName] ~= nil then
nick[user.sName] = nil
SaveToFile(user.sName,fname,nick)
PmToAStupidTablesGrrrButIAmStartingToLikeThemLOL(msg,from,user.sName)
nick[user.sName]=user.sName
SaveToFile(user.sName,fname,nick)
return 1
else
user:SendPM(botname,"Du har inte tilltr?de till detta rum!!!")
end
end
end
------------------------------------------------------------------------
Title:
Post by: lynyrd on 24 February, 2004, 23:47:00
ok i give up on that one...i've tried alot of ways but no..
but not giving up.
got another idea =) how do i call a bot from this script?
it is a noob cut n paste job
code:
------------------------------------------------------------------------
Bot = "chatcontrol"
chatbotname = "ITGR" --the bot im trying to call

function Main()
   frmHub:UnregBot(botname)
   
end

function DataArrival(user,data)
if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s(.*)")
if (arg==nil) then
s,e,cmd = strfind(data, "%b<>%s+(%S+)%s*")
end
if (cmd=="+it") then
user:SendPM(chatbotname,"test")
end
end
end
------------------------------------------------------------------------
my problem is that i have different intrest groups on my hub.so i made them chatrooms so they can chat privately..it's about 4 of those chatrooms..i dont want them to show in the list,and unreg them is a bad idea since no one can acsess them then. so i try to make a script so that you only need to type a command in main to acsess the chatroom..please please help me out
Title:
Post by: lynyrd on 26 February, 2004, 21:25:58
Hi after much headake and bad language i got a bit further.dispite my limited knowledge in both english and lua =)

code:
------------------------------------------------------------------------
BotName = "Chatkontroll"

Bot1 = "FFGR"

Bot2 = "ITGR"

cmd1 = "+ff"

cmd2 = "+it"

function Main()
frmHub:UnregBot(BotName)
end

function DataArrival(user,data)
if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s(.*)")
if (arg==nil) then
s,e,cmd = strfind(data, "%b<>%s+(%S+)%s*")
end
if cmd == cmd1 then
user:SendPM(Bot1,"Hi this is the FFGR-ChatRoom...")
return 1
elseif cmd == cmd2 then
user:SendPM(Bot2,"hi this is the ITGR-chatroom...")
end
end
end
------------------------------------------------------------------------
end of code

now my only problems is that when i unreg the chat rooms they go offline. can any nice scripter give me a little hint?
and one more thing..how do i make the command invisible to others in mainchat? so they dont see "!ff"
have a nice day =)
Title:
Post by: Stravides on 27 February, 2004, 01:18:31
QuoteOriginally posted by lynyrd
Hi after much headake and bad language i got a bit further.dispite my limited knowledge in both english and lua =)

------------------------------------------------------------------------
BotName = "Chatkontroll"

Bot1 = "FFGR"
Bot2 = "ITGR"
cmd1 = "!ff" -- decide on your prefix
cmd2 = "!it" -- double dash enables you to put a comment in..

function Main()
frmHub:UnregBot(BotName)   -- This Unregisters the bot u sure u want to do this ?
-- frmHub:RegBot(BotName) -- is the opposite, but is not active as there is a -- in front of it.
end

function DataArrival(user,data)
if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s(.*)")
if (arg==nil) then
s,e,cmd = strfind(data, "%b<>%s+(%S+)%s*")
end
if cmd == cmd1 then
user:SendPM(Bot1,"Hi this is the FFGR-ChatRoom...")
return 1
elseif cmd == cmd2 then
user:SendPM(Bot2,"hi this is the ITGR-chatroom...")
return 1 -- this means dont show it
end
end
end
------------------------------------------------------------------------
now my only problems is that when i unreg the chat rooms they go offline. can any nice scripter give me a little hint?
and one more thing..how do i make the command invisible to others in mainchat? so they dont see "!ff"
have a nice day =)

They see !ff as you are using command +ff, change it as above...
also try to indent your code ie after an If or While indent, then close it as you end or else them, makes debugging easier too..
The return 1 will not show the command, but you must use the correct prefix (! or +)
Title:
Post by: lynyrd on 27 February, 2004, 02:41:18
hi,
is there any problem by not reg the bot?
it seems to work fine..
and the !ff thing was a mistype when i posted..sorry!
when looking at your "tutorial" i hit's me that every script should have it..
because i did'nt know what it excactly did and so on..
that would really help others to become better at scripting.
and for the unregged bot i read that it was'nt possible
off to new tasks for more headakes =)
many thanks stravides
Title:
Post by: Stravides on 27 February, 2004, 09:44:35
basically the Regbot puts the bot in your userlists and can then send and receive PM's in a separate window.
otherwise the bot will be considered "offline" and the main chat window will give Private Message from xyz message..

Unregbot just takes it out of that listing...  all depends upon what you wanna achieve :)

I was just making sure that you knew the diff between reg n unreg, I tend to do both to make sure that its a clean install of the bot..
Unreg then Reg, but not neccessary  :D

Keep up the coding its the only way we'll improve :)
Title:
Post by: OpiumVolage on 01 March, 2004, 12:43:00
PmToAStupidTablesGrrrButIAmStartingToLikeThemLOL(msg,from,user.sName)

Hmmm, Piglja's coding style ;))
Title:
Post by: lynyrd on 01 March, 2004, 21:06:11
those were the good old days =)
her vipchat script is surely the best ever made