Author Topic: HOW-TO: Write your own bot = Lesson 6  (Read 1578 times)

0 Members and 1 Guest are viewing this topic.

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
HOW-TO: Write your own bot = Lesson 6
« on: 14 November, 2003, 17:31:48 »
ok lesson 5 we had at the end

Code: [Select]

Bot = "Keiko"

version = "0.6"
NEWCON = 1
prefix = "!"
TimeMins = 5  --set it to 5 mins


function Main()
frmHub:RegBot(Bot)
SetTimer(TimeMins*60000)
StartTimer()
end

function OnTimer() --This is what will be sent on the timer
randomtimer = random(2) --only 2 data's
if randomtimer == 1 then
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 5--")
SendToAll(Bot,"-------------------------------")
elseif randomtimer == 2 then
SendToAll(Bot,"-----------------------------------------")
SendToAll(Bot,"--This lesson bot was created by Phatty--")
SendToAll(Bot,"-----------------------------------------")
end
end

function NewUserConnected(user)
if NEWCON == 1 then
user:SendData (Bot,"A User has connected")
end
end

function OpConnected(user)
thisisthevariable = random(5)
if thisisthevariable == 1 then
SendToAll(Bot,"This is message 1")

elseif thisisthevariable == 2 then
SendToAll(Bot,"This is message 2")

elseif thisisthevariable == 3 then
SendToAll(Bot,"This is message 3")

elseif thisisthevariable == 4 then
SendToAll(Bot,"This is message 4")

elseif thisisthevariable == 5 then
SendToAll(Bot,"This is message 5")
end
end



function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == prefix.."version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version.." by Phatty")
return 1
elseif cmd == prefix.."help" then
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
return 1
end
end
end


now i dont know about you but im sick of keep changing

the This is lesson blablah

so........

Code: [Select]

function OnTimer() --This is what will be sent on the timer
randomtimer = random(2) --only 2 data's
if randomtimer == 1 then
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson "..version.."--")
SendToAll(Bot,"-------------------------------")
elseif randomtimer == 2 then
SendToAll(Bot,"-----------------------------------------")
SendToAll(Bot,"--This lesson bot was created by Phatty--")
SendToAll(Bot,"-----------------------------------------")
end
end


now we are going to sup up the user connect msg's a little

Code: [Select]

function OpConnected(user)
thisisthevariable = random(5)
if thisisthevariable == 1 then
SendToAll(Bot,user.sName.." has entered the hub")

elseif thisisthevariable == 2 then
SendToAll(Bot,user.sName.." has entered, feel his wrath")  

elseif thisisthevariable == 3 then
SendToAll(Bot,user.sName.." is one of the big bosses, who just entered")

elseif thisisthevariable == 4 then
SendToAll(Bot,user.sName.." has sneaked into the hub")  

elseif thisisthevariable == 5 then
SendToAll(Bot,user.sName.." has just kicked down the door")
end
end



so now we have

Code: [Select]

Bot = "Keiko"

version = "0.5"
NEWCON = 1
prefix = "!"
TimeMins = 5  --set it to 5 mins


function Main()
frmHub:RegBot(Bot)
SetTimer(TimeMins*60000)
StartTimer()
end

function OnTimer() --This is what will be sent on the timer
randomtimer = random(2) --only 2 data's
if randomtimer == 1 then
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson "..version.."--")
SendToAll(Bot,"-------------------------------")
elseif randomtimer == 2 then
SendToAll(Bot,"-----------------------------------------")
SendToAll(Bot,"--This lesson bot was created by Phatty--")
SendToAll(Bot,"-----------------------------------------")
end
end

function NewUserConnected(user)
if NEWCON == 1 then
user:SendData (Bot,"A User has connected")
end
end

function OpConnected(user)
thisisthevariable = random(5)
if thisisthevariable == 1 then
SendToAll(Bot,user.sName.." has entered the hub")

elseif thisisthevariable == 2 then
SendToAll(Bot,user.sName.." has entered, feel his wrath")  

elseif thisisthevariable == 3 then
SendToAll(Bot,user.sName.." is one of the big bosses, who just entered")

elseif thisisthevariable == 4 then
SendToAll(Bot,user.sName.." has sneaked into the hub")  

elseif thisisthevariable == 5 then
SendToAll(Bot,user.sName.." has just kicked down the door")
end
end



function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == prefix.."version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version.." by Phatty")
return 1
elseif cmd == prefix.."help" then
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
return 1
end
end
end


ok now we will add a profile idx in one of the entrances

Code: [Select]

function OpConnected(user)
Pillock = GetProfileName(user.iProfile)
thisisthevariable = random(5)
if thisisthevariable == 1 then
SendToAll(Bot,user.sName.." has entered the hub")

elseif thisisthevariable == 2 then
SendToAll(Bot,Pillock.." "..user.sName..",has entered, feel his wrath")  

elseif thisisthevariable == 3 then
SendToAll(Bot,user.sName.." is one of the big bosses, who just entered")

elseif thisisthevariable == 4 then
SendToAll(Bot,user.sName.." has sneaked into the hub")  

elseif thisisthevariable == 5 then
SendToAll(Bot,user.sName.." has just kicked down the door")
end
end


now i dont know about you but i hate using SendToAll("Blablahblah")

so i will name it SendC ("Whatever")

Code: [Select]

Bot = "Keiko"

version = "0.6"
NEWCON = 1
prefix = "!"
TimeMins = 5  --set it to 5 mins
SendC = SendToAll

function Main()
frmHub:RegBot(Bot)
SetTimer(TimeMins*60000)
StartTimer()
end

function OnTimer()
randomtimer = random(2) --only 2 data's
if randomtimer == 1 then
SendC(Bot,"-------------------------------")
SendC(Bot,"--Write your own bot lesson "..version.."--")
SendC(Bot,"-------------------------------")
elseif randomtimer == 2 then
SendC(Bot,"-----------------------------------------")
SendC(Bot,"--This lesson bot was created by Phatty--")
SendC(Bot,"-----------------------------------------")
end
end

function NewUserConnected(user)
if NEWCON == 1 then
user:SendData (Bot,"A User has connected")
end
end

function OpConnected(user)
Pillock = GetProfileName(user.iProfile)
thisisthevariable = random(5)
if thisisthevariable == 1 then
SendC(Bot,user.sName.." has entered the hub")

elseif thisisthevariable == 2 then
SendC(Bot,Pillock.." "..user.sName..",has entered, feel his wrath")  

elseif thisisthevariable == 3 then
SendC(Bot,user.sName.." is one of the big bosses, who just entered")

elseif thisisthevariable == 4 then
SendC(Bot,user.sName.." has sneaked into the hub")  

elseif thisisthevariable == 5 then
SendC(Bot,user.sName.." has just kicked down the door")
end
end



function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == prefix.."version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version.." by Phatty")
return 1
elseif cmd == prefix.."help" then
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
return 1
end
end
end


thats all there is for this subject, til next time cya ;)

-phatz
Resistance is futile!

PtokaX forum

HOW-TO: Write your own bot = Lesson 6
« on: 14 November, 2003, 17:31:48 »