HOW-TO: Write your own bot = Lesson 7
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

HOW-TO: Write your own bot = Lesson 7

Started by pHaTTy, 14 November, 2003, 21:29:27

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

pHaTTy

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


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

MessageTimer = 1

so now we have

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

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:

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!

SMF spam blocked by CleanTalk