Fundamentals of Sad Scripting

           XtremeWorlds (XW) is a free MMORPGmaker. It is very stable and has some good features, but you won't be able to make a descent game with it unless you learn how to use the scripting system. So what is the scripting system of XW? XW uses a scripting language called "Sad Script" which is a corrupted, or "dumb downed" version of VB-Script 6.

          The first thing you need to know about with Sad Scripting is Subs. The default Subs are called by either a button in the game, or something else that happens in the game. You can also make your own subs that can be called out of other subs, but we will talk about that more later.

          So how do you make a sub? Well first name it, Example: Sub "Subs Name"(Index) Change "Subs Name" to whatever you want. Make sure you put the Sub somewhere not in another Sub or Function. Then you need to End the Sub to do so Type "End Sub" on the next line below your subs name. We will call this Sub "Test" Your Sub should look like this: 

Sub Test(Index)
End Sub           

Now we need to learn how to do something with a sub. To do this we need to tell the server what to do, we do this with calls. Here are some example calls.

Call PlayerMsg(Index,"Example message." , C_CYAN)
Call PlayerWarp(Index, Map, X, Y)
Call SetPlayerLevel(Index, N)
Call SetPlayerSprite(Index, SpriteNumber)
Call GlobalMsg(Index,"Example message." , C_CYAN)
Call GiveItem(Index, ItemNum, Amount)
Call TakeItem(Index, ItemNum, Amount)

These are just a few of the many calls you can use to do different things.  Now lets make our Sub do something.

Sub Test(Index)
Call PlayerMsg(Index,"This sub works!, C_CYAN)
End Sub 

        Now your sub will tell you that it works when it is called. That means we need to learn how to call Subs. There are several ways to call Subs, but we are going to just use select case parse. Open your Script Editor, and scroll down till you see select case parse. You will see some purple text under it. Click between "Select Case Parse", and the text that's already there. Press enter a couple times, and then the up arrow key. This is to make sure you don't mess up your script. Now put this under Select Case Parse.

Case"/Test"
Call Test(Index)

        This will call the Sub you made earlier. To call it save your script, wait for a message that says "Server Script Updated Successfully", and type /Test In the chat window of the game. You should see a message that says "This sub works!". If you don't see this message, go back through the previous steps and see what you did wrong.

         That was just an example of how to call a sub, but you can just put calls in an existing sub to do the same thing. So this would do the same thing as the first script.

Case"/Test"
Call PlayerMsg(Index, This Script Works!" C_CYAN)

          So now we will learn about IFs, IFs are very important when it comes to scripting. An IF checks to see if something is true and if it's not, the script ends. So if you have a script like this.

If GetPlayerMap = 5 Then
Call PlayerMsg(Index,"You are on map number 5", C_CYAN)
End If

          It will only call your message if you are on map 5. This example is kind of useless but it is to teach you how to use IFs. So what all can you check with IFs? Well almost anything, here are some examples.

If GetPlayerMap(Index) = "Map Number" Then
If GetPlayerX(Index) = "X Position" Then
If GetPlayerY(Index) = "Y Position" Then
If GetPlayerClassID(Index) = "Class Number" Then
If GetPlayerLevel(Index) = "Player Level" Then
If HasItem(Index, (ItemNum)) Then

        You can use an IF to check anything that you can use a call to set something in your game. Now we'll learn where to put certain IFs. For instance to check if a player is at a certain spot put it under "Select Case Map".

          So here are some example Scripts for you to study to learn how to do what you want.

In Sub UseItem(Index)

If ItemNum = 5 Then
If GetPlayerMap(Index) = 8 Then
If GetPlayerX(Index) = 6 And GetPlayerY(Index) = 4 Then
Call GiveItem(Index, 12, 1)
Call PlayerMsg(Index, "You picked some berries", C_CYAN
End If
End If
End If

In Select Case Map

Case 4 ' Case 4 = Map 4, Case 6 = Map 6 ect.
If GetPlayerX(Index) = 5 And GetPlayerY = 7
Call PlayerWarp(Index, 12, 5, 8)
Call PlayerMsg(Index, "You were warped to the Arena", C_CYAN
End If

In Sub JoinGame

If GetPlayerLevel(Index) < 5 Then
Call PlayerMsg(Index, "Hint, Use the arrow keys to move, and Ctrl. to talk to NPCs.
End If

           It is always important to put as many End IFs after the calls, as you have IFs.

          Now we will go over how you compare things. You can use this If GetPlayerLevel(Index) = 5 or, If GetPlayerLevel(Index) < 5 or If GetPlayerLevel(Index) > 5. You can even combine two of these such as  If GetPlayerLevel(Index) => 5

          The last thing to go over is variables, variables can make things less wordy, for instance if you  put this at the top of a sub.

Map = GetPlayerMap(Index)
X = GetPlayerX(Index)
Y = GetPlayerY(Index)

Then you can just put Map instead of GetPlayerMap(Index) every time in that sub. For Example.

This:

If ItemNum = 5 Then
If GetPlayerMap(Index) = 8 Then
If GetPlayerX(Index) = 6 And GetPlayerY(Index) = 4 Then
Call GiveItem(Index, 12, 1)
Call PlayerMsg(Index, "You picked some berries", C_CYAN)
End If
End If
End If

Can become This:

If ItemNum = 5 Then
If Map = 8 Then
If X = 6 And Y = 4 Then
Call GiveItem(Index, 12, 1)
Call PlayerMsg(Index, "You picked some berries", C_CYAN)
End If
End If
End If

         You can see how this would make things easier for things that you will be checking or calling often. Those are the basics good luck scripting, and if you have a question feel free to post a comment.

HTML Comment Box is loading comments...