Author Topic: HOW-TO: Write you own bot = Lesson 9  (Read 11039 times)

0 Members and 1 Guest are viewing this topic.

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
HOW-TO: Write you own bot = Lesson 9
« on: 19 December, 2003, 20:36:44 »
Ok i am going to be more advanced here, and i will notice alot of things that are alot different to other scripters, you will see my style of programming





ok what we had from long time ago :

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(user) -- 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
user: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 im gonna show some of the most common functions such as mass message and some i have been asked for.....


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
elseif (cmd==prefix.."mass") then
if user.bOperator then
s,e,cmd,message = strfind(data,"%s+(%S+)%s+(.*)")
SendC(Bot," "..user.sName..": "..message)
end
end
end
end
end



now lets add a message if they dont enter a message to send

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
elseif (cmd==prefix.."mass") then
if user.bOperator then
s,e,cmd,message = strfind(data,"%s+(%S+)%s+(.*)")
if message == nil then
user:SendData(Bot,"Please enter a message to mass")
return 1
end
SendC(Bot," "..user.sName..": "..message)
end
end
end
end
end



Now we will add a kick/kicktempban/ban

Code: [Select]

Bot = "Keiko"

version = "0.9"
NEWCON = 1
prefix = "!"
TimeMins = 5  --set it to 5 mins
TimeToBan = "15" -- the tempban time
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(user) -- 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
user: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
elseif (cmd==prefix.."mass") then
if user.bOperator then
s,e,cmd,message = strfind(data,"%s+(%S+)%s+(.*)")
if message == nil then
user:SendData(Bot,"Please enter a message to mass")
return 1
else
SendC(Bot," "..user.sName..": "..message)
end
end
elseif (cmd==prefix.."kick") then
s,e,cmd,whotokick = strfind(data,"%s+(%S+)%s+(%S+)")
if whotokick == nil then
return 1
else
twat = GetItemByName(whotokick)
twat:Disconnect() --without tempban
end
elseif (cmd==prefix.."temp") then
s,e,cmd,whotokick = strfind(data,"%s+(%S+)%s+(%S+)")
if whotokick == nil then
return 1
else
twat = GetItemByName(whotokick)
twat:TimeBan(TimeToBan) --ban for specified
end
elseif (cmd==prefix.."ban") then
s,e,cmd,whotokick = strfind(data,"%s+(%S+)%s+(%S+)")
if whotokick == nil then
return 1
else
twat = GetItemByName(whotokick)
twat:Ban() --perm ban
end
end
end
end



enjoy this little lesson and try add some kick messages ;)

bbl for more

-phatty
Resistance is futile!

PtokaX forum

HOW-TO: Write you own bot = Lesson 9
« on: 19 December, 2003, 20:36:44 »

Offline Tarokkk

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
??
« Reply #1 on: 23 December, 2003, 11:15:30 »
What is TWAT in the script ?

Code: [Select]
elseif (cmd==prefix.."temp") then
s,e,cmd,whotokick = strfind(data,"%s+(%S+)%s+(%S+)")
if whotokick == nil then
return 1
else
twat = GetItemByName(whotokick)
twat:TimeBan(TimeToBan) --ban for specified
end


Offline Tarokkk

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #2 on: 23 December, 2003, 11:18:47 »
Oh I'm sorry :D I know what is it ...

twat = user :D

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #3 on: 23 December, 2003, 15:06:20 »
lol, yep ;)

well technically whotokick = twat / if whotokick is nil then its nothink, if > 0 then twat = user ;)
Resistance is futile!

Offline Tarokkk

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #4 on: 23 December, 2003, 19:45:25 »
I think this script don't work

twat nil value ......

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #5 on: 23 December, 2003, 19:50:16 »
well a mistake on ur end or you using an old ptokax ;)

works for me :P
Resistance is futile!

Offline Tarokkk

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #6 on: 23 December, 2003, 19:58:04 »
I type !kick somebody and the error in the ptoka

--
Syntax Error: attempt to index global `twat' (a nil value)
--

Offline NotRabidWombat

  • Lord
  • ***
  • Posts: 384
  • Karma: +2/-0
(No subject)
« Reply #7 on: 23 December, 2003, 20:04:59 »
s,e,cmd,whotokick = strfind(data,"%s+(%S+)%s+(%S+)")

This regex isn't safe. You never change data so its still in the same form, msg, less the pipe. I would suggest you extract the message and make it the new data like so:

local s,e,data, cmd = strfind(data,"%b<>%s+((%S+).+)")

Now you won't have the nick part that is causing the problem. Additionally, you can reuse variables that you no longer need such as:

whotokick = GetItemByName(whotokick);

Plus the use of local variables and variable names that make sense (twat?) would be a lot more helpful. It is also good practice to check ALL user input dependent variables for nil results. A person could type !kick NonExistantNick and this will restult in a nil returned from GetItemByName.

-NotRabidWombat
« Last Edit: 23 December, 2003, 20:06:18 by NotRabidWombat »


I like childish behavior. Maybe this post will be deleted next.

Offline Tarokkk

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
THX
« Reply #8 on: 23 December, 2003, 20:15:36 »
IT's Gooood :D

Offline Tarokkk

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
I did that but...
« Reply #9 on: 23 December, 2003, 21:32:19 »
I did that but I don't understand the new strfind.. :(

So the script is stopped when the user name isn't real

Code: [Select]
Bot = "Keiko"

-------
version = "0.9"
NEWCON = 1
prefix = "!"
TimeMins = 5  --set it to 5 mins
TimeToBan = "15" -- the tempban time
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(user) -- 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
user: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
elseif (cmd==prefix.."mass") then
if user.bOperator then
s,e,cmd,message = strfind(data,"%s+(%S+)%s+(.*)")
if message == nil then
user:SendData(Bot,"Please enter a message to mass")
return 1
else
SendC(Bot," "..user.sName..": "..message)
end
end

elseif (cmd==prefix.."kick") then
local s,e, cmd,whotokick,mess = strfind(data,"%s+(%S+)%s+(%S+)%s+(.*)")

if whotokick == nil then
user:SendData (Bot, "The User isn't in the HUB!")
return 1
elseif mess == nil then
user:SendData (Bot, "You forgot the reason...")
return 1
else
twat = GetItemByName(whotokick)
twat:SendPM (Bot, "You are being kicked by  "..user.sName.." because:   "..mess)
twat:Disconnect()
end


elseif (cmd==prefix.."temp") then
s,e,cmd,whotokick,mess = strfind(data,"%s+(%S+)%s+(%S+)%s+(.*)")
if whotokick == nil then
return 1
else
twat = GetItemByName(whotokick)
twat:SendPM (Bot, "You are being timbanned for "..TimeToBan.." minutes by  "..user.sName.." because:   "..mess)
twat:TimeBan(TimeToBan) --ban for specified
end
elseif (cmd==prefix.."ban") then
s,e,cmd,whotokick,mess = strfind(data,"%s+(%S+)%s+(%S+)%s+(.*)")
if whotokick == nil then
return 1
else
twat = GetItemByName(whotokick)
twat:SendPM(Bot, "YOUR ASS IS BANNED !!!          because:   "..mess)
twat:Ban() --perm ban
end
end
end
end

Offline Intel

  • Double Ace
  • *
  • Posts: 101
  • Karma: +1/-0
(No subject)
« Reply #10 on: 05 January, 2004, 09:40:34 »
Cool I went trough all And Got many explanations + and good overview of how it functions and how to write a bit :) mainly thanks to (uk-kingdom)pH?tt? and a few others who corrected & ASked a few question which i might asked if i was apart of the forum 1 month back..

But I have a Small question...

prefix = "!" if i want, cause i change it to prefix = "#" or what ever i want it to be ?? I am 99 % sure i can but asking for a safty reason...hehe

Also Where can I find the commands for Lua such as
SendC , NEWCON , OpConnected ....  Many their are many thousand others which we dont use, which i want to use ....

Once again Thanks :) If their are more lessons, Me in 2 :)
Punnakku

Offline SaintSinner

  • Lord
  • ***
  • Posts: 293
  • Karma: +1/-0
(No subject)
« Reply #11 on: 05 January, 2004, 15:10:37 »
Quote
Originally posted by Intel
Cool I went trough all And Got many explanations + and good overview of how it functions and how to write a bit :) mainly thanks to (uk-kingdom)pH?tt? and a few others who corrected & ASked a few question which i might asked if i was apart of the forum 1 month back..

But I have a Small question...

prefix = "!" if i want, cause i change it to prefix = "#" or what ever i want it to be ?? I am 99 % sure i can but asking for a safty reason...hehe

Also Where can I find the commands for Lua such as
SendC , NEWCON , OpConnected ....  Many their are many thousand others which we dont use, which i want to use ....

Once again Thanks :) If their are more lessons, Me in 2 :)



Ok im not a lua expert yet...but i will try to explain as good as i can, from what i learned...
prefix = "!" yes you can use whatever prefix you want, that is why its defined as prefix equals "this", just make sure that its in the "".
you could have:
prefix = "!"
elseif cmd == prefix.."help" then
--hubowners can define the prefixes themselves.
--if you have
elseif cmd == "!help" then
--then the hubowners have to use ! or edit each
--command himself.

SendC is defined in the script as
SendC = SendToAll
so instead of typing SendToAll() all the time you will just type SendC().


OpConnected and other functions are listed in the Docs folder of the hubsoft.
i

m still not sure on the NEWCON
but from what i gathered its new connection
function NewUserConnected(user)
   if NEWCON == 1 then
   user:SendData (Bot,"A User has connected")
im guessing its there to be able to
shut is to shut it on and off, for when you need it.
0=off     will not send a message
1=on     will send a message

« Last Edit: 05 January, 2004, 15:13:48 by SaintSinner »
   


Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #12 on: 05 January, 2004, 15:18:52 »
Quote
Originally posted by SaintSinner
Quote
Originally posted by Intel
Cool I went trough all And Got many explanations + and good overview of how it functions and how to write a bit :) mainly thanks to (uk-kingdom)pH?tt? and a few others who corrected & ASked a few question which i might asked if i was apart of the forum 1 month back..

But I have a Small question...

prefix = "!" if i want, cause i change it to prefix = "#" or what ever i want it to be ?? I am 99 % sure i can but asking for a safty reason...hehe

Also Where can I find the commands for Lua such as
SendC , NEWCON , OpConnected ....  Many their are many thousand others which we dont use, which i want to use ....

Once again Thanks :) If their are more lessons, Me in 2 :)



Ok im not a lua expert yet...but i will try to explain as good as i can, from what i learned...
prefix = "!" yes you can use whatever prefix you want, that is why its defined as prefix equals "this", just make sure that its in the "".
you could have:
prefix = "!"
elseif cmd == prefix.."help" then
--hubowners can define the prefixes themselves.
--if you have
elseif cmd == "!help" then
--then the hubowners have to use ! or edit each
--command himself.

SendC is defined in the script as
SendC = SendToAll
so instead of typing SendToAll() all the time you will just type SendC().


OpConnected and other functions are listed in the Docs folder of the hubsoft.
i

m still not sure on the NEWCON
but from what i gathered its new connection
function NewUserConnected(user)
   if NEWCON == 1 then
   user:SendData (Bot,"A User has connected")
im guessing its there to be able to
shut is to shut it on and off, for when you need it.
0=off     will not send a message
1=on     will send a message



very well explained, well done :)
Resistance is futile!

Offline Intel

  • Double Ace
  • *
  • Posts: 101
  • Karma: +1/-0
(No subject)
« Reply #13 on: 05 January, 2004, 22:43:49 »
Cool I am 100 into it now, are their more lessons ? I guess I have to try and try and try and suddenly i will be able to help many people in this forum...
is lua used anywhere else than scripting ? What else can we use Lua to ? Does anyone knows ?
Punnakku

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #14 on: 05 January, 2004, 22:50:36 »
lua is a scripting langauge, you can integrate it into games, its often used in games such as homeworld and things like that, i am currently thinking of using it in a game for the AI Units....
Resistance is futile!

Offline Intel

  • Double Ace
  • *
  • Posts: 101
  • Karma: +1/-0
(No subject)
« Reply #15 on: 05 January, 2004, 22:57:00 »
so lua is mainly for games...why has the author of Ptokax Choosen Lua and not Vb or C++...cause their their are many other  cool things we can make, not because i am much into scriptings but..if the new version can be both Vb & Lua then it would be cool.. ?


Quote
maybe wrong question in the wrong place but just shootes it out in the blue air....
Punnakku

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #16 on: 05 January, 2004, 23:05:58 »
altho i find vb a nice language its pretty slow, and c++ has to many things you can do i guess i a popup window, so a good way to stop that is by using lua i suppose, and lua is a natural scripting language :)
Resistance is futile!

Offline NotRabidWombat

  • Lord
  • ***
  • Posts: 384
  • Karma: +2/-0
(No subject)
« Reply #17 on: 05 January, 2004, 23:13:04 »
VB is not as rich of language as lua (I usually find vbscript very cumbersome). C++ isn't really a scripting language because it has to be compiled (like the dlls used in winamp).
Lua is used in a lot more places than games. I've recently wrote a program that used lua as a scripting language to create robot navigational code.
It's becoming very popular because it is very easy to integrate and can be supported on many different OS platforms. You can also write your own lua standalone scripts that can do just about anything. Go to http://www.lua.org to find out all about it.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

Gazza-95

  • Guest
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #18 on: 20 April, 2006, 18:36:57 »
phatty how long till the next lesson

Offline Znupi

  • Junior Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • No one else
    • Znupi's LUA scripts
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #19 on: 28 May, 2006, 23:04:21 »
Hello ppl, glad 2 be here ... this is me first post here ... so here I go ...

Is there a command that logs out a bot ?? ... here's what i mean :

is there the oposite of frmHub:RegBot(Bot) ? if there is , pls tell me ...

Offline 6Marilyn6Manson6

  • Scripter
  • King
  • ******
  • Posts: 869
  • Karma: +47/-35
    • http://www.marilynmanson986.altervista.org
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #20 on: 28 May, 2006, 23:11:41 »
Hello ppl, glad 2 be here ... this is me first post here ... so here I go ...

Is there a command that logs out a bot ?? ... here's what i mean :

is there the oposite of frmHub:RegBot(Bot) ? if there is , pls tell me ...

Code: [Select]
--Killbot LUA5
--
--by American Idiot
--
--Removes a bot from main user listing by typing
--!killbot <botname>
--in main or...
--!listbot <botname>
--to restore botname.

SendMenu = "yes"    -- Send Command Menu? "yes"/"no"
--
--Set your profiles here
--[profileidx#] = 0 or 1
--0=No Menu, No Command / 1=Send Menu & Can use Command
Profiles = {
[-1] = 0, --Unregistered User
[0] = 1, --Master
[1] = 1, --Operator
[2] = 0, --Vip
[3] = 0, --Registered User
[4] = 1, --Moderator
[5] = 1, --NetFounder
}

--Set menu name or leave as is for hubname set in PtokaX
HubMenu = frmHub:GetHubBotName()

function NewUserConnected(user)
    if SendMenu == "yes" then
   if Profiles[user.iProfile] ==1 then
  customCMDS(user)
   end
    end
end

OpConnected = NewUserConnected

--$UserCommand 1 X  Where -> 1=Hub Menu 2=User Menu 3=Hub/User Menu
function customCMDS(user)
--user:SendData("$UserCommand 255 7") --clear the menu first
user:SendData("$UserCommand 1 1 "..HubMenu.."\\Bot Admin\\Remove Bot $<%[mynick]> !killbot %[line:BotNick]&#124;|")
user:SendData("$UserCommand 1 2 "..HubMenu.."\\Bot Admin\\Remove Bot $<%[mynick]> !killbot %[nick]&#124;|")
user:SendData("$UserCommand 1 3 "..HubMenu.."\\Bot Admin\\Restore Bot $<%[mynick]> !listbot %[line:BotNick]&#124;|")
end

function ChatArrival(user, data)
if Profiles[user.iProfile] ==1 then
data=string.sub(data,1,string.len(data)-1)
s,e,cmd,name = string.find(data,"%b<>%s+(%S+)%s+(%S+)")
if cmd=="!killbot" then
frmHub:UnregBot(name)
return 1
elseif cmd=="!listbot" then
frmHub:RegBot(name)
return 1
end
end
end

You can study this script ^_^

Offline Znupi

  • Junior Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • No one else
    • Znupi's LUA scripts
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #21 on: 28 May, 2006, 23:14:50 »
ThX !! Damn u were fast ...

Offline 6Marilyn6Manson6

  • Scripter
  • King
  • ******
  • Posts: 869
  • Karma: +47/-35
    • http://www.marilynmanson986.altervista.org
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #22 on: 29 May, 2006, 08:05:32 »
Welcome ;)

Offline Znupi

  • Junior Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • No one else
    • Znupi's LUA scripts
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #23 on: 29 May, 2006, 09:34:21 »
Is there a function or smth like ... delay ? like ... make it w8 a few seconds / miliseconds before moving on with the script ...

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #24 on: 29 May, 2006, 14:30:55 »
You'll have to work with timers.

SetTimer(timerinterval in miliseconds)

StartTimer()   --starts the timer

OnTimer()  --code to be executes when timerinterval has passed

StopTimer()  --stops the timer

PtokaX forum

Re: HOW-TO: Write you own bot = Lesson 9
« Reply #24 on: 29 May, 2006, 14:30:55 »