Author Topic: HOW-TO: Write your own bot = Lesson 8  (Read 9739 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 8
« on: 14 November, 2003, 22:02:25 »
Ok we will be dealing with tables a bit later on but first gonna add a few things and make this script abit better

from lesson 7 we had:

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()
dead = random(5)
if dead == 1 then
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
elseif dead == 2 then
SendC(Bot,user.sName.." has killed their self, what a pillock")
elseif dead == 3 then
SendC(Bot,user.sName.." is a total nutter, they killed em'self")
elseif dead == 4 then
SendC(Bot,user.sName.." is now dead, falling from the hub")
elseif dead == 5 then
SendC(Bot,user.sName.." jumps a mile high with a rope around their nech and drops down a hole, thats the last we seen of em")
end
return 1
end
end
end

adding a bit randomisation to the death command

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()
dead = random(5)
if dead == 1 then
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
elseif dead == 2 then
SendC(Bot,user.sName.." has killed their self, what a pillock")
elseif dead == 3 then
SendC(Bot,user.sName.." is a total nutter, they killed em'self")
elseif dead == 4 then
SendC(Bot,user.sName.." is now dead, falling from the hub")
elseif dead == 5 then
SendC(Bot,user.sName.." jumps a mile high with a rope around their nech and drops down a hole, thats the last we seen of em")
end
return 1
end
end
end


now the death command looks to big to be in data arrival, i think im gonna remove it and reassert it in a function

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
deathfunction(user) --the function i will use instead, send the users name with (user)
return 1
end
end
end

now to make the function

Code: [Select]
function deathfunction(pillock) -- reciving name of user from deathfunction(user)
dead = random(5)
if dead == 1 then
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
elseif dead == 2 then
SendC(Bot,user.sName.." has killed their self, what a pillock")
elseif dead == 3 then
SendC(Bot,user.sName.." is a total nutter, they killed em'self")
elseif dead == 4 then
SendC(Bot,user.sName.." is now dead, falling from the hub")
elseif dead == 5 then
SendC(Bot,user.sName.." jumps a mile high with a rope around their nech and drops down a hole, thats the last we seen of em")
end
pillock:Disconnect() --notice that its now pillock, becase the recieve data was not user, it was pillock
end

together 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 deathfunction(pillock) -- reciving name of user from deathfunction(user)
dead = random(5)
if dead == 1 then
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
elseif dead == 2 then
SendC(Bot,user.sName.." has killed their self, what a pillock")
elseif dead == 3 then
SendC(Bot,user.sName.." is a total nutter, they killed em'self")
elseif dead == 4 then
SendC(Bot,user.sName.." is now dead, falling from the hub")
elseif dead == 5 then
SendC(Bot,user.sName.." jumps a mile high with a rope around their nech and drops down a hole, thats the last we seen of em")
end
pillock:Disconnect()
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
deathfunction(user)
return 1
end
end
end

now we are going to use a table to filter badwords that are said in the main hub

Code: [Select]
TheBadWords = { "fuck", "twat", "suck", "fucker" }

now remember for checking tet it has to go in the data arrival as this is where data enters the script

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+)")
for key,checkWord in TheBadWords do
if (strfind(data, checkWord, 1, 1)) then
return 1
return 1
end
end
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
deathfunction(user)
return 1
end
end
end

now there we go this will now work :)

Code: [Select]
Bot = "Keiko"

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

MessageTimer = 1

TheBadWords = { "fuck", "twat", "suck", "fucker" }

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 deathfunction(pillock) -- reciving name of user from deathfunction(user)
dead = random(5)
if dead == 1 then
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
elseif dead == 2 then
SendC(Bot,user.sName.." has killed their self, what a pillock")
elseif dead == 3 then
SendC(Bot,user.sName.." is a total nutter, they killed em'self")
elseif dead == 4 then
SendC(Bot,user.sName.." is now dead, falling from the hub")
elseif dead == 5 then
SendC(Bot,user.sName.." jumps a mile high with a rope around their nech and drops down a hole, thats the last we seen of em")
end
pillock:Disconnect()
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+)")
for key,checkWord in TheBadWords do
if (strfind(data, checkWord, 1, 1)) then
return 1
return 1
end
end
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
deathfunction(user)
return 1
end
end
end

next on next post, not enough space
Resistance is futile!

PtokaX forum

HOW-TO: Write your own bot = Lesson 8
« on: 14 November, 2003, 22:02:25 »

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
Continued...
« Reply #1 on: 14 November, 2003, 22:03:33 »
now that was checking a table, now we are going to store data in a table, we will accomplish this by the badwords, we will count each badword that is said by the users and after 3 times it will disconnect them

Code: [Select]
BadWord={}


and now the code

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+)")
for key,checkWord in TheBadWords do
if (strfind(data, checkWord, 1, 1)) then
if BadWord[user.sName]==nil then
BadWord[user.sName]=0
elseif BadWord[user.sName]== 3 then
user:Disconnect()
else
BadWord[user.sName]=BadWord[user.sName]+1
end
return 1
end
end
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
deathfunction(user)
return 1
end
end
end

ok now we have :

Code: [Select]
Bot = "Keiko"

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

MessageTimer = 1
BadWord={}

TheBadWords = { "fuck", "twat", "suck", "fucker" }

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 deathfunction(pillock) -- reciving name of user from deathfunction(user)
dead = random(5)
if dead == 1 then
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
elseif dead == 2 then
SendC(Bot,user.sName.." has killed their self, what a pillock")
elseif dead == 3 then
SendC(Bot,user.sName.." is a total nutter, they killed em'self")
elseif dead == 4 then
SendC(Bot,user.sName.." is now dead, falling from the hub")
elseif dead == 5 then
SendC(Bot,user.sName.." jumps a mile high with a rope around their nech and drops down a hole, thats the last we seen of em")
end
pillock:Disconnect()
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+)")
for key,checkWord in TheBadWords do
if (strfind(data, checkWord, 1, 1)) then
if BadWord[user.sName]==nil then
BadWord[user.sName]=0
elseif BadWord[user.sName]== 3 then
user:Disconnect()
else
BadWord[user.sName]=BadWord[user.sName]+1
end
return 1
end
end
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
deathfunction(user)
return 1
end
end
end

now in the next lesson we will probablly be looking at parsing text and a bit more on tables ;)

l8rr,,

-phatz
Resistance is futile!

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #2 on: 22 November, 2003, 16:28:23 »
someone finally spotted the error hahaha

pillock = user

pillock:Disconnect() ahahahah

user:Disconnect()



well done SaintSinner
Resistance is futile!

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #3 on: 23 November, 2003, 06:48:07 »
there is another bug.
what happens when a user says 3x a bad word and comes back in the hub and says 1 more bad word ???

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Intel

  • Double Ace
  • *
  • Posts: 101
  • Karma: +1/-0
(No subject)
« Reply #4 on: 05 January, 2004, 09:31:31 »
i know i am weeks late to this lesson but...cant we say
user:Kick("Too many Bad Words")
Punnakku

Offline ((KMN))Gazza-95

  • Junior Member
  • **
  • Posts: 24
  • Karma: +3/-1
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #5 on: 21 April, 2006, 23:03:33 »
phatty i have done all the lessons so far and the script has come out in lua 3 and i need it lua 5 is there any way i can change that

Markitos

  • Guest
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #6 on: 21 April, 2006, 23:57:59 »
phatty i have done all the lessons so far and the script has come out in lua 3 and i need it lua 5 is there any way i can change that

yes...check this example and visit www.lua.org
Code: [Select]
--[[

HOW-TO: Write your own bot lesson 8
Optimized by Markitos:
-- Lua 5/5.1 Compatible
-- Use of string.rep ------->>>> string.rep (s, n) Returns a string made of n concatenated copies of string s.

]]--

Bot = "Keiko"

version = "0.81"
NEWCON = 1
TimeMins = 5  --set it to 5 mins
SendC = SendToAll

MessageTimer = 1
BadWord={}

TheBadWords = { "fuck", "twat", "suck", "fucker" }

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

function OnTimer()
if MessageTimer == 1 then
randomtimer = math.random(2) --only 2 data's
if randomtimer == 1 then
SendC(Bot,""..string.rep("-",15).."")
SendC(Bot,"--Write your own bot lesson "..version.."--")
SendC(Bot,""..string.rep("-",15).."")
elseif randomtimer == 2 then
SendC(Bot,""..string.rep("-",15).."")
SendC(Bot,"--This lesson bot was created by Phatty--")
SendC(Bot,""..string.rep("-",15).."")
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 = math.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 deathfunction(user) -- reciving name of user from deathfunction(user)
dead = math.random(5)
if dead == 1 then
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
elseif dead == 2 then
SendC(Bot,user.sName.." has killed their self, what a pillock")
elseif dead == 3 then
SendC(Bot,user.sName.." is a total nutter, they killed em'self")
elseif dead == 4 then
SendC(Bot,user.sName.." is now dead, falling from the hub")
elseif dead == 5 then
SendC(Bot,user.sName.." jumps a mile high with a rope around their nech and drops down a hole, thats the last we seen of em")
end
user:Disconnect()
end


function ChatArrival(user,data)
if string.sub(data, 1, 1) == "<" then
data=string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data,"%b<>%s+[%!%+](%S+)")
for key,checkWord in ipairs(TheBadWords) do
if (string.find(data, checkWord, 1, 1)) then
if BadWord[user.sName]==nil then
BadWord[user.sName]=0
elseif BadWord[user.sName]== 3 then
user:Disconnect()
else
BadWord[user.sName]=BadWord[user.sName]+1
end
return 1
end
end
if cmd == "version" then
return user:SendData(Bot,"This bot is Learn to write a bot version: "..version.." by Phatty"),1
elseif cmd == "help" then
return user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P"),1
elseif cmd == "death" then
return deathfunction(user),1
end
end
end

Offline 6Marilyn6Manson6

  • Scripter
  • King
  • ******
  • Posts: 869
  • Karma: +47/-35
    • http://www.marilynmanson986.altervista.org
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #7 on: 22 April, 2006, 00:04:03 »
Code: [Select]
function ChatArrival(user,data)
data=string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data,"%b<>%s+[%!%+](%S+)")
for key,checkWord in ipairs(TheBadWords) do
if (string.find(data, checkWord, 1, 1)) then
if BadWord[user.sName]==nil then
BadWord[user.sName]=0
elseif BadWord[user.sName]== 3 then
user:Disconnect()
else
BadWord[user.sName]=BadWord[user.sName]+1
end
return 1
end
end
if cmd == "version" then
return user:SendData(Bot,"This bot is Learn to write a bot version: "..version.." by Phatty"),1
elseif cmd == "help" then
return user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P"),1
elseif cmd == "death" then
return deathfunction(user),1
end
end

This function is most correct :D

Markitos

  • Guest
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #8 on: 22 April, 2006, 09:33:44 »
This function is most correct :D

Is it?

Some obversavations, and merely just pointing out the choices we have...

Tables are more efficient than if elseif...
I think a table is best here if more than a 1 or 2 elseifs

String subbing..
data=string.sub(data,1,string.len(data)-1)
Why string.sub unless your adjusting the string, the line above has no effect
It simply represents the orifinal data.

s,e,cmd = string.find(data,"%b<>%s+[%!%+](%S+)")
If you dont need a global variable here, why have one? local s,e,cmd...
As for the pattern, %b<>%s+
Do you expect more than a single space, this will match one or an infinite number of space chars here
Consider %b<>%s[%!...    or use a space   %b<> [%!...
more on the pattern...
+[%!%+](%S+)"
This is fine if you do want to restrict the prefix to just these charachters.
Now for the command name itself, is it really ok to be any non space charachter?
If you dont mind, its fine, but I'd rather specify, and write that pattern as...
"%b<>%s%p(%w+)"


food for thought...



Yes i agree with you...tables are more eficient but i was off to bed so did a quick djob  ;D
And thanks for the hint about pattern matching.

Going to rewrite...

Edited// I rewrote the ChatArrival but it gives me an error
Code: [Select]
--[[

HOW-TO: Write your own bot lesson 8
Optimized by Markitos:
-- Lua 5/5.1 Compatible
-- Use of string.rep ------->>>> string.rep (s, n) Returns a string made of n concatenated copies of string s.

]]--

Bot = "Keiko"

version = "0.81"
NEWCON = 1
TimeMins = 5  --set it to 5 mins
SendC = SendToAll

MessageTimer = 1
BadWord={}

TheBadWords = { "fuck", "twat", "suck", "fucker" }

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

function OnTimer()
if MessageTimer == 1 then
randomtimer = math.random(2) --only 2 data's
if randomtimer == 1 then
SendC(Bot,""..string.rep("-",15).."")
SendC(Bot,"--Write your own bot lesson "..version.."--")
SendC(Bot,""..string.rep("-",15).."")
elseif randomtimer == 2 then
SendC(Bot,""..string.rep("-",15).."")
SendC(Bot,"--This lesson bot was created by Phatty--")
SendC(Bot,""..string.rep("-",15).."")
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 = math.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 deathfunction(user) -- reciving name of user from deathfunction(user)
dead = math.random(5)
if dead == 1 then
SendC(Bot,user.sName.." has killed their self, and fell out the hub")
elseif dead == 2 then
SendC(Bot,user.sName.." has killed their self, what a pillock")
elseif dead == 3 then
SendC(Bot,user.sName.." is a total nutter, they killed em'self")
elseif dead == 4 then
SendC(Bot,user.sName.." is now dead, falling from the hub")
elseif dead == 5 then
SendC(Bot,user.sName.." jumps a mile high with a rope around their nech and drops down a hole, thats the last we seen of em")
end
user:Disconnect()
end


function ChatArrival(user,data)
local s,e,cmd = string.find(data,"%b<>%s%p(%w+)")
if cmd then
local tCmds = {
["version"] = function(user)
user:SendData(Bot,"This bot is Learn to write a bot version: "..version.." by Phatty")
end,
["help"] = function(user)
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
end,
["death"] = function(user)
deathfunction(user)
end,
}
if tCmds[cmd] then
return tCmds[cmd](user),1
end
for key,checkWord in ipairs(TheBadWords) do
if (string.find(data, checkWord, 1, 1)) then
if BadWord[user.sName]==nil then
BadWord[user.sName]=0
elseif BadWord[user.sName]== 3 then
user:Disconnect()
else
BadWord[user.sName]=BadWord[user.sName]+1
end
return 1
end
end
end
end
[10:58]Ptokax 0.3.4.0f0.dbg\scripts\test.lua:89: `}' expected (to close `{' at line 85) near `['
« Last Edit: 23 April, 2006, 21:09:37 by Markitos »

Markitos

  • Guest
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #9 on: 22 April, 2006, 16:09:50 »
Is there anything else to short in the script?
« Last Edit: 22 April, 2006, 16:25:41 by Markitos »

Markitos

  • Guest
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #10 on: 22 April, 2006, 17:34:36 »
I dont understand your question, please rephrase.

For what its worth I'd been using this command format in a global commands table...

Code: [Select]
tCmds = {
cmdname = function(user,data)
if user then
        --DoStuff
else
return "Description",cmdarg1,cmdarg2
end
end,
}

It allows for one function to exec a command, return a description [for use in script help] or
to generate context menus (right click)
As a global table, I can also call the commands from other functions like this  to execute:
tCmds.cmdname(user)
or like this to return Description and args:
tCmds.cmdname()
Indeed...i saw that kind of code in your scripts anyway thanks for the help  ;)

Offline ((KMN))Gazza-95

  • Junior Member
  • **
  • Posts: 24
  • Karma: +3/-1
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #11 on: 23 April, 2006, 20:35:15 »
MARKITOS IT STILL SEZ LUA 3

Markitos

  • Guest
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #12 on: 23 April, 2006, 21:11:22 »
MARKITOS IT STILL SEZ LUA 3
Lua 3??? I converted it to lua5/5.1...
There was an issue alright but its already solved.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #13 on: 24 April, 2006, 20:53:03 »
Was there any PtokaX with lua3?
Everything could have been anything else and it would have just as much meaning.

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #14 on: 25 April, 2006, 00:51:50 »
NO  ::)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Markitos

  • Guest

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #16 on: 14 November, 2006, 05:20:02 »
Hello guys,
If I want to add tables means I want some commands wich will be used by specific profile nos. only, thn wat and whr shud I add.

And this small Bot I tried to make, but its not working :(
Code: [Select]

Bot = "HOPS"


function ChatArrival(user,data)
local s,e,cmd = string.find(data,"%b<>%s%p(%w+)")
if cmd then
          local tCmds = {
                    ["myip"] = function(user)
                          user:SendData(Bot,"Your IP is: "..user.sIP)
                    end
          }
  end
end
Thx for any help
« Last Edit: 14 November, 2006, 05:27:53 by speedX »
Thanking You,

speedX

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #17 on: 23 November, 2006, 15:44:58 »
Thx American Idiot, If I want only specific profile nos. to use the command thn wat shud I do? also If i want all to see the command thn wat shud be code??
Thx for any help
Thanking You,

speedX

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #18 on: 23 November, 2006, 16:58:37 »
Hey American Idiot, since this is a tutorial page, I wanted to ask something for some time now - What's the difference between reading commands from table and reading commands directly?
From what I saw it's the same, but you need to write more with a table :S
Is it faster or eats less mem?  ???

Code: [Select]
if cmd then
local tCmds = {
["myip"] = function()
...
end

Code: [Select]
if cmd == "myip" then
...
end

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #19 on: 23 November, 2006, 17:25:15 »
It should seem obvious to you that you will need to the user's profile.
If I would have known scripting, thn I would have never asked tht question....

Do you do any research? This type of code is built into more than half
of every script written for PtokaX since the dawn of time. Or would you
rather pose such questions and wait until someone writes the code for you?
Its not tht Sir, as all scripters have different style of writing so newbie's like us find it difficult to understand wat a particular command does.

Anyways thx for all the help, and sorry if I was rude......
Thanking You,

speedX

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: HOW-TO: Write your own bot = Lesson 8
« Reply #20 on: 23 November, 2006, 17:28:10 »
...
A table can be looped or hashed and functions within that table
may be called again and again saving you redundant code.
...

Hashed?  :o
There are always things to learn (and there are some surprising ones)  :D
Thanks American Idiot, I'll experiment with these thingies to see what's up with them

PtokaX forum

Re: HOW-TO: Write your own bot = Lesson 8
« Reply #20 on: 23 November, 2006, 17:28:10 »