Aller au contenu

Photo

On death script question


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

#1
PJ156

PJ156
  • Members
  • 2 988 messages
What should be the structure for an on death script that fires regarless of who kills the npc. It seems that whenever I write one they are very unrieliable and don't always fire. I am putting this down to the fact that an npc put in the last blow but I'm not actually sure.

Is it enought just to put GetLastKiller() at the start or should I put no test at all?

Thanks,

PJ 

#2
Morbane

Morbane
  • Members
  • 1 883 messages
GetLastKiller() is more functional for an NPC script. Something for the player(s) OnDeathScript should always fire when the player dies, regardless what killed it. But if you need to know specifically what NPC killed the player then I think you may have to use the test.

There may be other tests that will function to that end but if you are having reliability problems a more detailed dissection may be needed for your script - which might require your script to be posted.

#3
Claudius33

Claudius33
  • Members
  • 258 messages
Hello PJ,

I usually put no test at all. I have never encountered any trouble. Including in battles involving PC, companions and other allies.

#4
PJ156

PJ156
  • Members
  • 2 988 messages

Morbane wrote...

GetLastKiller() is more functional for an NPC script.


My bad I posted while trying to prepare toast for four children ...

I am looking at an npc on deathscript; the full script is this:

void main()
{
object oPC = GetLastKiller();
while (GetIsObjectValid(GetMaster(oPC)))
   {
   oPC=GetMaster(oPC);
   }
if (!GetIsPC(oPC)) return;
object oTarget;
oTarget = GetObjectByTag("1005_cs2_speaker");
AssignCommand(oTarget, ActionStartConversation(oPC, ""));
}

It's a lilac soul script.

I have often had to try to work around on death scripts for this very reason, they always seem unreliable. Here, as you can see I simply want to start a convo when the npc dies. When I tested with a single player it always works. When I test with the party it often does not. I have put this down to an npc putting in the final damage but perhaps it's something else?

Do yours differ from this Claudius?

Thanks,

PJ

Modifié par PJ156, 03 mars 2012 - 01:23 .


#5
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
GetNearestObjectByType(PC)?

or, if you don't mind being sloppy, just GetFirstPC().

But I would also but the GetIsPC check higher up, just after GetLastKiller, and then send some feedback (SendMessageToPc(GetFirstPC(), GetTag(oPC)) ) to try and figure out when and why it's failing.

#6
Claudius33

Claudius33
  • Members
  • 258 messages
You don't really need to test, you can simpy have :

oPC = GetFirstPC();
oTarget = ...
AssignCommand ...

The problem comes probably because either the PC or the Target is still busy in combat and that kills the convo.
You may try the sequence :

AssignCommand(oPC, ClearAllActions(TRUE));
AssignCommand(oTarget, ClearAllActions());
DelayCommand(0.2f, AssignCommand(oTarget, ActionStartConversation(oPC, "")));

It is more robust but may fail very rarely. If you want to be 100% sure just update the journal in the on death script, saying to the player to talk to the Target. Or control that the PC can't leave the area if s/he has not talked to the Target yet.

Modifié par Claudius33, 03 mars 2012 - 08:15 .


#7
PJ156

PJ156
  • Members
  • 2 988 messages
I did wonder why the script put the test in. Thanks for the posts, I will try to clear all actions and take the post out. I can hard wire a back up for if the script fails but it will be cludgy.

Cheers,

PJ