Aller au contenu

Photo

Question about GetLastKiller.


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
andysks

andysks
  • Members
  • 1 650 messages

Hi all. I just want to know/clarify what the thing that Lilac's says is when I create an OnDeath script with it.

 

If you choose to treat the PC as the killer, the script will forget which associate landed the killing blow, instead acting as if the PC landed it. If you choose to keep the associate as the killer, then that associate will be treated no differently than any other NPC (including having the script abort for lack of a PC, if you chose that option).

 

If I choose "treat the PC as the killer", the script becomes.

// Get the creature who triggered this event.
    object oPC = GetLastKiller();

    // We are really interested in the ultimate master of the killer.
    while ( GetMaster(oPC) != OBJECT_INVALID )
        oPC = GetMaster(oPC);

So here's the main question.

If I leave a script like

object oPC = GetLastKiller();

Without the second part... what happens then if a companion makes the killing? Is this non important in NWN2, or... in general, how should an OnDeath start in order to know that it will fire in any case?

 

P.S Any case of course means not a random creature killing the NPC, but the party :D.

 

I ask because I have quite some instances where the journal gets updated through a kill, and I want to be certain that it will always do. Thanks a lot! As always :).



#2
Tchos

Tchos
  • Members
  • 5 054 messages

If the death of the NPC should always update the journal, no matter who kills it, then don't put the journal update inside a conditional check.  If it's possible for a random creature to kill the NPC before the party even shows up, then that's a different problem that I'd address in other ways.



#3
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

You should use the first bit of code if you want the journal to update when the PC's party kills a creature.



#4
4760

4760
  • Members
  • 1 207 messages

Do you want the journal update to also show who actually killed the NPC?



#5
kevL

kevL
  • Members
  • 4 061 messages

object oPC = GetLastKiller();

if (GetIsObjectValid(GetFactionLeader(oPC)))
{
    // killed by party (and only party).
}


#6
PJ156

PJ156
  • Members
  • 2 983 messages

In my experience any script in the on death section will run on the creatures death. GetLastKiller() is just a test to see who did it, it is not a required part of the on death script that makes it fire or function. So write any script you want there and it should fire.

 

PJ

 

PS: I think that's what Tchos said but in a different way  :P



#7
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

I ran in to this bug in a PW setting when I had an area with a walkmesh that differed from the terrain. The items were dropping to the terrain despite a walkmesh helper being baked well above it. IIRC this bug only appeared in interior areas but it could be replicated outdoors as well.



#8
andysks

andysks
  • Members
  • 1 650 messages

Thanks for the info.

 

PJ: that could be the case...

 

But do we mean that if a script looks like that

void main()
{
    object oPC = GetFirstPC();

    GiveGoldToCreature(oPC, 20);
}

would fire fine no matter what just because it's on the OnDeath event? And killed by anyone... PC, companion, NPC... the weather... whatever. Just... died.

Whereas KevL's addition makes it fire only for PC and party. Just in case there is a chance he'll die before the PC reaches. Even though that should never be possible... but still. I guess. Did I get it correct :)?

 

4760: No, just journal update. Like: You killed that guy, go back to that guy.



#9
kevL

kevL
  • Members
  • 4 061 messages

... anyone.

 

 

ps. you might want to update to different journal entries, depending on whether PC-faction was the slayer or not, like

Entry #1: you killed the Giant ...

Entry #2: the Giant was slain ...



#10
PJ156

PJ156
  • Members
  • 2 983 messages

Thanks for the info.

 

PJ: that could be the case...

 

But do we mean that if a script looks like that

void main()
{
    object oPC = GetFirstPC();

    GiveGoldToCreature(oPC, 20);
}

would fire fine no matter what just because it's on the OnDeath event? And killed by anyone... PC, companion, NPC... the weather... whatever. Just... died.

Whereas KevL's addition makes it fire only for PC and party. Just in case there is a chance he'll die before the PC reaches. Even though that should never be possible... but still. I guess. Did I get it correct :)?

 

4760: No, just journal update. Like: You killed that guy, go back to that guy.

 

 

I believe so :)

 

PJ