Author Topic: Could use a hand with a script...  (Read 404 times)

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Could use a hand with a script...
« on: April 03, 2015, 02:15:22 am »


               

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.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Could use a hand with a script...
« Reply #1 on: April 03, 2015, 02:35:29 am »


               

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.



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Could use a hand with a script...
« Reply #2 on: April 03, 2015, 02:54:37 am »


               

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);
}


               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Could use a hand with a script...
« Reply #3 on: April 03, 2015, 04:16:39 am »


               

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



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Could use a hand with a script...
« Reply #4 on: April 03, 2015, 04:28:16 am »


               


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?


               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Could use a hand with a script...
« Reply #5 on: April 03, 2015, 03:33:01 pm »


               

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


 


 


Kato 



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Could use a hand with a script...
« Reply #6 on: April 03, 2015, 11:02:54 pm »


               


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.


               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Could use a hand with a script...
« Reply #7 on: April 04, 2015, 04:51:37 pm »


               

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


               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Could use a hand with a script...
« Reply #8 on: April 04, 2015, 10:18:31 pm »


               


 


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!