Jump to content

Home

Scripting Trouble...


Dak Drexl

Recommended Posts

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.

Link to comment
Share on other sites

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()
{
   [color=darkorange]// object oYourItem = GetObjectByTag("your_tag");[/color]
   [color=darkorange]// object oPC = GetFirstPC();[/color]
   ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_DEATH);
   [color=darkorange]// ActionGiveItem(oYourItem, oPC);[/color]
   /*
   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

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 3 weeks later...

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;}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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")));
}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...