Jump to content

Home

Some Scripting help needed!


Robespierre

Recommended Posts

I hope this will be the last bit of help that I need.

 

I need to make some conditional scripts for my droid, so that certain dialog options only become available after you’ve visited certain locations (let’s call them point A and point B for simplicity). I’m going to have a go at adding the waypoints at point A and point B to the module .git file.

 

Now here comes the tricky part. When I’ve been to point A and point B, I need a conditional script that says that I can now travel to point A and B. Not too hard, but here’s the really hard one: When I’m standing at point A, point A can’t be listed as an option. So I need two conditional scripts for each dialog option. Here’s what I mean; when I’m standing at Point B, after traveling to both point A and point B:

 

“Welcome master, please select your destination:”

 

Point A (has two conditional scripts: you are not standing at point A AND you have traveled to Point A)

(hidden)Point B (also has two conditional scripts, but since I AM standing at Point B, the dialog is unavailable).

 

One other issue: with my dialog, I need a dialog node to become UNavailable after you’ve traveled to one location. Essentially, if you haven’t been to at least two points, the droid will simply say, “sorry, no can do”. When you HAVE been to both points, the droid needs to then start on the other dialog node, in which you can choose your destination. So I need one whole node to be unavailable unless you’ve traveled to at least two points.

 

Can anyone help me with that?

 

I do have some ideas on what to do:

 

Say you are standing at Point B. When you stand at the droid, you set a local variable which states that he is at Point B to True. When he goes through and checks all the dialog options, he sees that the variable which states that he is at Point B is True, so the dialog option does not show. However, since all of the droids use the same .dlg file, I’m unsure of how this will work.

 

How about, when you are standing on or near the Point B waypoint, the global variable that states that you are standing near Point B is set to True. When the droid goes through the checks, it sees that you are standing near the Point B waypoint, so it doesn’t show the Point B teleporter option. When you walk away, it becomes false again.

 

In terms of registering where you’ve been, I think it should be something to do with triggering variables when you get close to certain waypoints. Once you’re there, the (global?) variable turns to True, instead of False. Say that you are again at Point B, when you go to the droid, it performs checks and sees that the variable that if you have traveled to Point A is true, so it shows the dialog option.

 

So a script that checks the global variables for both conditions, as well as a script that changes the global variable if you’re close to a particular droid and if you’ve been to a certain location. Since there are 7 points, that’s 14 global variables. Is that possible?

 

I’m sorry for that random brainstorm. Can someone confirm that I’m right? Or what I’m saying is at least possible?

 

So all I need to do apart from that is put the waypoints in the .git file and cause the droid to teleport you to the waypoint if you select that option (which I’m fairly sure I can do, I’ll yell out if I need help). Child’s play, really.

 

Again, thanks so much for your help. Without everyone here, this wouldn’t have been done.

Link to comment
Share on other sites

So I can use the 'GetDistanceToObject()' to determine if I am a certain distance away. Then I can use a check to say, if I am within a certain distance, make this False and don't display the dialog option. Any help with specific coding here?

 

And I also need a script to determine if I've already been somewhere, so that it can change a variable to true (as I posted above), so that the droid will display the option to transport me there.

Link to comment
Share on other sites

loony636 wrote:

So I can use the 'GetDistanceToObject()' to determine if I am a certain distance away. Then I can use a check to say, if I am within a certain distance, make this False and don't display the dialog option. Any help with specific coding here?

Actually GetDistanceBetween() is better choise here.

int StartingConditional() {
object oWP = GetObjectByTag("Waypoint tag", 0);
if (GetDistanceBetween(GetFirstPC(), oWP) > 20.0) {
	return TRUE;
}
return FALSE;
}

loony636 wrote:

And I also need a script to determine if I've already been somewhere, so that it can change a variable to true (as I posted above), so that the droid will display the option to transport me there.

I guess you'll have to use triggers and local variables here. There's got to be a tutorial somewhere for placing triggers. Use the script

void main() {
       if (GetEnteringObject() == GetFirstPC()) {
	if (GetLocalBoolean(OBJECT_SELF, 30)) {
		return;
	}
	SetLocalBoolean(OBJECT_SELF, 30, TRUE);
       }
}

as the trigger's OnEnter script. If you use an existing trigger choose a vacant local boolean and insert the line

SetLocalBoolean(GetObjectByTag("trigger's tag",0), nLocalBoolean, TRUE);

where nLocalBoolean is the number of the boolean you chose, to the trigger's OnEnter script. When checking if you've been to the area use the conditional c_local_set with the boolean number as the first integer parameter and the trigger's tag as the script parameter.

Link to comment
Share on other sites

After finally getting round to trying those scripts, I couldn't manage to get the conditional "GetDistanceBetween" script to work. I put it into a .nss and compiled, put it as the conditional script for the dialog option, and it just didn't appear, even when I was in a totally different module to the waypoint.

 

Any clues?

Link to comment
Share on other sites

Looks like I overlooked the possibility of the waypoint being in another module. The function GetDistanceBetween() will return the value 0.0 if either object is invalid which means that the script will return false if the waypoint is in another module. Maybe this script will work better:

int StartingConditional() {
object oWP = GetObjectByTag("Waypoint tag", 0);
if ((GetIsObjectValid(oWP)) && (GetDistanceBetween(GetFirstPC(), oWP) < 20.0)) {
	return FALSE;
}
return TRUE;
}

This one should show the dialog option if the waypoint is not found in the module or if it is not closer than 20 meters to the PC.

Link to comment
Share on other sites

Excellent, that works perfectly.

 

Actually, due to my supidity, it took me 30 minutes to work out that not putting the most updated version of the .dlg file in the override folder, not compiling the conditional scripts and putting the wrong waypoints in the script files generally leads to the whole thing not working. Half an hour of my life wasted. :(. But it all works now, so thanks!

 

Thanks again.

Link to comment
Share on other sites

Ah, I need some more help. And with the responses, please understand that this is for K1, as I understand that the methods are slightly different for TSL.

 

I set the trigger to trigger the script on enter as: visit_m02ac. Then I put the following in the visit_m02ac.nss file:

 

void main() {
       if (GetEnteringObject() == GetFirstPC()) {
	if (GetLocalBoolean(OBJECT_SELF, 30)) {
		return;
	}
	SetLocalBoolean(OBJECT_SELF, 30, TRUE);
       }
}

 

Which I believes makes the local variable "30" set to "true".

 

Then I made this script as a conditional to check what the variable was set to and then display the dialog option if it is set to true:

 

int StartingConditional() {
if (GetLocalBoolean(OBJECT_SELF, 30) == TRUE) {
return TRUE;
       }
return FALSE;
}

 

But now the dialog option never appears, even when I've triggered the trigger.

 

Any ideas?

 

At the moment I'm trying to narrow down the possible issues. If the scripts are alright, then I'll start to look at the .git and .utt files.

Link to comment
Share on other sites

I set the trigger to trigger the script on enter as: visit_m02ac. Then I put the following in the visit_m02ac.nss file:

(snip)

Which I believes makes the local variable "30" set to "true".

 

Then I made this script as a conditional to check what the variable was set to and then display the dialog option if it is set to true:

(snip)

But now the dialog option never appears, even when I've triggered the trigger.

 

It is most likely a question of setting the local variable in one place and then looking for the value in another. Local variables are set on an object (creature, placeable, trigger, area, module etc...) and will hold the value for that object only. Since you use OBJECT_SELF as the object the variable is set on, it will be set on the object running the script (the area I think if this is an area's OnEnter script).

 

When you then use OBJECT_SELF in the dialog script you check for the variable on the dialog owner (most likely some NPC or placeable). In other words you are setting one variable but looking up a different one. You can get around that by specifying what object the variable is on. Like...

void main() {
   if (!GetLocalBoolean(GetModule(), 30) && (GetEnteringObject() == GetFirstPC())) {
       SetLocalBoolean(GetModule(), 30, TRUE);
   }
}

 

int StartingConditional() {
   return GetLocalBoolean(GetModule(), 30);
}

...which would set and get the variable on the Module object.

 

You should also be careful with checking the value of a Local Boolean against the TRUE constant. I don't remember if this applies to Kotor1 as well, but in Kotor2 this function will not always return TRUE or FALSE, but rather FALSE or not FALSE. (TRUE or FALSE are constants in NWScript that have the value 1 and 0 respectively, while not FALSE is any non-zero value.)

Link to comment
Share on other sites

You should also be careful with checking the value of a Local Boolean against the TRUE constant. I don't remember if this applies to Kotor1 as well, but in Kotor2 this function will not always return TRUE or FALSE, but rather FALSE or not FALSE.

 

TRUE == 1 in KotOR1 nwscript.nss also. That's a good tip. When evaluating booleans in IF statements, it's good rule of thumb to simply not use an == operator.

 

:disaproveif (nBool == TRUE) { ... } (not reliable)

:thumbsup:if (nBool) { ... }

 

:disaproveif (nBool != TRUE) { ... } (not reliable)

:disaproveif (nBool == FALSE) { ... } (works but goes against rule of thumb)

:thumbsup:if (!nBool) { ... }

 

****

(TRUE or FALSE are constants in NWScript that have the value 1 and 0 respectively, while not FALSE is any non-zero value.)
"not FALSE" == 0xFFFFFFFF == -1

"not equal to FALSE" describes any non-zero :p

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...