Jump to content

Home

Scripting a Creature's Movement, Help Please


Ulic and Cay

Recommended Posts

I have a situation where I'm using scripts in a dialog. It is set up like this: at a specific point in the dialog tree I run the "a_spawnsdd" script below to spawn a droid. Then, depending on further dialog choices, scripts will run that affect that droid (it will be set to hostile, or neutral, stunned, etc.) Those scripts run fine but can't seem to get the droid to move.

I have a particular script that has the droid attack a locked door so it will open. It fails everytime. Its the "a_opensecdoor" script below. The droid won't move to attack the door and I don't know why. Can anyone tell me what I'm doing wrong?

 

a_spawnsdd:

void main() {
if ((GetGlobalNumber("102PER_SpawnSDD") == 0)) {
	object oG_assassindrd010 = CreateObject(1, "g_assassindrd010", GetLocation(GetObjectByTag("WP_DROID_DOOR", 0)), 0);
	AssignCommand(oG_assassindrd010, ClearAllActions());
	DelayCommand(2.0, AssignCommand(oG_assassindrd010, ChangeToStandardFaction(oG_assassindrd010, 1)));
	SetGlobalNumber("102PER_SpawnSDD", 1);
}
return;
}

 

a_opensecdoor:

void main() {
object oSecDoor = GetObjectByTag("SecDoor", 0);
object oG_assassindrd010 = (GetObjectByTag("droidopendoor", 0));
AssignCommand(oG_assassindrd010, ActionMoveToObject(GetObjectByTag("WP_DROID_DOOR", 0), 0, 1.0));
AssignCommand(oG_assassindrd010, ActionPlayAnimation(107, 1.0, 0.0));
SetLocked(oSecDoor, 0);
DelayCommand(4.0, ActionOpenDoor(oSecDoor));
}

Link to comment
Share on other sites

Odd to respond to my own post before anyone else has but I figured out my problem. The delay command I was using before I changed the droid's faction was too short. I'm not sure why some commands can be strung one right after the other with no problem while others will bring everything to a crashing halt. Anyone have an explanation for that? Or a good rule of thumb to work with so I don't run into this in the future?

 

(Also disregard the scripts I posted above. I have since totally reworked them using local numbers...)

Link to comment
Share on other sites

I'm not sure why some commands can be strung one right after the other with no problem while others will bring everything to a crashing halt. Anyone have an explanation for that?

 

When you spawn a new object into the game world you usually have to wait briefly to manipulate that object to give it time to spawn in properly. This doesn't just apply to creatures, but other objects like containers and stores (which has to be delayed before they can be opened) as well. No idea why it works in this unreliable way, but I've observed that it does. :)

 

Thus I usually tend to put any manipulation that needs to be performed on a recently spawned object into its own function, and then call that function with a delay after the object is spawned.

 

(In your script you don't really need to assign the faction change to the NPC though, since the faction change function is not an Action. You can just run it directly without putting it on the NPCs own command queue.)

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...