PtokaX forum

Development Section => HOW-TO's => Topic started by: pHaTTy on 14 November, 2003, 17:31:48

Title: HOW-TO: Write your own bot = Lesson 6
Post by: pHaTTy on 14 November, 2003, 17:31:48
ok lesson 5 we had at the end


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........


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


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


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


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")


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