HOW-TO : Write your own Bot = Lesson 1
 

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 your own Bot = Lesson 1

Started by pHaTTy, 12 October, 2003, 15:42:49

Previous topic - Next topic

0 Members and 5 Guests are viewing this topic.

pHaTTy

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
Resistance is futile!

SaintSinner

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
   


pHaTTy

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 ;)
Resistance is futile!

SaintSinner

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?  :]
   


pHaTTy

Resistance is futile!

SaintSinner

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.
   


pHaTTy

i will include that in lesson 6
there is 4 more lessons atm for you ;)
Resistance is futile!

Markitos

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

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

Markitos

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

enigma

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

bastya_elvtars

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.

enigma


MetalPrincess

Cool works well thanks :D Is there a place where I can find other commands so I can finish writing my little bot?

Psycho_Chihuahua

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


speedX

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
Thanking You,

speedX

Naithif

#17
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")

speedX

Thx Naithif

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

speedX

Naithif

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

Herodes

This whole series of HOW-TO should really really be moved to the wiki ;)

Naithif

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

JueLz

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

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

Naithif

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

SMF spam blocked by CleanTalk