Jump to content

Welcome to Pure Warfare - The #1 Community for Pures

Welcome to Pure Warfare - The #1 Community for Pures, like most online communities you must register to view or post in our community, but don't worry this is a simple free process that requires minimal information for you to signup. Be apart of Pure Warfare - The #1 Community for Pures by signing in or creating an account.
  • Start new topics and reply to others
  • Subscribe to topics and forums to get email updates
  • Get your own profile page and make new friends
  • Send personal messages to other members.

[Tutorial] Writing your first script.


Recommended Posts

Your First Script



This tutorial is to help users who are brand new to mSL learn the basic process of writing a script. I will be assuming that you have already ready my An Introduction to mSL guide. A popular script amongst new coders is a "Perform" script. This is where the owner of the bot is able to make their bot perform commands remotely, such as ".do msg #PureWarfare Hey!" or ".do join #PureWarfare", etc. I will be walking you through the steps of how to make one of these scripts.




Step One - The trigger.



All remote scripts require a trigger to activate them. For this particular one, we will be using a TEXT trigger. A text trigger looks like this:

on <level>:TEXT:<matchtext>:<*><?><#[,#]>:<commands>


When we add in our parameters, ours will be:
ON *:TEXT:.do*:#: {}



This means that the script will trigger when any users says a line that begins with ".do" in any channel. Don't worry, we'll add security later!

Notice how I added an opening and closing bracket. These brackets will contain the entire script - all of your work for this script should go inside of these brackets.

Step Two - Just Checking



Now, because our trigger is ".do*" (note the wildcard), it will trigger on any line which begins with ".do". This means it will trigger on: ".do", ".do-hicky", ".dododododod", ".doyouunderstand?", etc. For this reason, we're just going to add an "if" statement to remember that the script and the user are on the same page.

if ($1 == .do) {



By using this statement, we make sure that the trigger the user is using is ".do", and nothing else. Now let's add it to our script. Don't forget to close that bracket!

ON *:TEXT:.do*:#: {  if ($1 == .do) {  }}



Now if we put our script within the brackets of that "if" statement, we'll be fine.

Step Three - Who goes there?



We don't want just anybody controlling your bot. For this script, we'll make it usable for you only. As it is not safe to do a check for a nickname (anybody could switch to your nickname and control your bot), we'll compare the address of the bot to the address to the nick. If they're the same (meaning on the same computer), then we'll continue.

if ($address($nick,2) == $address($me,2)) {



Now let's add that in, and once again don't forget to close that bracket!

ON *:TEXT:.do*:#: {  if ($1 == .do) {	if ($address($nick,2) == $address($me,2)) {	}  }}



Now we've made sure only you can use this script. But just for giggles, let's let users know when they've been thwarted by adding an "else" line after that "if" line. That means if the user is NOT you, it will perform the "ELSE" action, in this case, informing them that you won't be abused that easily!

else {



Let's add it in there after your if statement, with a little message within the brackets.

ON *:TEXT:.do*:#: {  if ($1 == .do) {	if ($address($nick,2) == $address($me,2)) {	}	else {	  notice $nick Access denied!	}  }}



Step Four - Get to work!



Now that we've made sure your thoughts and the bot's are on the same page, and that the person using this is actually you, let's make the bot do what we tell it to.

 $($2-,2)



$() is an evaluation identifier. We will use this so that you can use things such as "#" (to return the channel name), $nick, and variables within the command, and the bot will evaluate them.

ON *:TEXT:.do*:#: {  if ($1 == .do) {	if ($address($nick,2) == $address($me,2)) {	  $($2-,2)	}	else {	  notice $nick Access denied!	}  }}



Step Five - Enjoy.



That's it! You're all done! Now you can remotely control your bot, and feel safe doing it. Go ahead, give it a shot, ".do msg # Hey there!". You're the boss now!

Congratulations, you've made your first script.

- Jay

emmawatsonjay.png

34rfuk5.png

(+`Obsession) jay is a legend

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
  • Create New...