Author Topic: HOW-TO : Write your own Bot = Lesson 1  (Read 12039 times)

0 Members and 1 Guest are viewing this topic.

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
HOW-TO : Write your own Bot = Lesson 1
« on: 12 October, 2003, 15:42:49 »
First of all you need to have an idea of what its gonna do, for this example we'll make a little welcome msg's for connecting users



For the functions

--function --all functions must begin with this

function NewUserConnected(user) --this is a ptokax standard
SendToAll("J???","Welcome our new guest "..user.sName..", enyot your stay") --SendToAll --remember cap sensitive, sendtoall is differ to SendToAll
end -- function

function OpConnected(user)
SendToAll("J???","WElcome our Op "..user.sName" hope he enjoys his stay")
end --function

now we have a little script, keep awaiting lesson 2 ;)

the script without comments

Code: [Select]



function NewUserConnected(user)
SendToAll("J???","Welcome our new guest "..user.sName..", enyot your stay")
end

function OpConnected(user)
SendToAll("J???","WElcome our Op "..user.sName" hope he enjoys his stay")
end



now why write so much for the bots name, lets make it easier

Code: [Select]

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



-phatty
« Last Edit: 12 October, 2003, 15:58:54 by (uk-kingdom)pH?tt? »
Resistance is futile!

PtokaX forum

HOW-TO : Write your own Bot = Lesson 1
« on: 12 October, 2003, 15:42:49 »

Offline SaintSinner

  • Lord
  • ***
  • Posts: 293
  • Karma: +1/-0
(No subject)
« Reply #1 on: 12 November, 2003, 16:10:26 »
hello proffesor phatty
is school still in session :D
i tried writing this bot but i only get this
Syntax Error: attempt to call field `sName' (a string value)
even when i copy and paste your script to see if i was doing something wrong i get the same error
   


Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #2 on: 12 November, 2003, 16:20:26 »
nope this is perfect :P

Code: [Select]

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




well keep going there is 5 lessons so far ;)
Resistance is futile!

Offline SaintSinner

  • Lord
  • ***
  • Posts: 293
  • Karma: +1/-0
(No subject)
« Reply #3 on: 12 November, 2003, 16:32:03 »
yes proffesor i fixed it
the error came from

Code: [Select]


function OpConnected(user)
SendToAll(Bot,"WElcome our Op "..user.sName" hope he enjoys his stay")
end


there are no dots after the "..user.sName" so when i tried to logon with as operator it gave me the error message, and no greeting, but when i added .. it works with no errors and the welcome message.

whadathink?  :]
   


Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #4 on: 12 November, 2003, 16:45:44 »
very good ;)
Resistance is futile!

Offline SaintSinner

  • Lord
  • ***
  • Posts: 293
  • Karma: +1/-0
(No subject)
« Reply #5 on: 12 November, 2003, 17:41:01 »
thank you

how come you write
function OpConnected(user)<----(user)
and the ptokax scripting text show that the function is

function OpConnected(curUser),<---(curUser)

any diffrence in the functions, must not be huh

i did finished my first bot....YAAYY
Code: [Select]
Bot = "Archangel"

function NewUserConnected(user)
SendToAll(Bot, "Hello there jerkynuts "..user.sName.." how are you today")
end
function OpConnected(user)
SendToAll(Bot, "Bow before the "..user.sName.." feel his wrath!!!")
end
one question though how can i add the users profile in the SendToAll message? ie
Bow before the "..profile here.." "..user.sName.." feel his wrath!!!
i tried looking at the scripting text
and i tried


GetProfileIdx(profile_name)
that gives me
Bow before the -1saintsinner feel his wrath!!!

am i jumping ahead of myself?
will that be left for the next lesson, ok off to try a few more welcome messages and im off to lesson two.
   


Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #6 on: 12 November, 2003, 18:17:58 »
i will include that in lesson 6
there is 4 more lessons atm for you ;)
Resistance is futile!

Markitos

  • Guest
(No subject)
« Reply #7 on: 21 May, 2005, 10:12:13 »
Quote
Originally posted by (uk-kingdom)pH?tt?
First of all you need to have an idea of what its gonna do, for this example we'll make a little welcome msg's for connecting users



For the functions

--function --all functions must begin with this

function NewUserConnected(user) --this is a ptokax standard
SendToAll("J???","Welcome our new guest "..user.sName..", enyot your stay") --SendToAll --remember cap sensitive, sendtoall is differ to SendToAll
end -- function

function OpConnected(user)
SendToAll("J???","WElcome our Op "..user.sName" hope he enjoys his stay")
end --function

now we have a little script, keep awaiting lesson 2 ;)

the script without comments

Code: [Select]



function NewUserConnected(user)
SendToAll("J???","Welcome our new guest "..user.sName..", enyot your stay")
end

function OpConnected(user)
SendToAll("J???","WElcome our Op "..user.sName" hope he enjoys his stay")
end



now why write so much for the bots name, lets make it easier

Code: [Select]

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



-phatty
Hi patty im trying to create ma one script but i always get an error. I've tried the script full (posted by u) but it still givin an error Syntax Error: attempt to call field `sName' (a string value)
heres the script
Code: [Select]
Bot = "1st"



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


Best regards

[NL]Pur

  • Guest
(No subject)
« Reply #8 on: 21 May, 2005, 10:29:32 »
Code: [Select]
Bot = "1st"



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[COLOR=red]..[/COLOR] " hope he enjoys his stay")


end



add the .. to concat the string after that.

Markitos

  • Guest
(No subject)
« Reply #9 on: 21 May, 2005, 10:37:23 »
Quote
Originally posted by [NL]Pur
Code: [Select]
Bot = "1st"



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[COLOR=red]..[/COLOR] " hope he enjoys his stay")


end



add the .. to concat the string after that.
Thnks!!! It worked great, now im going to lesson 2 :-)

Cheers...

Offline enigma

  • Member
  • ***
  • Posts: 44
  • Karma: +2/-0
(No subject)
« Reply #10 on: 04 November, 2005, 19:44:44 »
i want the message to be like
Welcome to XXX hub.
when u join hub [ mesage only for ur eyes]
for both newuserconnected and opconnected
and wat to replace for sendtoall ??

better some1 post a simple code :P
thank u
« Last Edit: 04 November, 2005, 19:45:48 by enigma »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #11 on: 04 November, 2005, 20:10:56 »
user:SendData(Bot,"Welcome our new guest "..user.sName..", enyot your stay")
Everything could have been anything else and it would have just as much meaning.

Offline enigma

  • Member
  • ***
  • Posts: 44
  • Karma: +2/-0
(No subject)
« Reply #12 on: 04 November, 2005, 21:46:50 »
thank u

Offline MetalPrincess

  • Junior Member
  • **
  • Posts: 17
  • Karma: +1/-0
    • Metal Bootleg Database
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #13 on: 01 July, 2006, 13:42:36 »
Cool works well thanks :D Is there a place where I can find other commands so I can finish writing my little bot?

Offline Psycho_Chihuahua

  • Systemspecialist IT
  • Emperor
  • **
  • Posts: 1 054
  • Karma: +112/-1
  • I am wherever i want to be
    • PtokaX Luaboard
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #14 on: 01 July, 2006, 14:22:17 »
have a peek in the ScriptingInterface.txt that comes along with PtokaX ;)

that first, otherwise you could also search through the scripts here or in the PtokaX Scriptdb and pick out certain functions from other scripts to use in your own one.

If you run into probs you can post what you have, along with its error and i'm sure someone would be able to help you along :D
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Offline MetalPrincess

  • Junior Member
  • **
  • Posts: 17
  • Karma: +1/-0
    • Metal Bootleg Database
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #15 on: 02 July, 2006, 16:42:27 »
Thanks I'll give that a whirl :D

MP

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #16 on: 12 November, 2006, 20:50:24 »
user:SendData(Bot,"Welcome our new guest "..user.sName..", enyot your stay")

If I want to display my hub name in tht message, thn wat shud I do??
like:
Welcome To Paradise Hub Mr.<username>, enjoy ur stay
Thanking You,

speedX

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #17 on: 12 November, 2006, 21:45:10 »
If I want to display my hub name in tht message, thn wat shud I do??
like:
Welcome To Paradise Hub Mr.<username>, enjoy ur stay

You can write anything between the quotation marks
Example
Code: [Select]
user:SendData(Bot,"Welcome To Paradise Hub Mr. "..user.sName..", enjoy ur stay")

Or maybe you can pull this from your hub:
Code: [Select]
user:SendData(Bot,"Welcome To "..frmHub:GetHubName().." Mr. "..user.sName..", enjoy ur stay")
« Last Edit: 12 November, 2006, 22:15:53 by Naithif »

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #18 on: 13 November, 2006, 04:59:10 »
Thx Naithif

And If I want to show the profile name also thn??
like:
Welcome Reg User <username>
Thanking You,

speedX

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #19 on: 13 November, 2006, 07:01:20 »
Hi

That's only a little bit from there
Let's check PtokaX Scripting-Interface.txt

Quote
User.
-----
..
iProfile
..

'i' means it's an integer, but we need it as a text, so let's find another command in the text file

Quote
Profiles
-------
..
GetProfileName(ProfileNumber)      - Return ProfileName or nil for failed
..

This should do the trick
However it will return "nil" for User so another addition is needed
Let's add a variable called 'rank'. We need it because we want to modify it's value if it comes as 'nil'

Code: [Select]
rank = GetProfileName(user.iProfile)
if rank == nil then rank = "User"; end

First line makes rank equal to the profile's name that we got the number to
The second line makes rank = 'User' if it returns as nil because of the above
So this (Welcome Reg User <username>) would be

Code: [Select]
rank = GetProfileName(user.iProfile); if rank == nil then rank = "User"; end
user:SendData(Bot,"Welcome "..rank.." User "..user.sName)

This should be under the
Code: [Select]
function NewUserConnected(user)
Part because we added 'User' into the text (So it would became 'Welcome Reg User <username> and Welcome VIP User <username>)
Operators and masters shouldn't be called like that (OP User? ;D), but I believe you can mod their part  ;)

Edit: Oops made a mistake, this way a User gets  'User User'
Check this bit for correction

Use this one

Code: [Select]
rank = GetProfileName(user.iProfile)
if rank == nil then rank = "User"; user:SendData(Bot,"Welcome "..rank.." "..user.sName)
else user:SendData(Bot,"Welcome "..rank.." User "..user.sName); end


That would mean that we create a different case if the user's a User to do not show 'User' extension (like with OPs ;) )
You could do it short as
(Don't use this one)
Code: [Select]
rank = GetProfileName(user.iProfile)
if rank == nil then rank = ""; end
user:SendData(Bot,"Welcome "..rank.." User "..user.sName)
This would only leave one 'User' word, but f**** up spaces and it looks bad for me

Cheers
« Last Edit: 13 November, 2006, 07:16:42 by Naithif »

Herodes

  • Guest
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #20 on: 13 November, 2006, 07:35:46 »
This whole series of HOW-TO should really really be moved to the wiki ;)

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #21 on: 13 November, 2006, 07:57:44 »
My guess would be that more people read these here than in the wiki - but they would be nice there too
And I like these tutorials, they're good for newbies (like me) :)

Offline JueLz

  • Double Ace
  • *
  • Posts: 103
  • Karma: +8/-14
  • HT 500
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #22 on: 13 November, 2006, 13:46:53 »
Hello Teachers
What is the
function to Register a Bot?
I am owner of the MzDistortion? Empire
the addy to my hub is mzdistortion.no-ip.org
____________________________________________
--=                        [HT 500]                          =--

Herodes

  • Guest
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #23 on: 13 November, 2006, 14:04:22 »
Hello Teachers
What is the
function to Register a Bot?
Please take a look at the Scripting-interface inside the PtokaX folder...
Code: [Select]
frmHub
------
RegBot(BotName) - Chars $|<>:?*"/\ and space not allowed, max length 64 chars. Here hub not create myinfo, you need for compatibility with some clients (DC2) to send bot myinfo by script !
RegBot(BotName, bIsOP, Description, Email) - Chars $|<>:?*"/\ and space not allowed in nick, $| not allowed in Description and Email, max length 64 chars per string. IsOP is number, 1 = have key, 0 = not have key. With this is created $MyINFO for bot !!! If you want $MyINFO without key/description/email use for example RegBot("botname", 0, "", "")
use like frmHub:RegBot(...)

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #24 on: 13 November, 2006, 15:03:10 »
Teachers LOL - would be funny :D

Jut don't forget to put it into "function Main()" function for example as it would be weird that the bot gets regged only on userconnect for example  :)

Code: [Select]
function Main()
frmHub:RegBot(Bot)
end

Just don't forget do define your bot's name previously
Code: [Select]
Bot = "Write_any_name_here"
Anyway I don't understand why the inbuilt 1 bot isn't enough in PtokaX :)
Code: [Select]
Bot = frmHub:GetHubBotName()And you get a 'Bot' called bot who's name equals the what you've set in your hub, no need to register it, and it should be capable of doing anything  :D

PtokaX forum

Re: HOW-TO : Write your own Bot = Lesson 1
« Reply #24 on: 13 November, 2006, 15:03:10 »