lfnetwork.com mark read register faq members calendar

Thread: The power of TSL script parameters
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 01-29-2009, 04:16 PM   #1
glovemaster
Now-a-days GroovyCarrot
 
Join Date: Jan 2007
Location: Liverpool, UK
Posts: 697
Current Game: No time for games, sadly
Helpful! 
Arrow The power of TSL script parameters

From this thread.

I noticed there was no tutorials on how to make use of the TSL script parameters so I've just threw this together to help people understand their uses.

Though they seem pretty self-explanatory, some of us don't really understand them and how useful they can be. I will warn you that I am assuming that you have some knowledge of scripting, at least enough to know what a script is doing.

Basically a TSL script parameter is something that you can set in your .dlg file, incase you have never seen it before:

The contents of the red box is what I'm going to explain how to use.

So first of all lets look at your "P1" up to "P5" collumns.
Well these are basically integer variables that you can set from the dialog in your script, these are useful to compact several scripts.
If you have a dialog file that has several scripts used inside it, say one script will give you credits, another will give you an item, a third will give you a slap around the face. You would initially think that you would need three scripts to do this, one for each action, and you place the individual script to fire on each node, but using one of these dialog script parameters, we can put all of these into only one script. Example:
Code:
void main(){
    int iAction = GetScriptParameter(1);
    if ( iAction == 1 ){
        // Give the PC some credits.
    }
    else if ( iAction == 2 ){
        // Give the PC an item.
    }
    else if ( iAction == 3 ){
        // Give the PC a good slap around the face!
    }
}
Now, on each dialog node where we wanted something to happen, instead of using three different scripts, we put this script on all of those lines, and in the "P1" collumn we set that to either 1, 2 or 3 depending on the action we want to happen. If your wondering "Why P1?", the reason is because I am using GetScriptParameter(1), of course if I chose to use GetScriptParameter(4) then you would need to set your 1, 2 or 3 in collumn "P4".

I hope your following because I'm going to go a little more advanced...
Now, in the script above, if you specify ScriptParameter(1) to be "1", then the script will give the PC some credits, we can also use ScriptParameter to specify how many credits to give the PC, expanding on the above...
Code:
void main(){
    int iAction = GetScriptParameter(1);
    if ( iAction == 1 ){
        int iCredit = GetScriptParameter(2);
        // Give the PC "iCredit" amount of credits.
        AssignCommand(GetFirstPC(), GiveGoldToCreature(GetFirstPC(), iCredit));
    }
    else if ( iAction == 2 ){
        // Give the PC an item.
    }
    else if ( iAction == 3 ){
        // Give the PC a good slap around the face!
    }
}
Now you will notice that I am using GetScriptParameter(2), this is because ScriptParameter(1) is in use, if you don't understand that then I recommend you look back in scripting tutorials. Now, if I wanted to give the PC 500 credits, then I would set the "P1" collumn to "1" to specify that I want to give the PC credits, and also "P2" to "500" to specify that I want to give the PC 500 credits, this is very helpful if you want to give the user 500 credits on one dialog node, and say 1000 credits on another, you can use the same script, and just change "P2" to 1000.


I hope your still following because its gonna get even more snazzy
Now we have looked at giving credits lets look at the next part, giving items.
Next to the "P*" collumns, you will notice a "String Param" collumn, with a larger input box, I am going to use that. So here is the script:
Code:
void main(){
    int iAction = GetScriptParameter(1);
    if ( iAction == 1 ){
        int iCredit = GetScriptParameter(2);
        // Give the PC "iCredit" amount of credits.
        AssignCommand(GetFirstPC(), GiveGoldToCreature(GetFirstPC(), iCredit));
    }
    else if ( iAction == 2 ){
    string sItem = GetScriptStringParameter();
        // Give the PC "sItem"
        AssignCommand(GetFirstPC(), CreateItemOnObject(sItem, GetFirstPC()));
    }
    else if ( iAction == 3 ){
        // Give the PC a good slap around the face!
    }
}
So to give the PC a lightsaber, we would put "2" in "P1", and in the "String Param" we would put "g1_w_lghtsbr01". Similar to the Credits part of the script, if we wanted to give the user a lightsaber on one node, but maybe a short lightsaber on another node, we can use the same script but in your "String Param" you would put "g1_w_shortsbr01".


Now, if your hoping that I am going to show you how to slap the PC around the face, sadly I don't think you can Unless you can find a "Slapping" animation. But if you wanted to merge in a fourth, fifth or maybe even sixth script then you can simpily append a new "else if" statement, so to merge in your fourth script, just add to the end:
Code:
    else if ( iAction == 4 ){
        // Your fourth script
    }
I hope this helps you, it certainly compacts the override on script heavy mods and allows scripts to do alot more, you can use ScriptParameters for lots more things, but those are your basic starts, and its much better and I find more fun to explore things yourself.


If you're looking for any of the junk I did a few years ago; you can probably still find it all on filefront
glovemaster is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > Knights of the Old Republic > Editing / Modding > Holowan Laboratories > Tutorials: Scripting > The power of TSL script parameters

Tags
dialog script parameters

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:33 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.