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

0 Members and 1 Guest are viewing this topic.

Offline Psycho_Chihuahua

  • Systemspecialist IT
  • Emperor
  • **
  • Posts: 1 054
  • Karma: +112/-1
  • I am wherever i want to be
    • PtokaX Luaboard
Not Tested - but maybe a good guess ;)
« Reply #25 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
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"
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
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"
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
« Last Edit: 29 May, 2006, 16:51:36 by Psycho_Chihuahua »
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

PtokaX forum

Not Tested - but maybe a good guess ;)
« Reply #25 on: 29 May, 2006, 16:46:01 »

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 #26 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 ...)

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #27 on: 30 May, 2006, 19:38:02 »
Indeed there is,
Code: [Select]
string.sub("asdfgh",2)
Ignorance is Bliss.

Herodes

  • Guest
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #28 on: 30 May, 2006, 19:46:57 »
Znupi: Thats one hell of an avatar... :)

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 #29 on: 30 May, 2006, 21:09:55 »
Indeed there is,
Code: [Select]
string.sub("asdfgh",2)
:D ThX
Znupi: Thats one hell of an avatar... :)
Yep :D

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 #30 on: 30 May, 2006, 21:58:22 »
Code: [Select]
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 :( ... :
Code: [Select]
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 ...)

Offline Thor

  • Scripter
  • Lord
  • ******
  • Posts: 290
  • Karma: +45/-5
    • Hungarian Direct Connect Site
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #31 on: 30 May, 2006, 22:34:23 »
I tried it, just set timer to 1 secs:
Code: [Select]
[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:
Code: [Select]
if ( i == 22 ) then
to
Code: [Select]
if ( i == string.len(mes) ) then
« Last Edit: 30 May, 2006, 22:36:57 by Hungarista »

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 #32 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

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 #33 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
« Last Edit: 10 June, 2006, 15:36:35 by Znupi »

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 #34 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 ...
« Last Edit: 11 June, 2006, 12:32:19 by Znupi »

Offline ((KMN))Gazza-95

  • Junior Member
  • **
  • Posts: 24
  • Karma: +3/-1
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #35 on: 20 August, 2006, 22:44:46 »
phatty how long till next lesson its bin a while :)

Herodes

  • Guest
Re: HOW-TO: Write you own bot = Lesson 9
« Reply #36 on: 21 August, 2006, 07:31:15 »
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 ..

PtokaX forum

Re: HOW-TO: Write you own bot = Lesson 9
« Reply #36 on: 21 August, 2006, 07:31:15 »