PDA

View Full Version : Need Help With NPC Script


greymeister
03-28-2004, 02:44 AM
Ok, what I saw in another forum didn't seem to help, so I'll post here and see if anyone can help. I tried to use the function
"GetObjectByTag(string)" but it doesn't seem to work. Does anyone know the correct syntax if it exists? Also, is there any easy way to test scripts later in the game? Games that I load after editing the override folder don't seem to change....


Thanks
Greymeister

tk102
03-28-2004, 02:50 AM
From nwnscript.nss:

// 200: Get the nNth object with the specified tag.
// - sTag
// - nNth: the nth object with this tag may be requested
// * Returns OBJECT_INVALID if the object cannot be found.
object GetObjectByTag(string sTag, int nNth=0);


that last part, the nNth parameter, is optional (as noted by the =default parameter that it has attached).

Maybe post a little bit o' the script...

As for testing scripts, I thought that was an important enough question to warrant its own thread. (http://www.lucasforums.com/showthread.php?s=&threadid=125847)

In a recent scripting snafu, I didn't copy the .ndb file generated from nwnnsscomp to the override folder, just the .ncs. I thought that was all that was involved-- but my .ncs wasn't working until the .ndb file coexisted in the Override folder.

Maybe that's part of it?

greymeister
03-28-2004, 03:55 PM
Ok, here is my script:

void main()
{
ChangeFaction(GetObjectByTag("kor_calo"), GetFirstPC());
/* This I don't know if you need ...*/

AddPartyMember(NPC_T3_M4, GetObjectByTag("kor_calo"));
/* This makes ol' Calo help you take out his buds... */
}

Now the problem is, when Calo Nord is on the Ebon Hawk he attacks you. I have tried changing the faction of the utc file and editing it to make it use the same scripts as other henchmen but to no avail. Also, I found that if I use this:

AddAvailableNPCByTemplate(NPC_T3_M4, "p_darthmalak");
/* This makes ol' Calo recruitable in the future.... */

Calo is still the one on the EH. Any ideas?

tk102
03-28-2004, 04:35 PM
I know you've seen gameunlimited's post (http://www.lucasforums.com/showthread.php?s=&postid=1484603#post1484603) describing changing the .utc tag. What affect did that have for you?

greymeister
03-28-2004, 05:24 PM
Well I've gotten it to work fine now so that at least in my game I can recruit darth malak from the beginning dialogue if I choose the right options and I've changed his tag to "Juilhani"(sp) so that now the replication problem is gone. That is the reason I wanted to add a different character to the available slots than the calo character so that I could use a custom calo utc file with tag of t3m4 so that the replication problem does not exist there either. However, due to the problem with him being hostile upon entry to the EH I'm stuck as to whether that will even work.

gameunlimited
03-29-2004, 02:16 AM
I am pretty sure I might be able to help you with this problem. But I am not clear exactly on what you are doing here. Perhaps you can describe a bit what you want to accomplish, where and when? Maybe even you can put your whole script in here. I will see what I can do then.

greymeister
03-29-2004, 02:49 AM
Well what I already posted is the whole script. I just can't figure out how to make Calo Non-hostile when you enter the Ebon Hawk. I'm trying to do what someone wanted which was to be able to recruit Calo Nord. It was as much of trying to answer his request as experimenting with scripting KOTOR, but I've hit a brick wall and I'm not sure of a way around it :(

gameunlimited
03-29-2004, 04:21 AM
Try naming your utc file unique. Make sure the FactionID is set to 2 in the utc file. Then use this script:


void main()
{
RemoveAvailableNPC(NPC_T3_M4);
AddAvailableNPCByTemplate(NPC_T3_M4, "unique_name_here");
}


To troubleshoot your problem, maybe you can use the script above without worrying about changing the faction of Calo Nord nor use the AddPartyMember function. See if this works fine. So basically, try calling this script from anywhere (but not from inside of the Ebon Hawk) and then go back to ebon hawk. It works fine for me at least.

greymeister
03-29-2004, 05:28 AM
Ok, the problem seems to be that the NPC that is present where I'm trying the mod (The calo encounter on korriban, aka "kor_calo") is the one who shows up on the ebon hawk after I use the following script:

void main()
{
ChangeFaction(GetObjectByTag("kor_calo"), GetFirstPC());
RemoveAvailableNPC(NPC_T3_M4);
AddAvailableNPCByTemplate(NPC_T3_M4, "n_newcalo");
AddPartyMember(NPC_T3_M4, GetObjectByTag("kor_calo"));
}

What happens is that the object "kor_calo" ends up permanently in the T3M4 slot, and the new object that isn't hostile does not. I tested it by fighting the calo fight and then checking my party and the non-hostile version was indeed there in the ebonhawk.

It all comes down really to the damn tag issue. You have to make sure recruitable NPCs have tags corresponding to whatever slot they replace or the Replication Problem (http://www.lucasforums.com/showthread.php?s=&threadid=125631) will occur. That is why I use the n_newcalo object which has been fixed for this, however, since the kor_calo one overrites this (which I didn't think it should) it makes it irrelevant.

Also, changing the kor_calo object's tag is not an option because it breaks the ambush encounter.

gameunlimited
03-29-2004, 05:55 AM
So have you got the problem solved? If not, I have a suggestion on how you can handle this situation:


void main()
{
DestroyObject(GetObjectByTag("kor_calo"));
CreateObject(OBJECT_TYPE_CREATURE, "n_newcalo", GetLocation(GetFirstPC()));
RemoveAvailableNPC(NPC_T3_M4);
AddAvailableNPCByTemplate(NPC_T3_M4, "n_newcalo");
AddPartyMember(NPC_T3_M4, GetObjectByTag("n_newcalo"));
}


Basically what this script does is to delete the "kor_calo", then it spawns the edited "n_newcalo", adds him to the party and also to the AvailableNPC slot.

greymeister
03-29-2004, 12:50 PM
I had thought to destroy the calo object, but if I do I'm going to have to move the script or something so that it doesn't break the dialogue. I will try to do that.

greymeister
03-29-2004, 06:45 PM
I ended up using two scripts, which go as follows:

This one when the correct dialogue choice is taken:

void main()
{

ChangeFaction(GetObjectByTag("kor_calo"), GetFirstPC());
/* This I don't know if you need ...*/

RemoveAvailableNPC(NPC_T3_M4);

SetLocalBoolean(GetObjectByTag("kor_calo"), 3, TRUE);

}

ANd this one at the end of the dialogue:

void main()
{

if(GetLocalBoolean(GetObjectByTag("kor_calo"), 3))
{
DestroyObject(GetObjectByTag("kor_calo"), 0.0, FALSE, 1.0);

CreateObject(OBJECT_TYPE_CREATURE, "n_newcalo", GetLocation(GetFirstPC()));

AddAvailableNPCByTemplate(NPC_T3_M4, "n_newcalo");

AddPartyMember(NPC_T3_M4, GetObjectByTag("T3M4"));
}
}


Thanks for the help.
Greymeister

tk102
03-29-2004, 07:11 PM
Was the choice of 3 in SetLocalBoolean arbitrary?

greymeister
03-29-2004, 07:19 PM
Well I guess it probably seems arbitrary, but the fact is that since it was
said that the number had to be less than 4, and I didn't want to accidentally
overrite some random boolean that Bioware might have used, I just chose 3 :)

tk102
03-29-2004, 07:31 PM
Alright then. I've been nervous about tweaking anything there myself -- but since you're going to destroy the old Calo anyway it doesn't matter what Bioware used. Good job -- nice and effecient.

greymeister
03-29-2004, 07:41 PM
The only problem with this solution to making him hirable is that every Calo encounter dialogue would have to be changed and the scripts would have to be changed as well for the different tags. I didn't do that because I'd already accomplished what the guy wanted but I'm sure it wouldn't be that hard to replicate. Now that I've finally suceeded in editing dialogue as well with the toolset (a very arduous process, I really wish speakeasy would be edited to allow the different dialog file) I'm looking into other possibilities such as new NPCs that you'd be able to hire other than ones already in the game.