Aller au contenu

Photo

OnDeath scipt not firing


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

#1
Clyordes

Clyordes
  • Members
  • 300 messages
I'm sure I'm missing something obvious here, but please help if you can.  I'm getting some reports of this OnDeath script not firing.  Only problem is I'm having problems replicating the situation, so I'm not sure what I've got wrong. 

Here's the script - who wants to be first to point out the obvious error (I hope):

void main()
{

object oPC = GetLastKiller();

while (GetIsObjectValid(GetMaster(oPC)))
   {
   oPC=GetMaster(oPC);
   }

if (!GetIsPC(oPC)) return;

FloatingTextStringOnCreature("The evil creature finally slumps to the floor - you are victorious!!", oPC);

AddJournalQuestEntry("vileness", 30, oPC, TRUE, FALSE);


}

If it helps - the script is for the main protagonist in my Reptile God adventure, and she's encountered with a bunch of trogs and a viper, all of which attack together.

Many thanks in advance - O great ones!  :(

Cly.

#2
MasterChanger

MasterChanger
  • Members
  • 686 messages
For me, step one in debugging any script at all is to slap a SendMessageToPC at the start (using GetFirstPC if you're in single-player, just as a shortcut) that tells you you're in the script.

You need to isolate the problem: is the script not firing, or is firing but not working as you expect it to?

#3
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
So it looks like when you kill this creature, you want the journal to update and a message to go to the PC. Is that right?

Maybe if would work to not bother checking who killed the creature.

When the creature dies, if you want to have some flavour dialogue, it may be easier to just start an NWN1-style convo, and then update the journal from within the convo. It is a bit easier, and has a nice look to it. May I recommend that you give a 3-4 second delay before starting the convo so you can watch your advesary fall lifeless. It allows time for the catharsis of victory.

#4
Morbane

Morbane
  • Members
  • 1 883 messages
Try using SpeakString instead of FloatingTextString***

#5
Orion7486

Orion7486
  • Members
  • 161 messages

M. Rieder wrote...

Maybe if would work to not bother checking who killed the creature.

That's a good place to look at.  There could be several things that end up doing in your enemy, other than someone in your party.  If a trap laid by your rogue is what kills the npc, does that get traced back to the rogue as the LastKiller.
Also, GetIsPC doesn't return true for all members of your party.  As the explanation reads:
   Returns TRUE if oCreature is a player controlled character.  If the passed in creature is owned by the player, but the player is currently controlling another creature, this will return false.

So, best is to get rid of the check: if (!GetIsPC(oPC)) return;

I still get confused with GetIsPC, GetIsOwnedByPlayer, and companions, familiars, and henchmen.

#6
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
A couple potential problems. Firstly you should get rid of "while" and replace with "if". You aren't looping there so you shouldn't use it. Other possible problem is that Floating text might not being showing up if the creature is dead. You might also have the same problem with SpeakString. You might just want to try and SendMessageToPC and see if that shows up. I tested your script in NWN1 and it did show the line for a second but quickly vanished. However i did also get the message in my dialogue window.

@Orion. The line he has there to check if it is a player is fine since he is changing oPC to the master of non player controlled characters/creatures if one happened to be the last killer.

Hope this helps. Good luck.

Modifié par GhostOfGod, 09 mai 2011 - 02:05 .


#7
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
I can hear the objections coming already, but this is exactly the kind of case where I would just use GetFirstPC. It just doesn't matter who the killer was unless you are allowing each player to have their own journal, which is normally not the case.

My on death boss script is this:
// bb_onbossdeath
// by Brendan Bellina
// May, 2007

/*
This function can be used as a DeathScript for special
boss-type characters. It executes a series of functions
that are often useful when a boss character dies.
*/


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

ExecuteScript("bb_speakstring", OBJECT_SELF);
ExecuteScript("bb_journal_update", OBJECT_SELF);

int nXP = GetLocalInt(OBJECT_SELF, "XP"); // experience points to award
if (nXP) // award experience points
{
object oFM = GetFirstFactionMember(oPC, TRUE);
while( oFM != OBJECT_INVALID )
{
GiveXPToCreature( oFM, nXP );
oFM = GetNextFactionMember(oPC, TRUE);
}
}

// Set local variable ondeath_global to the name of a global integer variable to set to TRUE
// when the boss dies
string GlobalVar = GetLocalString(OBJECT_SELF, "ondeath_global");
if (GlobalVar != "")
SetGlobalInt(GlobalVar, TRUE);

// May want to add an unlock object script in here
// May want to add a drop item script in here
}

bb_speakstring and bb_journal_update issue a speakstring and update the journal, respectively.

All of these script are included with my King's Festival campaign.

Regards

#8
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Not really an objection here Kaldor...but I'm a bit confused. Does GetFirstPC work the same in NWN2 as it does in NWN1?
If I go kill "Goblinoid" the goblin king, why would the first player on the server(and his faction members) get my xp and get credit for killing him?
It is also important to note that GetFirstPC can also return a DM(at least in NWN1). And in the OPs script he is excluding those who are not players.

Kaldor wrote...
unless you are allowing each player to have their own journal, which is normally not the case.

Difference of opinion on this one I guess.;)

Modifié par GhostOfGod, 09 mai 2011 - 05:15 .


#9
Clyordes

Clyordes
  • Members
  • 300 messages
Ah - the gods of scripting are 'IN' today - thanks guys!

I know I'm going to get the usual "Learn to script" comments, and that's fine, but the script - like almost all my scripts that aren't conversation based - was a product of Lilac Soul's generator & it seems that maybe I either entered the wrong info, or it didn't work as it was designed in this case.

Either way, I'll have a bash at fixing it - I like the idea of jumping into a conversation when the Naga & her henchlings are all dead - so I might need to rewrite the script to check that they're all out of action before it fires too.

One question - if a spell that does damage over several rounds, say Combust, eventually kills something, is the spell caster or the spell classed as the 'killer'. Just an idle question really, but it struck me when someone mentioned traps above.

On the sort of good side, I've just tested it with a high level party (love this party editor I've got now its a campaign) & althogh the regular ending script didn't fire, the naga skull I put in her inventory fired it fine. But now I'm wanting to fix the issue 'properly' thanks to your collective help.

Cly.

#10
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages

GhostOfGod wrote...

Not really an objection here Kaldor...but I'm a bit confused. Does GetFirstPC work the same in NWN2 as it does in NWN1?
If I go kill "Goblinoid" the goblin king, why would the first player on the server(and his faction members) get my xp and get credit for killing him?
It is also important to note that GetFirstPC can also return a DM(at least in NWN1). And in the OPs script he is excluding those who are not players.

Kaldor wrote...
unless you are allowing each player to have their own journal, which is normally not the case.

Difference of opinion on this one I guess.;)


For campaigns/modules that are designed for single-player play, GetFirstPC (which just selects the first PC in the party) will be the same as the main PC in the campaign, and for single-player campaigns/modules the journal is shared.  This is not the case for MP play or playing on a PW.  If this campaign/module is intended for MP/PW play then using GetFirstPC would not be appropriate.

Seems like there a lot of use cases to test for. At least:
1. Killed by PC still alive
2. Killed by PC now dead
3. Killed by companion still alive and PC owner still alive
4. Killed by companion now dead and PC owner still alive
5. Killed by companion still alive and PC owner now dead
6. Killed by companion now dead and PC owner now dead
7. Repeat 3-6 for henchman
8. Repeat 3-6 for summoned creatures but also include tests if summoned creature is no longer present

Using GetMaster and GetIsPC to remove some of the use cases seems reasonable, especially since only PC's have journals, so in the end you have to select a PC, either living or dead.

In any event though it is a lot of conditions to test for and not easy to simulate.  My guess is that most modders do not do this kind of testing and just assume their code will work.  And in most cases it probably does.

My campaigns are specifically written by one person (me) and tested by one person (also me). I know that that testing is not going to be sufficient to say for certain that all of my scripts will function correctly in a MP or PW environment.  And so I simply state that they are designed for and tested for single-player.  If you want to play them MP or PW or with a DM then that can be done, but there may be some issues.  Lacking very clear guidance (any really) on scripting practices for MP and PW play, that is all I can do because that is really all I can test.  My preference is to code for something that I can test and works in most cases. I think that is better than trying to code something for all cases but cannot really be tested.

If someone well versed in MP/PW scripting would look at my script and say definitively what should be used rather than GetFirstPC so that the script works reliably for both SP and MP/PW usage then I would welcome that advice.

Regards

Modifié par Kaldor Silverwand, 10 mai 2011 - 02:25 .