Author Topic: HOW-TO: Write your own bot = Lesson 7  (Read 1691 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 7
« on: 14 November, 2003, 21:29:27 »
Ok i have had a few confusin's in a few of the lessons aut different things, so i will go over the problems now

ok some of the questions...


What is NEWCON=1?

its a variable

What is NEWCON=1 do/used for?
function NewUserConnected(user)
   if NEWCON == 1 then
      user:SendData (Bot,"A User has connected")
   end
end

checks


so now basically if i changed NEWCON=1 to NEWCON=0 then when a user connects it wont show the message


its like this


imagine this a real life

Speakers = 1

function Main()
--on restart and main serve
if Speakers == 1 then
PlayTheMusic()
else
end
end



there s mini help ;)

thats shud help, if you dont understand now, you will in later lessons, at the moment, its not about understanding what i aint explained, its about understanding what task is in hand, remember there is still many lessons togo before you can become a script master.

ok so now we are going to add a switch to stop the timer for the messages


Code: [Select]

function OnTimer()
if MessageTimer == 1 then
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
end



so now we have that we need a switch

Code: [Select]
MessageTimer = 1

so now we have

Code: [Select]
Bot = "Keiko"

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

MessageTimer = 1

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

function OnTimer()
if MessageTimer == 1 then
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
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


now we are going to make a few commands, i will use a few from gekko for example, first i will add death

death will disconnect you from the hub

[/code]
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
      elseif cmd == prefix.."death" then
         user:Disconnect() -- Notice the user disconnect now remember the following line wud not work
            --user:disconnect() -- now tell me why this line wud not work apart from the --
      return 1
      end
   end
end
[/code]

now we also add a death message

Code: [Select]
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
elseif cmd == prefix.."death" then
user:Disconnect()
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
return 1
end
end
end

now we have:

Code: [Select]
Bot = "Keiko"

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

MessageTimer = 1

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

function OnTimer()
if MessageTimer == 1 then
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
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
elseif cmd == prefix.."death" then
user:Disconnect()
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
return 1
end
end
end

enjoy, in the next lesson we will be user

Whatever = {}

l8rr,,

-phatty ;)
Resistance is futile!

PtokaX forum

HOW-TO: Write your own bot = Lesson 7
« on: 14 November, 2003, 21:29:27 »