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.

Erroneous Script

Page: 1 of 1
 Ataris
11-24-2008, 5:26 PM
#1
This script spawns the correct character, but can someone point out to me any sort of syntax errors? The character spawned (d_valkanar1) will not walk or start talking like the script is supposed to do. I managed it a long time ago, but since then I think the script got somewhat messed up. :xp:

void main()
{
int nCreatureSpawned = GetGlobalBoolean("d_valkanar1");
if (nCreatureSpawned) { return; }

SetGlobalBoolean("d_valkanar1",TRUE);

object oEntering = GetEnteringObject();
object oPC=GetFirstPC();
if (GetIsPC(oEntering))

if (!GetIsObjectValid(GetObjectByTag("o")))
CreateObject( OBJECT_TYPE_CREATURE, "d_valkanar1", Location(Vector(0.00, 19.59351), 90.00));
CreateObject( OBJECT_TYPE_CREATURE, "d_cragon1", Location(Vector(-3.320843, -148.0583), 180.00));
NoClicksFor(1.0);

object oActionSubject = GetObjectByTag("d_valkanar1");

// This is the object the action subject should move to.
object oMoveTo = GetFirstPC();

// If this is FALSE, the action subject will walk. If TRUE it will run.
int bRun = FALSE;

// This is the desired distance between the action subject and oMoveTo.
float fRange = 1.0;

AssignCommand(oActionSubject, ClearAllActions());
AssignCommand(oActionSubject, ActionForceMoveToObject(oMoveTo, bRun, fRange));
AssignCommand ((GetObjectByTag("d_valkanar1")), ActionDoCommand(ActionStartConversation(oPC)));

ExecuteScript("old_tr_enter_610", OBJECT_SELF);
}
 glovemaster
11-26-2008, 4:02 AM
#2
Well its been a while since I've been using NWScript :p Stuff leaves your brain over time >.< But I am assuming that your fRange = 1.0 isn't large enough say if the PC is 10m away.
Also I don't think the ActionStartConversation() needs to be wrapped in an ActionDoCommand() when your already using AssignCommand(). Also I can't remember the difference between ActionStartConversation() and BeginConversation().

I might not be right but its worth looking at them ;)
 Ataris
11-26-2008, 5:41 PM
#3
I'm glad there are still some scripters around here.

I'll see what I can do, thanks.
 stoffe
11-27-2008, 6:45 AM
#4
This script spawns the correct character, but can someone point out to me any sort of syntax errors? The character spawned (d_valkanar1) will not walk or start talking like the script is supposed to do. I managed it a long time ago, but since then I think the script got somewhat messed up. :xp:


A few problems and potential problems with that script that I could see:
You are missing { } block delimiters with a few of the IF statements, making them only operate on the statement coming right after them, which judging by the context isn't what was intended.


The old script, old_tr_enter_610, would never get fired after the global variable had been set since that would make the script return early. I assume you want the old script to fire everytime your custom one is run, regardless if your own additions do anything or not.


Does the object you want to check if it doesn't already exist before spawning your two NPCs really have the tag o? Looks like it might be a typo to me. :)


It's generally safest to get the object reference for the NPC you want to assign actions to directly from the CreateObject() function. That way you can be sure you always get the correct one if there happens to be more than one object in the area with the same tag.


You could try delaying the actions with a fraction of a second to allow the NPC to spawn in properly before getting actions assigned. I've noticed that this makes script work more reliably in some circumstances.


Not really an error, but your script had a fair amount of variable bloat which made it larger and longer to execute without adding anything functionality-wise. Not that it really would matter much in a script of this size that doesn't get run very often, but still. :p


Make sure you've added a boolean variable with the name d_valkanar1 in the globalcat.2da file, or your script will not be able to store any values in it.


Here's a reworked variant of your script taking some of the above into account, with some (maybe incorrect?) assumptions on what you are trying to do:
void main() {
object oPC = GetFirstPC();

if (GetGlobalBoolean("d_valkanar1") || (GetEnteringObject() != oPC)) {
ExecuteScript("old_tr_enter_610", OBJECT_SELF);
return;
}

SetGlobalBoolean("d_valkanar1", TRUE);

if (!GetIsObjectValid(GetObjectByTag("o"))) {
object oActionSubject = CreateObject( OBJECT_TYPE_CREATURE, "d_valkanar1", Location(Vector(0.00, 19.59351), 90.00));
CreateObject( OBJECT_TYPE_CREATURE, "d_cragon1", Location(Vector(-3.320843, -148.0583), 180.00));
NoClicksFor(1.0);
DelayCommand(0.5, AssignCommand(oActionSubject, ClearAllActions()));
DelayCommand(0.5, AssignCommand(oActionSubject, ActionForceMoveToObject(oPC, FALSE, 1.0)));
DelayCommand(0.5, AssignCommand(oActionSubject, ActionStartConversation(oPC)));
}

ExecuteScript("old_tr_enter_610", OBJECT_SELF);
}



Also I don't think the ActionStartConversation() needs to be wrapped in an ActionDoCommand() when your already using AssignCommand().

That should be correct. ActionDoCommand() just runs a non-action function as an action (i.e. add it to the object's action queue for execution rather than run it right away). Since ActionStartConversation() already is an action (as indicated by the name) that would be unnecessary in this case. :)


Also I can't remember the difference between ActionStartConversation() and BeginConversation().

ActionStartConversation() is used in scripts to make one object initiate conversation with another object. BeginConversation() is used in OnDialogue event scripts of objects to make them start the dialog interface. IIRC.
 Ataris
11-29-2008, 4:29 PM
#5
Much thanks, I think I need to spend more time looking for scripting tutorials...

The global boolean is used to ensure that "d_valkanar1" doesn't spawn again.
Incorrect, actually, the "old_tr_enter_610" I only want to occur once. So far the original script spawns the character, activates the old script, and then when you reenter none of that happens again.
Page: 1 of 1