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
On death script question
Débuté par
PJ156
, mars 03 2012 09:09
#1
Posté 03 mars 2012 - 09:09
#2
Posté 03 mars 2012 - 09:35
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.
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
Posté 03 mars 2012 - 09:42
Hello PJ,
I usually put no test at all. I have never encountered any trouble. Including in battles involving PC, companions and other allies.
I usually put no test at all. I have never encountered any trouble. Including in battles involving PC, companions and other allies.
#4
Posté 03 mars 2012 - 01:22
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
Posté 03 mars 2012 - 03:17
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.
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
Posté 03 mars 2012 - 06:59
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.
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
Posté 03 mars 2012 - 08:23
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
Cheers,
PJ





Retour en haut







