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.

Scripting Trouble...

Page: 1 of 1
 Dak Drexl
01-18-2011, 11:12 AM
#1
Ok, my first attempt at scripting - trying to do this for myself for once instead of getting someone else to. Thing is, I know a little about scripting, but nothing at all when it comes to doing it, so if you can help please bear with me:

Is there such a thing as an "ondeath" script? i.e. executes an action when someone dies (I'm sure there has to be)... what would this look like? I want the player to be given an item when Calo Nord dies the second time.

After I make the script, what do I do? Am I going to want to attach it to dialog that takes place after Calo "dies" on Taris to ensure that I don't get the item then by mistake? I'm not really sure if I'm being clear so I would be happy to clarify anything needed. Thanks a lot for any help and I apologize in advance for my scripting retardedness.
 Qui-Gon Glenn
01-18-2011, 11:17 AM
#2
The default OnDeath event is in your source scripts.bif, as are all of the basic UserDefined scripts.

As far as not getting the item too early.... I am sure there is a global boolean relating to calo's quest... or a numeric rather, that tells the game where along that plot you are. You can use this boolean in the same way.

EDIT: This is the default on death in K1

//:: k_def_death01
/*
Default On Death Script
*/
//:: Created By: Preston Watamaniuk
//:: Copyright (c) 2002 Bioware Corp.

#include "k_inc_switch"
#include "k_inc_debug"

void main()
{
// object oYourItem = GetObjectByTag("your_tag");
// object oPC = GetFirstPC();
ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_DEATH);
// ActionGiveItem(oYourItem, oPC);
/*
if(!GN_GetSpawnInCondition(SW_FLAG_AI_OFF))
{
SpeakString("GEN_I_AM_DEAD", TALKVOLUME_SILENT_TALK);
//Shout Attack my target, only works with the On Spawn In setup
SpeakString("GEN_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);
}
if(GN_GetSpawnInCondition(SW_FLAG_EVENT_ON_DEATH))
{
SignalEvent(OBJECT_SELF, EventUserDefined(1007));
}
*/
}
Now, is it that you don't want to just leave the item in the creature's bodybag? If you want the item to be given via script as a result of the battle with an "Items Received" box, there is a default script for that... i would have to look through nwscript atm, but then again you said you wanted to work through this on your own a bit :p

But the default bodybag you can probably drop the item into, on an unused hook on your Calo's .utc
 Dak Drexl
01-29-2011, 2:26 PM
#3
Well for some reason staff kotorfiles wouldn't let me attach it to Calo's .utc... said it wasn't a "safe" one, but I don't see why it isn't. Not a big deal anyhow, just get the item through cheats...

Gots a new problem. I'm trying to spawn a custom NPC. First off, how the hell do I get a custom .utc file to read a custom .2da entry? I don't get it :mad:
Anyway, here's my script, I want him to spawn at the entrance to the Republic base after the player gets the mission to break into the Sith Embassy on Manaan...

void main()
{
CreateObject(OBJECT_TYPE_CREATURE, "creature_dak_drexl", Location(Vector(81.02,59.52,56.38), 0.0));
}

(The coords in there are wrong, they're just placeholders. It should spawn him right next to Roland Wann at the moment)

I attached the script to a line in the "man26_repdip.dlg" file. Do I attach it by putting my script's name in the "Script to run for this node" entry in the dlg file? My compiled script is called "spawndak.ncs" so I put exactly that in there.

I know there are a lot of questions here but I would appreciate it if anyone could answer any of them!

Edit: I forgot to mention what's actually wrong - when I run through the dialogue, nothing happens. I'm not sure if this is due to my script not firing or that my script doesn't work at all.
 TimBob12
01-29-2011, 2:53 PM
#4
Don't put the .ncs extension in the script to run box.

in your script you may want to use


void main()
{

if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC())) {

SetLocalBoolean(OBJECT_SELF, 40, TRUE);


CreateObject(OBJECT_TYPE_CREATURE, "creature_dak_drexl", Location(Vector(81.02,59.52,56.38), 0.0));


}

ExecuteScript("k_ptat17ag_enter_old", OBJECT_SELF);

}


Adding that in will make sure it doesn't spawn more than once. it uses a local boolean to track that.

Hope this helps

TB12
 Qui-Gon Glenn
01-29-2011, 3:37 PM
#5
I attached the script to a line in the "man26_repdip.dlg" file. Do I attach it by putting my script's name in the "Script to run for this node" entry in the dlg file? My compiled script is called "spawndak.ncs" so I put exactly that in there.Hehehe... just the kinda thing I want TB12 to add to his little conditional tutorial *pokes TimBob12* :D

As TB12 said, eliminate the file extension (.ncs) anytime you are using the game's resources to call on, well, anything, just about!

Place it just where you are guessing, Dak. Sometimes animations will not fire properly on reply nodes, but scripts seem to fire whether on an entry or a reply, so place it on the dialog line that seems best!
 TimBob12
01-29-2011, 4:29 PM
#6
I will do it. Patience is a virtue. Annakin had no patience and look what happened to him :o
 Qui-Gon Glenn
01-29-2011, 8:42 PM
#7
^^^ :lol:

:lightning
 Dak Drexl
02-14-2011, 10:30 AM
#8
I'm writing a conditional that I want to unlock a dlg node if the PC is at least level 9 and has a certain datapad in the inventory, but my script won't compile.


int StartingConditional()
{
object oPC= GetFirstPC();

int nLevel = GetHitDice(oPC);

//insert item resref
object oPad1= GetItemPossessedBy(oPC, "dd_data1");



if (nLevel >= 9) && ((GetIsObjectValid(oPad1))

{
return TRUE;
}
return FALSE;
}




Also, I had a script before that I was using that only checked the level of the PC that worked fine. I just tried to add the datapad part, but here's the original script if that helps at all:

int StartingConditional(){ object oPC= GetFirstPC();

int nLevel = GetHitDice(oPC);
if (nLevel >= 9)
{
return TRUE;
}
return FALSE;}
 TimBob12
02-14-2011, 11:04 AM
#9
int StartingConditional()
{
object oPC= GetFirstPC();

int nLevel = GetHitDice(oPC);

//insert item resref
object oPad1= GetItemPossessedBy(oPC, "dd_data1");



if (nLevel >= 9 || GetIsObjectValid(oPad1))

{
return TRUE;
}
else
{
return FALSE;
}
}


Try that, thats the way to do multiple conditions. I don't know whether that will work with the kotor engine. Do you still want me to reply to your PM?

EDIT: That compiles fine.
 Dak Drexl
02-14-2011, 11:43 AM
#10
Thank you I'll test this right away. And please do respond to that because I'm hoping to attach that to this code as well.
 stoffe
02-14-2011, 11:46 AM
#11
I'm writing a conditional that I want to unlock a dlg node if the PC is at least level 9 and has a certain datapad in the inventory, but my script won't compile.


Mismatching parentheses in the if statement, at a quick glance.

if (nLevel >= 9) && ((GetIsObjectValid(oPad1))

...should be...

if ((nLevel >= 9) && GetIsObjectValid(oPad1))

You could also trim the function down a bit by eliminating unneeded variables:

int StartingConditional() {
object oPC= GetFirstPC();
return ((GetHitDice(oPC) >= 9) && GetIsObjectValid(GetItemPossessedBy(oPC, "dd_data1")));
}
 Qui-Gon Glenn
02-15-2011, 3:27 AM
#12
int StartingConditional() {
object oPC= GetFirstPC();
return ((GetHitDice(oPC) >= 9) && GetIsObjectValid(GetItemPossessedBy(oPC, "dd_data1")));

}

This is very informative. Thank you!
Page: 1 of 1