PtokaX forum

Development Section => HOW-TO's => Topic started by: pHaTTy on 12 October, 2003, 15:42:49

Title: HOW-TO : Write your own Bot = Lesson 1
Post by: pHaTTy 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




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


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
Title:
Post by: SaintSinner 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
Title:
Post by: pHaTTy on 12 November, 2003, 16:20:26
nope this is perfect :P


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 ;)
Title:
Post by: SaintSinner on 12 November, 2003, 16:32:03
yes proffesor i fixed it
the error came from



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?  :]
Title:
Post by: pHaTTy on 12 November, 2003, 16:45:44
very good ;)
Title:
Post by: SaintSinner 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
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.
Title:
Post by: pHaTTy on 12 November, 2003, 18:17:58
i will include that in lesson 6
there is 4 more lessons atm for you ;)
Title:
Post by: Markitos on 21 May, 2005, 10:12:13
QuoteOriginally 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




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


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
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
Title:
Post by: [NL]Pur on 21 May, 2005, 10:29:32
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.
Title:
Post by: Markitos on 21 May, 2005, 10:37:23
QuoteOriginally posted by [NL]Pur
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...
Title:
Post by: enigma 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
Title:
Post by: bastya_elvtars on 04 November, 2005, 20:10:56
user:SendData(Bot,"Welcome our new guest "..user.sName..", enyot your stay")
Title:
Post by: enigma on 04 November, 2005, 21:46:50
thank u
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: MetalPrincess 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?
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Psycho_Chihuahua 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
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: MetalPrincess on 02 July, 2006, 16:42:27
Thanks I'll give that a whirl :D

MP
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: speedX on 12 November, 2006, 20:50:24
Quote from: bastya_elvtars on 04 November, 2005, 20:10:56
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
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Naithif on 12 November, 2006, 21:45:10
Quote from: speedX on 12 November, 2006, 20:50:24
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

user:SendData(Bot,"Welcome To Paradise Hub Mr. "..user.sName..", enjoy ur stay")


Or maybe you can pull this from your hub:
user:SendData(Bot,"Welcome To "..frmHub:GetHubName().." Mr. "..user.sName..", enjoy ur stay")
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: speedX 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>
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Naithif on 13 November, 2006, 07:01:20
Hi

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

QuoteUser.
-----
..
iProfile
..

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

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

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


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


This should be under the
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



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)

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
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Herodes on 13 November, 2006, 07:35:46
This whole series of HOW-TO should really really be moved to the wiki  (http://www.ptxwiki.psycho-chihuahua.net/);)
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Naithif 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) :)
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: JueLz on 13 November, 2006, 13:46:53
Hello Teachers
What is the
function to Register a Bot?
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Herodes on 13 November, 2006, 14:04:22
Quote from: JueLz on 13 November, 2006, 13:46:53
Hello Teachers
What is the
function to Register a Bot?
Please take a look at the Scripting-interface inside the PtokaX folder...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(...)
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Naithif 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  :)

function Main()
frmHub:RegBot(Bot)
end


Just don't forget do define your bot's name previously
Bot = "Write_any_name_here"

Anyway I don't understand why the inbuilt 1 bot isn't enough in PtokaX :)
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
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: speedX on 13 November, 2006, 15:05:20
Thx for the help Naithif

Quote from: Naithif on 13 November, 2006, 07:57:44
My guess would be that more people read these here than in the wiki

Yup even I agree to this :)
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Naithif on 13 November, 2006, 15:17:17
You're welcome  :)
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Cêñoßy†ê on 13 November, 2006, 15:28:27
Quote from: Naithif on 13 November, 2006, 07:01:20

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


or like this:

user:SendData(Bot,"Welcome "..(GetProfileName(user.iProfile) or "User").." "..user.sName)
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Naithif on 13 November, 2006, 15:35:41
Nice idea :D
I could have shorten it too (not this much though :D), but he asked for "Reg User" and this extension should go only to Reg and VIP
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: speedX on 13 November, 2006, 15:48:39
And wat code to show Welcome Operator speedX or Master speedX?
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Naithif on 13 November, 2006, 16:09:08
You can use any of them

rank = GetProfileName(user.iProfile)
user:SendData(Bot,"Welcome "..rank.." "..user.sName)

(No chance for nil because operator on login can't be user :D)


C??o?y??'s code is good as he pasted it there above
user:SendData(Bot,"Welcome "..(GetProfileName(user.iProfile) or "User").." "..user.sName)
Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: jack_port1000 on 20 June, 2007, 18:02:57
is tat possible to add color in words if yes then in this script some error

[21:21] Syntax ... and Settings\SWAGAT.JAGIRDAR\Desktop\New Folder (3)\scripts\welcome.lua:15: ']' expected near '='



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

Title: Re: HOW-TO : Write your own Bot = Lesson 1
Post by: Psycho_Chihuahua on 20 June, 2007, 18:12:48
no you cannot add colors by scripting
Title: HOW TO Write your own Bot Lesson 1
Post by: JamespaX on 26 March, 2017, 01:20:43
Hi does anyone know how I can get into the chat room?

Thank you