PtokaX forum

Development Section => HOW-TO's => Topic started by: pHaTTy on 19 December, 2003, 20:36:44

Title: HOW-TO: Write you own bot = Lesson 9
Post by: pHaTTy 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 :


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.....




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



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


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
Title: ??
Post by: Tarokkk on 23 December, 2003, 11:15:30
What is TWAT in the script ?

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

Title:
Post by: Tarokkk on 23 December, 2003, 11:18:47
Oh I'm sorry :D I know what is it ...

twat = user :D
Title:
Post by: pHaTTy 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 ;)
Title:
Post by: Tarokkk on 23 December, 2003, 19:45:25
I think this script don't work

twat nil value ......
Title:
Post by: pHaTTy on 23 December, 2003, 19:50:16
well a mistake on ur end or you using an old ptokax ;)

works for me :P
Title:
Post by: Tarokkk 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)
--
Title:
Post by: NotRabidWombat 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
Title: THX
Post by: Tarokkk on 23 December, 2003, 20:15:36
IT's Gooood :D
Title: I did that but...
Post by: Tarokkk 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

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
Title:
Post by: Intel 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 :)
Title:
Post by: SaintSinner on 05 January, 2004, 15:10:37
QuoteOriginally 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

Title:
Post by: pHaTTy on 05 January, 2004, 15:18:52
QuoteOriginally posted by SaintSinner
QuoteOriginally 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 :)
Title:
Post by: Intel 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 ?
Title:
Post by: pHaTTy 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....
Title:
Post by: Intel 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.. ?


Quotemaybe wrong question in the wrong place but just shootes it out in the blue air....
Title:
Post by: pHaTTy 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 :)
Title:
Post by: NotRabidWombat 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
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Gazza-95 on 20 April, 2006, 18:36:57
phatty how long till the next lesson
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi 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 ...
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: 6Marilyn6Manson6 on 28 May, 2006, 23:11:41
Quote from: Znupi 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 ...

--Killbot LUA5
--
--by Mutor
--
--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 ^_^
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi on 28 May, 2006, 23:14:50
ThX !! Damn u were fast ...
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: 6Marilyn6Manson6 on 29 May, 2006, 08:05:32
Welcome ;)
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi 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 ...
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: CrazyGuy 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
Title: Not Tested - but maybe a good guess ;)
Post by: Psycho_Chihuahua on 29 May, 2006, 16:46:01
Here a Script Noobs try  ;D

Not quite sure where to place the StartTimer(Delay*1000) so here 2 possibilities - maybe 1 is correct ^^

Try Nr. 1
--Killbot LUA5
--
--by Mutor
--
--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"
Delay = 3 -- Delay in Seconds
--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+)")
StartTimer(Delay*1000)
if cmd=="!killbot" then
OnTimer()
frmHub:UnregBot(name)
StopTimer()
return 1
elseif cmd=="!listbot" then
OnTimer()
frmHub:RegBot(name)
StopTimer()
return 1
end
end
end


or

Try Nr. 2
--Killbot LUA5
--
--by Mutor
--
--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"
Delay = 3 -- Delay in Seconds
--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
StartTimer(Delay*1000)
OnTimer()
frmHub:UnregBot(name)
StopTimer()
return 1
elseif cmd=="!listbot" then
StartTimer(Delay*1000)
OnTimer()
frmHub:RegBot(name)
StopTimer()
return 1
end
end
end
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi on 30 May, 2006, 18:25:36
Is there any way in which I can select a character from a variable? :D
Example : a="asdfgh" ... smth like a[2] should be equal to "s"
Does this exist ? (sry my noobness ... im very new to LUA ... and it barely resembles a bit of C++ ... which I pretty am familiar with ...)
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Dessamator on 30 May, 2006, 19:38:02
Indeed there is,
string.sub("asdfgh",2)
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Herodes on 30 May, 2006, 19:46:57
Znupi: Thats one hell of an avatar... :)
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi on 30 May, 2006, 21:09:55
Quote from: Dessamator on 30 May, 2006, 19:38:02
Indeed there is,
string.sub("asdfgh",2)
:D ThX
Quote from: Herodes on 30 May, 2006, 19:46:57
Znupi: Thats one hell of an avatar... :)
Yep :D
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi on 30 May, 2006, 21:58:22

Bot = "PalaSh"

SendC = SendToAll
i=1
mes = " PalaSh e un mare idiot"
a = ""

function Main()
SetTimer(10000)
StartTimer()
end

function OnTimer()
a = string.sub(mes,i)
SendC(Bot,a)
i = i + 1
if ( i == 22 ) then
i = 1
end
end

Tryed this ... but id don't work :( ... :

stack traceback:
   1:  function `OnTimer' at line 21 [file `...op\Quickie\PtokaX_0.330_15.25\scripts\TimeR.lua']

Why ... ? :D (sorry if im annoying ...)
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Thor on 30 May, 2006, 22:34:23
I tried it, just set timer to 1 secs:

[2006. 05. 30. - 23:29:16] <PalaSh>? PalaSh e un mare idiot
[2006. 05. 30. - 23:29:17] <PalaSh> PalaSh e un mare idiot
[2006. 05. 30. - 23:29:18] <PalaSh> alaSh e un mare idiot
[2006. 05. 30. - 23:29:19] <PalaSh> laSh e un mare idiot
[2006. 05. 30. - 23:29:20] <PalaSh> aSh e un mare idiot
[2006. 05. 30. - 23:29:21] <PalaSh> Sh e un mare idiot
[2006. 05. 30. - 23:29:22] <PalaSh> h e un mare idiot
[2006. 05. 30. - 23:29:23] <PalaSh>? e un mare idiot
[2006. 05. 30. - 23:29:24] <PalaSh> e un mare idiot
[2006. 05. 30. - 23:29:25] <PalaSh>? un mare idiot
[2006. 05. 30. - 23:29:26] <PalaSh> un mare idiot
[2006. 05. 30. - 23:29:27] <PalaSh> n mare idiot
[2006. 05. 30. - 23:29:28] <PalaSh>? mare idiot
[2006. 05. 30. - 23:29:29] <PalaSh> mare idiot
[2006. 05. 30. - 23:29:30] <PalaSh> are idiot
[2006. 05. 30. - 23:29:31] <PalaSh> re idiot
[2006. 05. 30. - 23:29:32] <PalaSh> e idiot
[2006. 05. 30. - 23:29:33] <PalaSh>? idiot
[2006. 05. 30. - 23:29:34] <PalaSh> idiot
[2006. 05. 30. - 23:29:35] <PalaSh> diot
[2006. 05. 30. - 23:29:36] <PalaSh> iot
[2006. 05. 30. - 23:29:37] <PalaSh>? PalaSh e un mare idiot
and so on..

So it works? ;D
Maybe a little thing to change:

if ( i == 22 ) then

to

if ( i == string.len(mes) ) then
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi on 02 June, 2006, 08:17:41
Seems I had some old version of PtokaX ... coz i got the latest 1 and it worked  :D
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi on 10 June, 2006, 15:34:18
Ok ... I made this pretty cool bot ... I was thinking maybe it can be used as Lesson 10 :D ... Where can I post it so it can be analized and accepted / denied ?  ;D
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Znupi on 10 June, 2006, 23:29:06
I got pretty dissapointed 'coz someone revealed to me my coding inability ... I will not post my bot

And it pretty much doesn't resemble the bot developed so far ... I kind of started from scratch ... don't think it would be suitable ... dunno ...
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: ((KMN))Gazza-95 on 20 August, 2006, 22:44:46
phatty how long till next lesson its bin a while :)
Title: Re: HOW-TO: Write you own bot = Lesson 9
Post by: Herodes on 21 August, 2006, 07:31:15
Quote from: ((KMN))Gazza-95 on 20 August, 2006, 22:44:46
phatty how long till next lesson its bin a while :)

I think that phatty sadly has turned his interest on other places .. he hasn't been on the board for a long time .. possibly for about a year now ..