Journal Entry Upon NPC Death

Post » Fri May 27, 2011 12:03 pm

This is my first time actually trying to write my own script of this type. It seems as if it might be the same as a script using OnPCAdd, but changed to OnDeath. I want the player to get a final quest journal entry upon killing an NPC.

begin npcdeath

short OnDeath
short doonce

if ( doonce == 1 )
return
endif

if ( OnDeath == 1 )
set doonce to 1
Journal "name of entry here"
return
endif

end

I would attach this script to the NPC to be killed (or whichever script version works correctly). Is this script correct?
User avatar
James Smart
 
Posts: 3362
Joined: Sun Nov 04, 2007 7:49 pm

Post » Fri May 27, 2011 5:50 pm

It should work. Just remember that the Journal command is Journal "journal_id" #, where # is the actual number of the journal entry you want to add.
User avatar
Nathan Risch
 
Posts: 3313
Joined: Sun Aug 05, 2007 10:15 pm

Post » Fri May 27, 2011 6:59 am

Yes, as in the index number. Got that. Now to test this out.
User avatar
Rudy Paint fingers
 
Posts: 3416
Joined: Sun Nov 11, 2007 1:52 am

Post » Fri May 27, 2011 5:27 pm

Yes, as in the index number. Got that. Now to test this out.


This is directly from one of my mods and works fine

Begin 1p_aldorn_death

Short OnPCHitMe


If (GetJournalIndex P1_Eddie < 140)
Return
Endif

If (OnPCHitMe == 1)
StartCombat, Player
SetFight 100
Set aldornattack to 1
Endif


If (OnDeath == 1)
Journal P1_Eddie 160
Endif

End


I use the journal entry index to force return the script rather than just the NPC's death because if you kill the NPC before taking on the connected quest it would add the journal entry even if you have not taken the quest on yet.
User avatar
Frank Firefly
 
Posts: 3429
Joined: Sun Aug 19, 2007 9:34 am

Post » Fri May 27, 2011 3:20 pm

Ok, so i'm trying to understand how this script works. I'm still new at this stuff. So the first line "If (GetJournalIndex P1_Eddie < 140)" says less than journal index 140, but the final journal entry is 160 for death. Can you give me the basics on how this script works so i can understand it better? I also have some dialog for the NPC, so how would I fit that in there along with this script?



Edit: Could I just put this in the Results box of the last dialog of the NPC?

if ( OnDeath == 1 )
Journal such and such
endif
User avatar
gandalf
 
Posts: 3400
Joined: Wed Feb 21, 2007 6:57 pm

Post » Fri May 27, 2011 6:04 pm

No, it has to be in the NPC's script. The script you posted earlier would work, or you could use if ( GetHealth <= 0 ) instead of OnDeath if you're having problems with the journal not updating after the NPC dies. The problem with putting it into the results box is that the NPC won't be talking while dying so you need to have a script that watches for that and acts accordingly.
User avatar
Suzie Dalziel
 
Posts: 3443
Joined: Thu Jun 15, 2006 8:19 pm

Post » Fri May 27, 2011 1:11 pm

Ok. The original script I was using didn't work. The journal entry wasn't updated on the NPC's death. I'm going to try the shorter one above and see if it works.
User avatar
Rebecca Clare Smith
 
Posts: 3508
Joined: Fri Aug 04, 2006 4:13 pm

Post » Fri May 27, 2011 11:41 am

I've heard people say that OnDeath is undependable, and one suggestion I've heard to get around it is to use a GetDeadCount script instead.
User avatar
Ernesto Salinas
 
Posts: 3399
Joined: Sat Nov 03, 2007 2:19 pm

Post » Fri May 27, 2011 5:48 pm

If you know there will only ever be one of the NPC, and you're adding a new NPC (not modifying one from the original game), put this script on it:
if ( "player"->GetJournalIndex "topic" < 160 )    if ( GetHealth < 1 )        "player"->Journal "topic" 160    endifendif


That should do the trick. Just as a side-note, health of 1 is usually considered dead for NPCs.
User avatar
Juanita Hernandez
 
Posts: 3269
Joined: Sat Jan 06, 2007 10:36 am

Post » Fri May 27, 2011 9:00 pm

I've heard people say that OnDeath is undependable, and one suggestion I've heard to get around it is to use a GetDeadCount script instead.


It is. GetHealth or GetHealthGetRatio (uses a float) are better.
User avatar
Allison Sizemore
 
Posts: 3492
Joined: Wed Jul 19, 2006 6:09 am

Post » Fri May 27, 2011 8:24 am

It is. GetHealth or GetHealthGetRatio (uses a float) are better.


I'd never encountered GetHealthGetRatio (I just looked it up at UESP), but I can immediately see several good uses for it...
User avatar
Rebecca Dosch
 
Posts: 3453
Joined: Thu Jan 18, 2007 6:39 pm


Return to III - Morrowind