Jump to content

Home

Scripting questions


R2-X2

Recommended Posts

And again, I've got some questions about scripts...: (((K1!!!)))

 

1) How can I make a script for a dialog that lets the NPC say "Hello" when I talk to the NPC the first time, and if I talk to him the second time, he says "Hello again." ?

 

2) What are the scripts for item checks? There is one that looks if you have equipped sth. and there's one that just looks if you have the item in your inventory. What are they?

 

3) How can I make that a NPC just says "Hello" and nothing more, but if I talk to another NPC about a specific thing, he/I get(s) more dialog options?

 

4) What if the NPC is in another module than the one I have to talk to?

 

5) What is the script for letting NPCs look in a specific direction?

 

6) How can I make a NPC that doesn't turn around to me if I talk to him, and even if I speak to him, he looks in the direct where he looked before talking to him?

 

Hopefully and filled with questions, R2.

 

Maybe add the anwers to the Tutorials section, because these scripts are very usable.

Link to comment
Share on other sites

These scripts vary between the two games sometimes, I'm going to hazard a guess and explain this for TSL.

 

For question 1, TSL has scripts precompiled for this. On the "Hello" dialog node you need to add the conditional script "c_talkedto" and on the same node you need to fire the script "a_talktrue". Then underneath that node have your "Hello again".

 

Question 2, the conditionals you want are "c_hasitem" and I am unsure if there is an "item equipped" conditional, if you want to compile this it will do the same thing:

int StartingConditional() {
   sItemTag = GetScriptStringParameter();
   int iSlot;
   for(iSlot = 0; iSlot <= 19; iSlot++) {
       if(GetItemInSlot(iSlot, GetFirstPC()) == sTag)
           return TRUE;
   }
   return FALSE;
}

This script works if you write the tag of the item that needs to be equipped into the String Parameter field of the conditional.

 

For Question 3, since the other NPC is in another module you will need to use a GlobalNumber, or give the PC an item to be found by a conditional on the other NPC. If you need help with these scripts feel free to ask :)

 

To make an NPC look in a specific direction depends on whether you want him to generally face a direction, or face a specific object. If you want him to look in a general direction - i.e. East - then that can be done by simply changing his orientation settings in the GIT file. And to answer Q6, to stop him reorienting on the PC there is a setting in the characters UTC, if you open it in KotOR Tool it will appear as "Do not reorient on PC" or something similar, just check that box. :p

 

Hope that helps ;)

Link to comment
Share on other sites

int StartingConditional() {
   sItemTag = GetScriptStringParameter();
   int iSlot;
   for(iSlot = 0; iSlot <= 19; iSlot++) {
       if(GetItemInSlot(iSlot, GetFirstPC()) == sTag)
           return TRUE;
   }
   return FALSE;
}

 

A few problems with that script. You use sItemTag which has not bee declared, same with sTag in the if-statement. And looks like sTag should be a string by the prefix, though GetItemInSlot() returns an object reference. Need to use GetTag() there too. :)

 

Fixed:

int StartingConditional() {
   string sItemTag = GetScriptStringParameter();
   object oPC = GetFirstPC();
   int iSlot;

   if (GetIsObjectValid(GetItemPossessedBy(oPC, sItemTag))) {
       for(iSlot = INVENTORY_SLOT_HEAD; iSlot <= INVENTORY_SLOT_LEFTWEAPON2; iSlot++) {
           if(GetTag(GetItemInSlot(iSlot, oPC)) == sItemTag) {
               return TRUE;
           }
       }
   }
   return FALSE;
}

Link to comment
Share on other sites

Thank you two for the help!

 

But I need it for K1...:argh:my mistake.

Questions 1 & 6 cleared anyway, because for K1 the scripts are k_con_talkedto and k_act_talktrue (TSL scripts with a_ + name are k_act_ + name in K1 and so on)

 

Does stoffe's script work for K1 as well?

And what's the script for simply having the item, like a datapad, which can not be equipped?

 

To Q3+4, how to use Globals?:indif::eek:

Link to comment
Share on other sites

The problem with KotOR 1 is that there are no script parameters in dialog files. Because of this, Stoffe's script won't be able to work and there can't be a precompiled script for having an item.

 

For Stoffe's script to work you would have to change the line:

string sItemTag = GetScriptStringParameter();

To:

string sItemTag = "[color=cyan]tag_of_item[/color]"

Replacing tag_of_item with the tag of the item you are checking for, and compiling that.

 

The same applies for checking if the PC has an item:

int StartingConditional() {
   string sItemTag = "[color=cyan]tag_of_item[/color]";
   if (GetIsObjectValid(GetItemPossessedBy(GetFirstPC(), sItemTag))) {
       return TRUE;
   }
   return FALSE;
}

*Double checks script :p*

 

To use GlobalNumbers you have to make changes to globalcat.2da, I personally try to avoid editing lots of 2da files to keep mods simple and compatible with other mods. After adding a row with your identifier and set the number to 0 you can call it from scripts using GetGlobalNumber() and change it using SetGlobalNumber().

 

A quick explanation: NPC 1 in your first module will have a conditional check for your GlobalNumber to check if it is say, 1 or above. Being 0 to start with, when you first talk to him he would only have one thing to say; as we know 0 is less than 1 :p When you talk to NPC 2 in your second module, (s)he will fire a script to set your GlobalNumber to be 1 or higher, so that when you go back to NPC 1 and (s)he checks the GlobalNumber, the script will return true and give the PC access to more dialog options.

 

Hope that's not too brief, if you need any help just ask :)

Link to comment
Share on other sites

Ouch.

 

Could you explain more? How to make the scripts that check/set the GlobalNumbers?

How to set them to dialog options?

 

second: I meant how to let the NPC face a dricetion per script, for examle if you talk to him, then sth happens, and here suddently turns around to ther to see what happened.

Link to comment
Share on other sites

Well it seems I can't refer you to a tutorial so I'd might aswell write one :lol:

 

GlobalNumber's are use to track the PC's progress through quests by splitting the quest up into "stages", if you like, and giving each stage a number. For example, a simple "Something tragic has happened and for some reason you need to go all the way over to another planet and collect a fish" quest, the common template for most MMO quests ¬.¬ I'm going to presume you've followed a few dialog writing tutorials because I woke up half an hour ago :p

 

So the outline is:

  1. You talk to the first dude and he asks you to go somewhere to get him a fish.
  2. You go all the way over to another planet, talk to the second dude and he gives you the fish.
  3. You go all the way back to the first dude and he tells you that you have the wrong type of fish.
  4. Back to the second dude to get a replacement.
  5. Back to the first dude who gives you 5 credits and then you kill him.

 

So we have 5 stages to the quest, however GlobalNumber's include 0, and so 0 is a stage :lol:

 

First of all we need to add a line to globalcat.2da:

globalcat.png

That seems pretty self explanatory. :p

Then we can use the name "MY_NEW_GLOBAL" to call from scripts.

 

When you talk to "the first dude", his dialog structure will be like this:

 [u]Checks[/u]
(Stage 4) - Ah thank you for your troubles, here is five credits!
           - Five credits? Five credits?! [color=cyan][Fire hostile script][/color]
(Stage 3) - Well go on then! Get to it!
(Stage 2) - Dammit man, this fish is deep blue! I wanted navy blue!
           - Okay then... [color=cyan][Fire stage 4][/color]
(Stage 1) - What are you still here for?
         - Oh please help me! I need a fish but the dock officer banned me for being a t*@! 
           - Okay sure I'll help. [color=cyan][Fire stage 2][/color]

You'll notice that the order is backwards, this is because some conditional checks, check that GlobalNumbers are greater than a number, and so most of the conditionals will return true.

 

Here are the scripts that will be fired in K1 - in TSL there are quick and easy work arounds.

 

So in K1 your conditional script will look like this:

int StartingConditional() {
return(GetGlobalNumber("MY_NEW_GLOBAL") == [color=cyan]Stage[/color]);
}

Replacing Stage with the number of the Stage.

 

This script is then compiled and placed in the dialog node's conditional script box:

conditional.png

You need to make many scripts from this template, which is why KotOR2 is better to use Globals for.

 

However to change the GlobalNumber we need a second script:

void main(){
SetGlobalNumber("MY_NEW_GLOBAL", [color=cyan]Stage[/color]);
}

Again replacing Stage, with the stage you are changing the Global to.

I am unsure if you need to initially set the GlobalNumber to 0 - to be on the safe side I would :)

 

This script is placed on the dialog node like so:

newstage.png

 

I could go through the second dude's dialog but it would only be very similar, conditional checks, and when he gives you the fish the next stage will be fired.

 

Well there is a crash course on GlobalNumber's, if its not all that clear then I apologise :p Just ask if you need anything clarifying.

 

---

 

Also, to make an NPC face a different direction via a script you can use either:

void main() {
object oNPC = GetObjectByTag("Tag_of_NPC");
float fDirection = 90.0; // North
AssignCommand(oNPC, SetFacing(fDirection));
}

Replace 90.0 with any other angle (0-360) remember that 0 degrees is East and 90 is North. Also remember to add .0 on the end (the decimal place) otherwise you will get syntax errors.

 

Alternatively, to make him/her face an object:

void main() {
object oNPC = GetObjectByTag("Tag_of_NPC");
object oFace = GetObjectByTag("Tag_of_object_to_face");

AssignCommand(oNPC, SetFacingPoint(GetPosition(oFace)));
}

Replacing the tags as appropriate.

 

Hope that all helps :p As I said, if anything needs clarifying then feel free to ask. :)

Link to comment
Share on other sites

GlobalNumber's are use to track the PC's progress through quests by splitting the quest up into "stages", if you like, and giving each stage a number.

 

That works, but it's usually better to use journal entries to keep track of quest progress. Then you just use AddJournalQuestEntry() to set the quest stages, and GetJournalEntry() to check what stage the quest currently is at. :)

Link to comment
Share on other sites

I think I understand it now. I'll tell if (or if not) the globals work today in the evening.

 

Thanks, that really helped me.

 

oh, and there's no check box for not orienting in the utc file in K1, it's just in K2, but in K1 there are NPCs that don't even without that box.

 

Edit: Oh... journal entries... how to use them?

 

Maybe put these scripts and the "Globals Tutorial" into the Tutorals section.

 

Edit: Oops... a bit late ;) anyway, thanks for your help glovemaster, it works.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...