Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

Reply
 
Thread Tools Display Modes
  #1  
Old 01-19-2014, 08:19 AM
thepoetwarrior
Discordant
 
Join Date: Aug 2007
Posts: 307
Default Player Death

Code:
sub EVENT_ZONE
{
	my $GET_HP = $client->GetHP();
	if ($GET_HP < 0)
	{
		quest::we(13, "$name has been killed in $zonesn!");
	}
}
Is there a better way to detect if a player died? Also a way to find out how the player died, who killed the player?
Reply With Quote
  #2  
Old 01-19-2014, 08:45 AM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,589
Default

You can use sub EVENT_DEATH in player scripts, as far as getting what or who killed the player, you can't, there's no variable. NPCs have $targetname and $targetid for what killed them, possibly try that?
Reply With Quote
  #3  
Old 01-19-2014, 09:37 PM
thepoetwarrior
Discordant
 
Join Date: Aug 2007
Posts: 307
Default

I know sub EVENT_DEATH became EVENT_DEATH_COMPLETE last year for NPC. So I tried sub EVENT_DEATH_COMPLETE for player.pl and didn't work, maybe will have to try the old sub EVENT_DEATH instead, see if that returns anything?

Would like to find out who killed the player, for pvp purpose too.
Reply With Quote
  #4  
Old 01-19-2014, 09:57 PM
demonstar55
Demi-God
 
Join Date: Apr 2008
Location: MA
Posts: 1,165
Default

EVENT_DEATH still exists, it just happens at the start of the death functions instead of the end. EVENT_DEATH_COMPLETE happens at the end. Both pass this data along snprintf(buffer, 47, "%d %d %d %d", killerMob ? killerMob->GetID() : 0, damage, spell, static_cast<int>(attack_skill));

For NPC death, they both pass snprintf(buffer, 31, "%d %d %d", damage, spell, static_cast<int>(attack_skill));
Reply With Quote
  #5  
Old 01-19-2014, 11:07 PM
thepoetwarrior
Discordant
 
Join Date: Aug 2007
Posts: 307
Default

Just confirmed, EVENT_DEATH works in player.pl

Was even able to log via write() and have the GetHP() logged of current HP at the time of death.

Wonder how to find out what caused the death, and from who.

Need to create a variable for it I'm guessing.

Code:
sub EVENT_DEATH
{
	my $GET_HP = $client->GetHP();
	quest::write("EVENT_DEATH.txt","$name HP = $GET_HP");
}
Reply With Quote
  #6  
Old 01-19-2014, 11:17 PM
demonstar55
Demi-God
 
Join Date: Apr 2008
Location: MA
Posts: 1,165
Default

Well, it's setting data, but I don't think it's being exported :P
Reply With Quote
  #7  
Old 01-19-2014, 11:18 PM
Akkadius's Avatar
Akkadius
Administrator
 
Join Date: Feb 2009
Location: MN
Posts: 2,071
Default

Quote:
Originally Posted by demonstar55 View Post
Well, it's setting data, but I don't think it's being exported :P
Helping Kingly work on exporting it right now
Reply With Quote
  #8  
Old 01-19-2014, 11:20 PM
demonstar55
Demi-God
 
Join Date: Apr 2008
Location: MA
Posts: 1,165
Default

Quote:
Originally Posted by Akkadius View Post
Helping Kingly work on exporting it right now
Only caveat I see is that the player event and NPC event have different data.
Reply With Quote
  #9  
Old 01-20-2014, 02:21 AM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,589
Default

With some help from Akkadius I managed to create four new variables:
$killer_id, $killer_damage, $killer_spell, $killer_skill
These are valid in EVENT_DEATH and EVENT_DEATH_COMPLETE, here's a diff of the code.
Code:
--- "zone/attack.cpp"	
+++ "zone/attack.cpp"	
@@ -2042,8 +2042,8 @@
 	if(killerMob) {
 		oos = killerMob->GetOwnerOrSelf();
 
-		char buffer[32] = { 0 };
-		snprintf(buffer, 31, "%d %d %d", damage, spell, static_cast<int>(attack_skill));
+		char buffer[48] = { 0 };
+		snprintf(buffer, 47, "%d %d %d %d", killerMob ? killerMob->GetID() : 0, damage, spell, static_cast<int>(attack_skill));
 		if(parse->EventNPC(EVENT_DEATH, this, oos, buffer, 0) != 0)
 		{
 			if(GetHP() < 0) {
@@ -2058,8 +2058,8 @@
 				killerMob->GetCleanName(), GetCleanName(), ConvertArray(damage, val1));
 		}
 	} else {
-		char buffer[32] = { 0 };
-		snprintf(buffer, 31, "%d %d %d", damage, spell, static_cast<int>(attack_skill));
+		char buffer[48] = { 0 };
+		snprintf(buffer, 47, "%d %d %d %d", killerMob ? killerMob->GetID() : 0, damage, spell, static_cast<int>(attack_skill));
 		if(parse->EventNPC(EVENT_DEATH, this, nullptr, buffer, 0) != 0)
 		{
 			if(GetHP() < 0) {
@@ -2401,8 +2401,8 @@
 
 	entity_list.UpdateFindableNPCState(this, true);
 
-	char buffer[32] = { 0 };
-	snprintf(buffer, 31, "%d %d %d", damage, spell, static_cast<int>(attack_skill));
+	char buffer[48] = { 0 };
+	snprintf(buffer, 47, "%d %d %d %d", killerMob ? killerMob->GetID() : 0, damage, spell, static_cast<int>(attack_skill));
 	parse->EventNPC(EVENT_DEATH_COMPLETE, this, oos, buffer, 0);
 	return true;
 }
@@ -4496,4 +4496,3 @@
 		return damage;
 	}
 }
-

--- "zone/embparser.cpp"	
+++ "zone/embparser.cpp"	
@@ -1307,6 +1307,18 @@
 			break;
 		}
 
+		case EVENT_DEATH: 
+		case EVENT_DEATH_COMPLETE:
+		{ 
+			Seperator sep(data);
+			ExportVar(package_name.c_str(), "killer_id", sep->arg[0]);
+			ExportVar(package_name.c_str(), "killer_damage", sep->arg[1]);
+			ExportVar(package_name.c_str(), "killer_spell", sep->arg[2]);
+			ExportVar(package_name.c_str(), "killer_skill", sep->arg[3]);
+			break;
+		}
+
 		default: {
 			break;
 		}
Here is a script so you can test it on your server.
Code:
sub EVENT_DEATH_COMPLETE
{
	quest::gmsay("Killer ID: " . $entity_list->GetClientByID($killer_id)->GetName() . " Killer Damage: $killer_damage Killer Spell: $killer_spell Killer Skill: $killer_skill", 335, 1, 0, 250);
}
$killer_id: The entity ID of your Killer.
$killer_damage: The damage of the last hit your Killer did to you.
$killer_spell: The ID of the last spell your Killer hit you with.
$killer_skill: The skill used by the spell or weapon your Killer killed you with.
Reply With Quote
  #10  
Old 01-20-2014, 02:49 AM
NatedogEZ's Avatar
NatedogEZ
Developer
 
Join Date: Dec 2012
Posts: 515
Default

Tested this as well and it worked nicely for me
Reply With Quote
  #11  
Old 01-20-2014, 03:03 AM
demonstar55
Demi-God
 
Join Date: Apr 2008
Location: MA
Posts: 1,165
Default

Pushed it, it also fixed a problem with the way lua was handling the variables :P
Reply With Quote
  #12  
Old 01-20-2014, 03:05 AM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,589
Default

Quote:
Originally Posted by demonstar55 View Post
Pushed it, it also fixed a problem with the way lua was handling the variables :P
Great, thanks for the push.
Reply With Quote
  #13  
Old 01-20-2014, 02:55 PM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,743
Default

Shouldn't need this:
Code:
safe_delete(sep);
The variable is created on the stack and will be destroyed when it goes out of scope. Surprised it doesn't crash. If you don't use new, don't use delete.
Reply With Quote
  #14  
Old 01-20-2014, 03:15 PM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,589
Default

Quote:
Originally Posted by lerxst2112 View Post
Shouldn't need this:
Code:
safe_delete(sep);
The variable is created on the stack and will be destroyed when it goes out of scope. Surprised it doesn't crash. If you don't use new, don't use delete.
Yeah, I forgot to remove it, that wasn't actually committed in the change apparently, so there should be no issue in pulling it.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 08:43 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3