HOW-TO: Write your own bot = Lesson 4
 

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 4

Started by pHaTTy, 25 October, 2003, 14:55:06

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

pHaTTy

Using timers
---------------

First of all here is the code we had from lesson 3

Bot = "Keiko" 

version = "0.4" 
NEWCON = 1 
prefix = "!"

function Main() 
	frmHub:RegBot(Bot) 
end 

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

function OpConnected(user) 
	if user.iProfile == 0 then 
		user:SendData(Bot,"Hello Master "..user.sName.." How are you") 
	return 1 
	else 
		SendToAll(Bot,"A Op has entered") 
	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) 
		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 add a timed advert, its very simple

You first of all have to set the timer
SetTimer(60000)

but also have something to show on the timer

we are going to use:

function OnTimer()
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 4--")
SendToAll(Bot,"-------------------------------")
end

and now you need to also start the timer:

StartTimer()

so now we have so far :

Bot = "Keiko" 

version = "0.4" 
NEWCON = 1 
prefix = "!"

function Main() 
	frmHub:RegBot(Bot) 
	SetTimer(60000)
	StartTimer()	--In the main function because it starts the timer on hub start or restart
end 

function OnTimer() --This is what will be sent on the timer
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 4--")
SendToAll(Bot,"-------------------------------")
end

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

function OpConnected(user) 
	if user.iProfile == 0 then 
		user:SendData(Bot,"Hello Master "..user.sName.." How are you") 
	return 1 
	else 
		SendToAll(Bot,"A Op has entered") 
	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) 
		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 also dont forget to use tabs, scripters always use tabs when scripting, it helps then find errors, in there script for example:

Bot = "Keiko" 

version = "0.4" 
NEWCON = 1 
prefix = "!"

function Main() 
frmHub:RegBot(Bot) 
SetTimer(60000)
StartTimer()	--In the main function because it starts the timer on hub start or restart
end 

function OnTimer() --This is what will be sent on the timer
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 4--")
SendToAll(Bot,"-------------------------------")
end

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

function OpConnected(user) 
if user.iProfile == 0 then 
user:SendData(Bot,"Hello Master "..user.sName.." How are you") 
return 1 
else 
SendToAll(Bot,"A Op has entered") 
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) 
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
end

in this example you will not really notice the problem
but if you use tabs:

Bot = "Keiko" 

version = "0.4" 
NEWCON = 1 
prefix = "!"

function Main() 
	frmHub:RegBot(Bot) 
	SetTimer(60000)
	StartTimer()	--In the main function because it starts the timer on hub start or restart
end 

function OnTimer() --This is what will be sent on the timer
	SendToAll(Bot,"-------------------------------")
	SendToAll(Bot,"--Write your own bot lesson 4--")
	SendToAll(Bot,"-------------------------------")
end

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

function OpConnected(user) 
	if user.iProfile == 0 then 
		user:SendData(Bot,"Hello Master "..user.sName.." How are you") 
	return 1 
	else 
		SendToAll(Bot,"A Op has entered") 
	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) 
		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
end -- now we can see there is 1 to many ends

so for each if there is an end

so this is the working version, this lesson has tought you to use tabs when scripting, why, and a little on timers, remember this is still the basic lessons, advanced will come when you have the basic bot

Bot = "Keiko" 

version = "0.4" 
NEWCON = 1 
prefix = "!"

function Main() 
	frmHub:RegBot(Bot) 
	SetTimer(60000)
	StartTimer()	--In the main function because it starts the timer on hub start or restart
end 

function OnTimer() --This is what will be sent on the timer
	SendToAll(Bot,"-------------------------------")
	SendToAll(Bot,"--Write your own bot lesson 4--")
	SendToAll(Bot,"-------------------------------")
end

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

function OpConnected(user) 
	if user.iProfile == 0 then 
		user:SendData(Bot,"Hello Master "..user.sName.." How are you") 
	return 1 
	else 
		SendToAll(Bot,"A Op has entered") 
	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) 
		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

l8rr,,

-phatty
Resistance is futile!

raz

so what is the lesson. as u r explaining this. ?(

pHaTTy

QuoteOriginally posted by raz
so what is the lesson. as u r explaining this. ?(

i dont understand what you mean?
Resistance is futile!

raz

now that we have learnt about tabs and how to put a timer in to a bot. what is the next lesson? this lesson seems very easy to do. maybe u could put a harder 1 up. :D

pHaTTy

No im writing the lessons, so ill write them easy to hard, im not jumping ahead, to quick, because newbies might not be able to keep up, or need to ask questions, then as i decide what next, then i will put up the next lesson ;)
And you are not supposed to just copy, its not as simple as it seems..........

you are supposed to use this data to help you think of ideas to use in a timer this is to help you understadn the basic timer
Resistance is futile!

raz

sorry, but i thought there was only 2 of us last time trying lesson 2. its ok if u want 2 wait 4 other ppl. i have new ideas like you do the timer thing u can have it so information about the hub comes up every 30 mins and and few commands dey can do like !news etc... :D i don't mind waiting, just i wnat 2 make my bot sooooon. :P

pHaTTy

Well i will try and split my time up and mabbe try and get another few lessons done today, but like i sqaid earlier i got linux to sort out ;)
Resistance is futile!

raz

actuaaly take your time as we went some good lessons. don't do it in a hurry. if u wnat u can get ur linux done first and den come on to the lessons. :D

NightLitch

Nice going here... When do we get some advanced lessons.... :-D
//NL

RiPOFF

what about functions that generally are used?

like if an account is idle for a while its automaticlly backed up into a txt and then deleted

or
like other hub function...

pHaTTy

Not quite sure what you mean, i will start on lesson 5 soon, altho i am taking it easy, i am going thru all the beginners lessons, then go thru them agen, but in advanced, i also have gekko to work on too, so not to much time on my hands, if you have a requests for next lesson post em here, n can you explain what you mean, see i am not writing you a bot, i am just teaching how to write things,

so if you mean to backup something, i will randomly choose something to backup, then you can learn from it ;)

-phatty
Resistance is futile!

lazyj189

I dont know about anyone else, but these lessons are sure helping me.  For the most part the basics, I've got them figured out.  Hell, I can even pull certian code out of other scripts that others have done to make smallers ones.  I am glad that phatty has taken this nice and slow because to someone who has never really understood the language, it takes a little time to absorb all this info.  I know I am ready whenever you are for lesson 5.  Otherwise some good practice is taking scripts that others have made and go through them, trying to understand al the functions, what does what, and what the results are of each.  When I get a script I try to start at the top and follow it through to see how it jumps all over the place.  Just a little insight as to how i've learned a little more about scripting.
DivX Dominion Hub Owner
3 years running
DivX Dominion Hub

pHaTTy

i am really happy that these are helping people, i might cancel some of my projects to do some more lessons :o)
Resistance is futile!

Masterload

like these lessons ,
helping to understand the basics
of scripting like to learn more about this :P
good job !!
magmarnet

visit me at home....

 

Nemesis

Nice lessons you have here, just right for complete newbies who ar'nt afraid to mess aorund and learn, just one question....    SetTimer(60000) is 60000 set in seconds?? so i could set say 300 for 5 mins ??  

PS not yet set this last lesson up as off to work in a jiffy and dont have time to play :( so not sure how long value of 60000 will last in actual time value
 hope you understand what im asking !

i know these lessons have been up a while but im a newbie, please be patient for me  :)

 8)
We all have a photographic memory.. just some of us forget to put the film in...  

pHaTTy

60000 = 1 min ;)
Resistance is futile!

Nemesis

Noticed you use
function NewUserConnected(user) - and
function OpConnected(user) for sending short message
but what if you wanted to send diff message to reg or vip too?   8o  :D  8)
We all have a photographic memory.. just some of us forget to put the film in...  

pHaTTy

if user.iProfile == (profilenumberhere) then

vip < is newuser

op > is op of course ;)
Resistance is futile!

LiqUiD~TrolL

well hi ppl i was looking at these lessons but i think i saw them very late,the lessons are really nice ones
but i don t need something so complicated

what if i just wana fix a simple bot that is shows a txt file?? only this io want
can you help me????
________<>________


            -=@_ psydream-land.no-ip.org _@=-


             
http://www.psychedelicdreams.bravehost.com

Herodes

for that kind of bot there is a series of posts in the :Scripting:Utilities:Central: thread located in this forum ..

also , this particular type of bots has its king ... Texter by plop..
look in //www.plop.nl to find the complete series of this bot ...
it will give u example of what you need to do .. watch the way the script develops throught the versions .. and always expiriment .. :)

LiqUiD~TrolL

hello herodes ,well my firend i tried plops bot
the bot it is shown on the users list but i can t see the txt
i tried +text !text and +,! fdfolder but nothin happened
what the hell is going on with this bot ?????????
________<>________


            -=@_ psydream-land.no-ip.org _@=-


             
http://www.psychedelicdreams.bravehost.com

MetalPrincess

Coolness you rule (uk-kingdom)pH?tt? :D


MP

speedX

If I want the bot to show the +help command on main chat every 1 min thn wat shud I add in the script and where??
Thanking You,

speedX

Naithif

You mean to show up the command itself?

Clock = 60000 --(millisec)
Bot = frmHub:GetHubBotName() --or write a nick for it in quotation marks

function Main()
	SetTimer(Clock)
	StartTimer()
end

OnTimer = function()
	SendToAll(Bot, "Type +help for help!")
end


On Main function (upon starting the script) the timer starts ticking and on every tick (60000ms = 60 s = 1min) it sends a message to all

speedX

#24
if I want to show up a text file??
I mean if I have a txt file with command +bla
And I want to display the data in tht txt file in main, thn wat to do??

Is it possible?? Please reply even if it not possible
Thanking You,

speedX

SMF spam blocked by CleanTalk