Ok, so you made your first script. Only 3 lines long nice and sweet. However - there are some issues with this script. Most notably, ANY creature wondering in to the trigger is going to get jumped to the inside of your chest. This is ok if that is what you want, but we want it to only work if a Player enters the trigger. This is were conditions come into play. By definition Condition is nothing more that a specific decision made by the script based on specific information that your as a scripted give it. A condition is nothing more than "IF" this, then do that. For example, If it rains, take an umbrella.

Conditionals, part 1:

That's the basics of it, I'll cover more on the if/else later as we advance through the tutorial. Now it's time to get back into our script. Open the toolset and load your tutorial_1 mod. Before doing anything else, go to "File > Save As" and save the mod as "tutorial_2". This way if anything goes wrong you can simply back up to the previous tutorial instead of starting from scratch.


Go to the scripts palette and double click the script we made previously, "t_ent_chestgrabber". It should open up into the script editor. We want to add a line to make sure oEnter is a Player. Again, to find a function suited for this we can click in the script filter and enter the word "PC". You will have a few options, but by looking at the notes for each, we can see that the "GetIsPC" function is the one we want. We want to place it after the variable definitions. Lets also add a comment, so enter a blank line after your variables and add the comment "// Check for a Player". Also notice that in the notes for this function, it returns a "int" data type, FALSE if the specified object is not a Player Character and TRUE if the specified object is a Player Character.


Looking back at the syntax for the if statement, we need "if" (obviously) and then a condition between two parenthesis. so type in "if" then open "(" then close ")" and now enter GetIsPC between those parenthesis. For this function we also need a object. In this case the oEnter object, so again after you enter "GetIsPC" open "(" then close ")" and then type "oEnter" between them. Your line should look like this;

After you hit the Enter key, hit the TAB key to indent and then open a new scope with a "{" curly bracket. This is where we will place what we want to happen if the if statement results in TRUE. We already have what we want to happen, that's the "JumpToObject" part so we just need to close our new scope after that section with a "}" curly bracket. Your whole script should look like this;

There are 2 ways you can use the if statement here, by boolean - check for TRUE or FALSE, or by comparison - Check the value of the function to the value of TRUE. The script above is a boolean condition. The function GetIsPC returns a TRUE or FALSE to the statement (As described in it's notes for that function), which results in either TRUE or FALSE. A Comparison condition would look like this;

Here we actually compare the result of the function GetIsPC to the value of TRUE. If the function returns TRUE then they are equal and the if statement results to TRUE. If the comparison is not equal the result is FALSE. Either way is correct, use which ever way makes most sense to you. Personally, I prefer the boolean check myself.


Note really a big change here, but test out your script in game, it should work the same. As an exercise, place a NPC down and add some waypoints for the NPC to walk, making sure that the NPC must walk into the trigger of the chest. You should be able to watch the NPC walk around and not get ported in to the chest. In the next section we will add some animations to liven up our jumping PC.