Aller au contenu

Photo

Could use a hand with a script...


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

#1
Nic Mercy

Nic Mercy
  • Members
  • 181 messages

I have a few quest related npc's that put a local variable and update the pc's quest log when killed. Unfortunately if the pc has a summon or familiar and that minion gets the killing blow the update doesn't occur. My scripting ability is limited (I was not the original author of the script in question and it is quite old), but I can often reverse engineer existing scripts to my purposes.

 

Is there a way to have an ondeath script that places a variable and updates the pc's journal if they have the proper quest even if a pet or minion (or fellow party member) gets the killing blow? If someone could show me an example of such a mob on_death script I'd greatly appreciate it.



#2
WhiZard

WhiZard
  • Members
  • 1 204 messages

The GetMaster() function can be used to go up the master chain, but you probably want something more robust in case the NPC kills itself (e.g. with acid fog) during the battle.  I'd probably go by getting the nearest PC when the NPC dies to guarantee that someone would get credit.


  • Kato - aime ceci

#3
Nic Mercy

Nic Mercy
  • Members
  • 181 messages

Here's an example of the relevant section of script I am working with currently:

#include "j_inc_constants"
#include "nw_j_assassin"

void DeathCheck(int iDeaths);
void ClearSlot(int iSlotID);
void PartyGold(object oPC);
void main()
{
// initialise local variables
int nKillFlag = GetLocalInt(GetLastKiller(), "KILL_TASK_FLAG");
object oPC = GetLastKiller();
while (GetIsObjectValid(GetMaster(oPC)))
   {
   oPC=GetMaster(oPC);
   }
   if (!GetIsPC(oPC)) return;
string sTagSelf = GetTag(OBJECT_SELF);
string sTagTarget = GetLocalString(oPC, "KILL_TASK_TARGET");
PartyGold(oPC);
{
    if(GetIsPC(GetLastKiller()) &&
       GetLocalInt(GetLastKiller(),"NW_JOURNAL_ENTRY"  + "journalID") == 1)
    {
 AddJournalQuestEntry ("journalID", 2, oPC);
    }
}
aSetPLocalInt(GetLastKiller(), "nKilledQuestTarget", 1);
    SpeakString("npc says something when dying...", TALKVOLUME_TALK);
// check for correct kill task target and complete
if(sTagSelf == sTagTarget && nKillFlag == 1) {
SetLocalInt(oPC, "KILL_TASK_FLAG", 2);
AddJournalQuestEntry("kt_journal_01", 99, oPC);
}


#4
Kato -

Kato -
  • Members
  • 392 messages

What do you want the code to do if the killer is dead when the OnDeath script runs? Could be nothing, or give credit to party members within a distance, as suggested by Whizard.

 

 

Kato



#5
Nic Mercy

Nic Mercy
  • Members
  • 181 messages

What do you want the code to do if the killer is dead when the OnDeath script runs? Could be nothing, or give credit to party members within a distance, as suggested by Whizard.

 

 

Kato

 

Hmm is it possible for it to give credit to everyone in the party even if someone in the party didnt survive till the end?



#6
Kato -

Kato -
  • Members
  • 392 messages

Good question actually, since performing actions on a dead PC is a bit tricky. I'll try to think of something...

 

 

Kato 



#7
Nic Mercy

Nic Mercy
  • Members
  • 181 messages

Good question actually, since performing actions on a dead PC is a bit tricky. I'll try to think of something...

 

 

Kato 

 

At the very least, as long as the surviving pc/party members get quest credit if a pet or summon gets the killing blow I'd be happy.



#8
Kato -

Kato -
  • Members
  • 392 messages

It might look like this, yet there are some elements I don't possess, so you'll probably have to adjust the code to your exact needs.

 

void main()
{
   object oKiller = GetLastKiller();
   while(GetMaster(oKiller) != OBJECT_INVALID) oKiller = GetMaster(oKiller);   
   if(GetIsDM(oKiller) || GetIsDMPossessed(oKiller)) return;
 
   SpeakString("npc says something when dying...", TALKVOLUME_TALK);
 
   string sTagSelf = GetTag(OBJECT_SELF);
   object oMember = GetFirstFactionMember(oKiller);
   while(oMember != OBJECT_INVALID)
   {      
      if(sTagSelf == GetLocalString(oMember, "KILL_TASK_TARGET") && GetLocalInt(oMember, "KILL_TASK_FLAG") == 1)
      {
         SetLocalInt(oMember, "KILL_TASK_FLAG", 2);
         AddJournalQuestEntry("kt_journal_01", 99, oMember);
      }
      if(GetLocalInt(oMember, "NW_JOURNAL_ENTRY"+"journalID") == 1) AddJournalQuestEntry("journalID", 2, oMember);
      SetLocalInt(oMember, "nKilledQuestTarget", 1); // should probably go in one of the "if" conditions...
      oMember = GetNextFactionMember(oKiller);
   }
}
 
 
Kato

  • Nic Mercy aime ceci

#9
Nic Mercy

Nic Mercy
  • Members
  • 181 messages

 

It might look like this, yet there are some elements I don't possess, so you'll probably have to adjust the code to your exact needs.

 

void main()
{
   object oKiller = GetLastKiller();
   while(GetMaster(oKiller) != OBJECT_INVALID) oKiller = GetMaster(oKiller);   
   if(GetIsDM(oKiller) || GetIsDMPossessed(oKiller)) return;
 
   SpeakString("npc says something when dying...", TALKVOLUME_TALK);
 
   string sTagSelf = GetTag(OBJECT_SELF);
   object oMember = GetFirstFactionMember(oKiller);
   while(oMember != OBJECT_INVALID)
   {      
      if(sTagSelf == GetLocalString(oMember, "KILL_TASK_TARGET") && GetLocalInt(oMember, "KILL_TASK_FLAG") == 1)
      {
         SetLocalInt(oMember, "KILL_TASK_FLAG", 2);
         AddJournalQuestEntry("kt_journal_01", 99, oMember);
      }
      if(GetLocalInt(oMember, "NW_JOURNAL_ENTRY"+"journalID") == 1) AddJournalQuestEntry("journalID", 2, oMember);
      SetLocalInt(oMember, "nKilledQuestTarget", 1); // should probably go in one of the "if" conditions...
      oMember = GetNextFactionMember(oKiller);
   }
}
 
 
Kato

 

 

 

Thanks for the example! I'll see if I can work it to my needs!

 

EDIT: just incorporated your example into my primary script and it worked! TY SO MUCH!