From lesson 1 we have
Bot = "J???"
function NewUserConnected(user)
SendToAll(Bot,"Welcome our new guest "..user.sName..", enyot your stay")
end
function OpConnected(user)
SendToAll(Bot,"WElcome our Op "..user.sName" hope he enjoys his stay")
end
--now to add some more functions
to add the bot on the userlist is frmHub:RegBot(Bot)
so
function Main()
frmHub:RegBot(Bot)
end
then for a version command, we will need data arrival, the data arrival is the incoming data hence arrrival
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+)") -- this converts it into cmd (the incoming data)
if cmd == "version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version)
return 1
end
end
end
--now we have the data arrival we need the variable ie ..version
so we add :
version = "o.2 by Phatty"
now we have so far
Bot = "J???"
version = "o.2 by Phatty"
function Main()
frmHub:RegBot(Bot)
end
function NewUserConnected(user)
SendToAll(Bot,"Welcome our new guest "..user.sName..", enyot your stay")
end
function OpConnected(user)
SendToAll(Bot,"WElcome our Op "..user.sName" hope he enjoys his stay")
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 == "!version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version)
return 1
end
end
end
more to come as i get more time :o)
-phatty
wow i undersantd this is geting cool umm could you for your next lesson teach disable raw functions such as kick or mainchat or etc
You mean stop !ban etc etc?
is this
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+)") -- this converts it into cmd (the incoming data)
always come before a command
or is one time at the begining of the script?
so
function DataArrival(user,data)
blah blah blah
and then the command ...!ban
function DataArrival(user,data)
blah blah blah
and then the command ...!kick
function DataArrival(user,data)
blah blah blah
and then the command ...!version
is this correct
heheh well you will see on the next lesson ;)
Hi there,
You cannot use several DataArrival functions into 1 single script,... you can,, lol,... but it won't work properly,... ;)
Once the code defined about the way to find a command (there, 'cmd',,), use ' elseif ',... by example:
---------
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 == "!version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version)
return 1
end
elseif cmd == "!yourcmd1" then
-- Do your code there
return 1 -- use 'return 1' if you don't want the command showed on the main
end
elseif cmd == "!yourcmd2" then
-- Do your code there
-- none 'return 1',... cmd is visible to all
end
end
end
---------
Good luck, & good scripts,,, :)
l8tr,, ;)
Guibs dont worry its all in the next few lessons, i dont see why peeps ask questions b4 they ahve looked all the way thru them ;)
QuoteOriginally posted by (uk-kingdom)pH?tt?
Guibs dont worry its all in the next few lessons, i dont see why peeps ask questions b4 they ahve looked all the way thru them ;)
just curiosity i guess
:]
ghehehe ok :o)
I dont understand what this is
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+)") -- this converts it into cmd (the incoming data)
should this just be copy paste or could u give an small explanation on it ?? Actually i can just copy paste but i like to understand it...if possible :P
In lesson 1, the script worked without registering the bot, does this work for every kind of script or is registering the bot required for the script to run? [excluding scripts like opchat where it's necessarry to reg the bot]
Also what is dataarrival shown later in the script?
Thanx,
|Cain|
Ok more than 1 Data Arrival doesnt work hmmm
but the how would i combine
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+)")
end
if (cmd=="!help") then
if user.iProfile == nil then
SendUserhelp(user)
return 1
elseif user.iProfile == 0 then
SendMasterhelp(user)
return 1
elseif user.iProfile == 1 then
SendOpshelp(user)
return 1
elseif user.iProfile == 2 then
SendViphelp(user)
return 1
elseif user.iProfile == 3 then
SendReghelp(user)
return 1
elseif user.iProfile == 4 then
SendModeratorhelp(user)
return 1
end
elseif (cmd=="!lol") then
SendLol(user)
return 1
elseif (cmd=="!rules") then
SendRules(user)
return 1
elseif (cmd=="!network") then
SendNetwork(user)
return 1
elseif (cmd=="!faq") then
SendFaq(user)
return 1
elseif (cmd=="!description") then
SendDescription(user)
return 1
elseif (cmd=="!showreg") then
showreg(user)
return 1
elseif (cmd == "!myip" ) then
user:SendData(BOTName,"Deine Ip lautet: "..user.sIP)
return 1
elseif (cmd == "!myversion" ) then
user:SendData(BOTName,"Deine Client Version ist: "..user.iVersion)
return 1
elseif (cmd == "!addreguser") then
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
user:SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
elseif (cmd == "!me") then
AddAChatter(user)
return 0
end
local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)%|$")
if s and ptokaxcommands[cmd] then
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)%|$")
if s and ptokax2commands[cmd] then
if user.iProfile == 1 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
elseif (cmd == "!restartscripts") and user.iProfile == 0 then
return 0
elseif (cmd == "!restart") and user.iProfile == 0 then
return 0
end
end
end
with this function DataArrival( sUser , sData )
if strsub( sData , 1 , 7 ) == "$MyINFO" then
local _,_,openhubs = strfind( sData , ".+H:(%d+)" );
if ( openhubs ~= "0" ) then
SendToNick( sUser.sName , DisconnectMessage )
sUser:Disconnect()
end
end
end
and why? U see i'm still a noobie but my interest is getting stronger by the day :)
Hi,
The first step is to see that the contion that you want to implement has different user and data variable name
function DataArrival([b]user[/b] ,[b]data[/b])
function DataArrival([b]sUser[/b] ,[b]sData[/b])
Try to change to the same.
Best regards, nErBoS
ok, well the easiest to change was this one
function DataArrival( user , data )
if strsub( data , 1 , 7 ) == "$MyINFO" then
local _,_,openhubs = strfind( data , ".+H:(%d+)" );
if ( openhubs ~= "0" ) then
SendToNick( user.name , DisconnectMessage )
user:Disconnect()
end
end
end
and now for the next step :)
Hi,
Now add this...
if strsub( data , 1 , 7 ) == "$MyINFO" then
local _,_,openhubs = strfind( data , ".+H:(%d+)" );
if ( openhubs ~= "0" ) then
SendToNick( user.name , DisconnectMessage )
user:Disconnect()
end
end
...to the other DataArrival.
Best regards, nErBoS
.....
Is it really THAT easy?? ?( hehe
thnx alot nerbos
well to do it a little bit complicated you need when u add more if's in the DataArrival to do it like this with elseif's
function DataArrival( user , data )
if strsub(data, 1,1) == "<" then
-- do mainchat code here
elseif strsub(data, 1,7) == "$MyINFO" then
-- do myinfostring code here
elseif strsub(data, 1,4) == "$To:" then
-- do private message code here
end
end
hope u get the point...
/NL
well i think i got the point...
If this is right that is...
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+)")
end
if (cmd=="!help") then
if user.iProfile == nil then
SendUserhelp(user)
return 1
elseif user.iProfile == 0 then
SendMasterhelp(user)
return 1
elseif user.iProfile == 1 then
SendOpshelp(user)
return 1
elseif user.iProfile == 2 then
SendViphelp(user)
return 1
elseif user.iProfile == 3 then
SendReghelp(user)
return 1
elseif user.iProfile == 4 then
SendModeratorhelp(user)
return 1
end
elseif (cmd=="!lol") then
SendLol(user)
return 1
elseif (cmd=="!rules") then
SendRules(user)
return 1
elseif (cmd=="!network") then
SendNetwork(user)
return 1
elseif (cmd=="!faq") then
SendFaq(user)
return 1
elseif (cmd=="!description") then
SendDescription(user)
return 1
elseif (cmd=="!showreg") then
showreg(user)
return 1
elseif (cmd == "!myip" ) then
user:SendData(BOTName,"Deine Ip lautet: "..user.sIP)
return 1
elseif (cmd == "!myversion" ) then
user:SendData(BOTName,"Deine Client Version ist: "..user.iVersion)
return 1
elseif (cmd == "!addreguser") then
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
user:SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
elseif (cmd == "!me") then
AddAChatter(user)
return 0
end
local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)%|$")
if s and ptokaxcommands[cmd] then
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)%|$")
if s and ptokax2commands[cmd] then
if user.iProfile == 1 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
elseif (cmd == "!restartscripts") and user.iProfile == 0 then
return 0
elseif (cmd == "!restart") and user.iProfile == 0 then
return 0
end
elseif strsub(data, 1,7) == "$MyINFO" then
if strsub( data , 1 , 7 ) == "$MyINFO" then
local _,_,openhubs = strfind( data , ".+H:(%d+)" );
if ( openhubs ~= "0" ) then
SendToNick( user.name , DisconnectMessage )
user:Disconnect()
end
end
end
elseif strsub(data, 1,4) == "$To:" then
DisconnectMessage = "Nachricht kommt hier rein"
end
end
Not right you close the if so the elseif can not be checked...
I sorted it out for ya, look at your code close so you see what I have done.
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=="!help") then
if user.iProfile == nil then
SendUserhelp(user)
return 1
elseif user.iProfile == 0 then
SendMasterhelp(user)
return 1
elseif user.iProfile == 1 then
SendOpshelp(user)
return 1
elseif user.iProfile == 2 then
SendViphelp(user)
return 1
elseif user.iProfile == 3 then
SendReghelp(user)
return 1
elseif user.iProfile == 4 then
SendModeratorhelp(user)
return 1
end
elseif (cmd=="!lol") then
SendLol(user)
return 1
elseif (cmd=="!rules") then
SendRules(user)
return 1
elseif (cmd=="!network") then
SendNetwork(user)
return 1
elseif (cmd=="!faq") then
SendFaq(user)
return 1
elseif (cmd=="!description") then
SendDescription(user)
return 1
elseif (cmd=="!showreg") then
showreg(user)
return 1
elseif (cmd == "!myip" ) then
user:SendData(BOTName,"Deine Ip lautet: "..user.sIP)
return 1
elseif (cmd == "!myversion" ) then
user:SendData(BOTName,"Deine Client Version ist: "..user.iVersion)
return 1
elseif (cmd == "!addreguser") then
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
user:SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
elseif (cmd == "!me") then
AddAChatter(user)
return 0
end
local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)%|$")
if s and ptokaxcommands[cmd] then
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)%|$")
if s and ptokax2commands[cmd] then
if user.iProfile == 1 or user.iProfile == 4 then
return 0
elseif user.iProfile == nil then
SendPM(BOTName, "du bist nicht befugt diesen Befehl auszuf?hren")
end
elseif (cmd == "!restartscripts") and user.iProfile == 0 then
return 0
elseif (cmd == "!restart") and user.iProfile == 0 then
return 0
end
end
elseif strsub(data, 1,7) == "$MyINFO" then
local _,_,openhubs = strfind( data , ".+H:(%d+)" );
if ( openhubs ~= "0" ) then
SendToNick( user.name , DisconnectMessage )
user:Disconnect()
end
elseif strsub(data, 1,4) == "$To:" then
DisconnectMessage = "Nachricht kommt hier rein"
end
end
I hope I did make it all correct with the commands but the strsub's is right...
/NL
ok i wasn't quit sure about that, thnx for the info
you've been a great help you guys
Im confused about the:
if strsub (data,1,1) etc.... what does this line do? Or what does it mean? string...something?
And the (data,) is only there to know that data will arrive? (data is for commands?) I got some more questions though lol :D
some style n00b answers:
if strsub(data,1,1) == "<" then
data is the data that comes in DataArrival
with (data,1,1) == "<" you search for a particular string
and it is only ONE "<" char. this will catch MainChat commands
and put "$To:" that is 4 char. That will look with strsub
strsub(data, 1,4) == "$To:" this will catch all PM messages
hope this helps some don't really have the time answering now, Plop or anyone that is willing to explain better than me plz do... :D
Cheers / NightLitch
strsub(string, start, end)
this lua function s taking resulting in a copy of the 'string'
under the restrictions of 'start' and 'end' both of which are numbers ...
These two ( 'start' , 'end' ) signify the position of the characters in the string. For Example :
string = "what are you talking about"
strsub(string, 1, 1) --- will produce "w"
strsub(string, 2, 6) --- will produce "hat a"
strsub(string, 6, strlen(string)) --- will produce "re you talking about"
As you noticed strlen(string) gives us the 'length' of a string.
in other words it is the characters count in the string ...
Basically in the first strsub example we told lua to say to us what is the string between the first character and the first character (I know it's tricky to understand how)
In the second, we asked lua to give us the string of characters between the second(2) character and the sixth(6) character.
In the third we told lua to give us the string of characters between the sixth(6) character and the product of strlen which effectively is a number that signifies what is the number/position of the last character in the string in question(26) ...
lol well, i think i need some time to think all this through :D SOmedays i dont understand anything, and somedays i understand everything....L0L
thx for info and cheers! // Dj_OcTaGoN
y0 dJ... check out plops howto's... i learned alot about
pattern matching(strfind) and strsub from there...
http://www.plop.nl/howto/howto.php (http://www.plop.nl/howto/howto.php)
-BH
The data arrival isnt working
Posted on: 13 November 2006, 13:45:07
Is it because i am using the last ptokax?
Data Arrival is LUA4... The current PtokaX uses LUA 5.1...
Yip these posts are rather old :)
Try this
function ChatArrival(user, data)
local s,e,cmd = string.find(data, "%b<>%s+(%S+)(%S+)")
if cmd == "!command" then
--*define here what you want to happen when someone types the command, or filter it*
end
end
Of course !command can be changed to anything ;)
This example should be only for a command (!command), no extensions after it, if you want to know it, just ask
hi,
how do show a text file's data on some command input?
and plzz all lord scripters hold it a bit n give the newbe's time to lean n understand :P
thks,
achiever
Hi
Use PtokaX's inbuilt text file support, or if you need to do other things with that, you can find it in lesson 4 (as I remember)
Cheers
Quote from: achiever on 14 November, 2006, 08:25:39
and plzz all lord scripters hold it a bit n give the newbe's time to lean n understand :P
Generally you strike the steel while it hot. In any case you can always read through the forums, threads posts as many times you want, to get the meaning and follow through... ;)