HOW-TO: Write you own bot = Lesson 9 - Page 2
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

HOW-TO: Write you own bot = Lesson 9

Started by pHaTTy, 19 December, 2003, 20:36:44

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Psycho_Chihuahua

#25
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
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Znupi

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

Dessamator

Indeed there is,
string.sub("asdfgh",2)
Ignorance is Bliss.

Herodes

Znupi: Thats one hell of an avatar... :)


Znupi

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

Thor

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

Znupi

Seems I had some old version of PtokaX ... coz i got the latest 1 and it worked  :D

Znupi

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

Znupi

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

((KMN))Gazza-95

phatty how long till next lesson its bin a while :)

Herodes

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

SMF spam blocked by CleanTalk