Jump to content

Home

Conditional Scripts


TimBob12

Recommended Posts

Script Condidionals

 

Hello There,

When I was making my Tatooine Job Office (http://www.lucasforums.com/showthread.php?t=206577)

 

I wanted to find how to only make certain conversation options available after certain conditions had been met. Now I couldn't find a dedicated tutorial anywhere so I had to ask.

 

So I thought I'd make it easier by writing this tutorial. This is my first tutorial so go easy on me ;)

 

Things you will need:

 

KOTOR Tool

 

 

Things you should read:

 

http://www.lucasforums.com/showthread.php?t=143412

http://www.lucasforums.com/showthread.php?t=143681

http://www.lucasforums.com/showthread.php?t=143390

 

 

Right Script Conditionals. What can they do?

 

Script conditionals can be used when you want something (usually a dialog option) to only be displayed once a certain condition has been met. Some of the common conditions used are:

  • Global Variables
  • Local Variables
  • Item in PC Inventory
  • Certain Classes

 

 

There are many other conditions but as long as the condition returns either TRUE or FALSE then it will work.

 

Lets start Scripting!

 

First of all if you have only coded a little bit in KOTOR before then this will look completely different.

 

int StartingConditional() 
{
 int iResult;

 iResult = ((GetGlobalBoolean( "your_global_bool" ) == TRUE) );

 return iResult;  

}

 

Right lets break this down.

 

int StartingConditional() 

 

This starting line is different than most scripts in KOTOR for one reason. In most scripts you do not require an outcome as they usually make something happen. We however want an outcome so the dialogue (or whatever) knows what to do / display.

 

Most scripts start with:

 

void main()

 

Void is used when no output is required and means nothing or to get rid of.

Int is a variable type meaning that it has to be filled by something.

The StartingConditional() part tells the game that it is to be used as a Starting Conditional

 

Script.

 

The next bit

 

int iResult;

 

Here you are declaring the variable "iResult". You will use this variable to store the outcome and tell the game what to do. If you've never used variables before get used to it because they are VITAL to scripting.

 

Then next bit

 

 iResult = ((GetGlobalBoolean( "your_global_bool" ) == TRUE) );

 

This is the most important part of your script. It determines what must happen for the conversation option to become available and then puts it into the "iResult" variable. In this example it gets whether a global bool is TRUE and then outputs TRUE into "iResult"but there are other options such as

 

 object oW1 = GetObjectByTag("black_market_pad");

 iResult = GetIsObjectValid(oW1);

 

This checks for the existance of "black_market_pad" in the PC's inventory and puts TRUE in the

"iResult" variable.

 

The last bit

return iResult;  

 

This simply tells the script YES or NO / TRUE or FALSE. If the script sees TRUE it will display the dialog option.

 

Then you must simply compile the script and put the resulting file in the same place as your dialog. (For information on compiling scripts see one of the top links) or see this brief tutorial below.

 

Firstly you need to open up Kotor Tool Text Editor and either write or open your script. (save it as a .nss)

 

Show spoiler
(hidden content - requires Javascript to show)

compile1.png

 

Then you need to make sure it is saved and go to Script (in the top menu) Click whichever version of the game yours is for. Then click scripts again and Compile

 

Show spoiler
(hidden content - requires Javascript to show)

compile2.png

 

If all went well a small box should pop up. If it went wrong there will be extra lines telling you what went wrong and a helpful line number in brackets ()

 

Show spoiler
(hidden content - requires Javascript to show)

compile3.png

 

Now where ever you saved your .nss file, there should now also be a .ncs file which the game can read (Hooray!) that is the one that will need to be included in your overide folder or .MOD file.

 

It is then the name of that file (without the .ncs bit) that goes in your dialogue file. It should go in the part that says "Script that determines availablilty"

 

Show spoiler
(hidden content - requires Javascript to show)

scrpttut1.png

 

Thats it.

 

Hope this helped.

 

If you have any questions at all I will do my best to answer them.

 

Thanks

 

TB12


Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...