Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

The power of TSL script parameters

Page: 1 of 1
 glovemaster
04-16-2008, 2:20 PM
#1
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:
http://img185.imageshack.us/img185/4604/dlgparameterscd7.png)
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:
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...
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.
http://img390.imageshack.us/img390/5835/dlggivecreditsrh7.png)

I hope your still following because its gonna get even more snazzy :p
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:
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".
http://img230.imageshack.us/img230/1630/dlggiveitemtr2.png)

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 :p 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:
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. ;)
 Ferc Kast
04-16-2008, 8:52 PM
#2
I have a question concerning script parameters: If someone wanted P2 to reflect a NPC's number from npc.2da (to add a certain class to the party member specified), how they do that?
 glovemaster
04-17-2008, 3:44 AM
#3
void main(){
int iMember = GetScriptParameter(2);
object Member;
if(IsNPCPartyMember(iMember)){
switch(iMember){
case 0:
Member = GetObjectByTag("Atton");
break;
case 1:
Member = GetObjectByTag("BaoDur");
break;
case 2:
Member = GetObjectByTag("Mand");
break;
case 3:
Member = GetObjectByTag("g0t0");
break;
case 4:
Member = GetObjectByTag("Handmaiden");
break;
case 5:
Member = GetObjectByTag("hk47");
break;
case 6:
Member = GetObjectByTag("Kreia");
break;
case 7:
Member = GetObjectByTag("Mira");
break;
case 8:
Member = GetObjectByTag("T3m4");
break;
case 9:
Member = GetObjectByTag("VisasMarr");
break;
case 10:
Member = GetObjectByTag("Hanharr");
break;
case 11:
Member = GetObjectByTag("Disciple");
break;
}
int iClass = GetScriptParameter(3);
AssignCommand(Member, AddMultiClass(iClass, Member));
}
}
The above should do the trick, perhaps a little longer than you would have thought but I can't see an easier way to get the character from the integer.
Also I used GetScriptParameter(3) so you can also choose the class that you are adding from the dialog, thats optional but it opens the script up to more possibilities. You just need to take the number from this part of the NWscript:
int CLASS_TYPE_SOLDIER = 0;
int CLASS_TYPE_SCOUT = 1;
int CLASS_TYPE_SCOUNDREL = 2;
int CLASS_TYPE_JEDIGUARDIAN = 3;
int CLASS_TYPE_JEDICONSULAR = 4;
int CLASS_TYPE_JEDISENTINEL = 5;
int CLASS_TYPE_COMBATDROID = 6;
int CLASS_TYPE_EXPERTDROID = 7;
int CLASS_TYPE_MINION = 8;

Hope that helps ;)
Page: 1 of 1