EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Player Death (https://www.eqemulator.org/forums/showthread.php?t=37759)

thepoetwarrior 01-19-2014 08:19 AM

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?

Kingly_Krab 01-19-2014 08:45 AM

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?

thepoetwarrior 01-19-2014 09:37 PM

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.

demonstar55 01-19-2014 09:57 PM

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

thepoetwarrior 01-19-2014 11:07 PM

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


demonstar55 01-19-2014 11:17 PM

Well, it's setting data, but I don't think it's being exported :P

Akkadius 01-19-2014 11:18 PM

Quote:

Originally Posted by demonstar55 (Post 227760)
Well, it's setting data, but I don't think it's being exported :P

Helping Kingly work on exporting it right now

demonstar55 01-19-2014 11:20 PM

Quote:

Originally Posted by Akkadius (Post 227761)
Helping Kingly work on exporting it right now

Only caveat I see is that the player event and NPC event have different data.

Kingly_Krab 01-20-2014 02:21 AM

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.

NatedogEZ 01-20-2014 02:49 AM

Tested this as well and it worked nicely for me :)

demonstar55 01-20-2014 03:03 AM

Pushed it, it also fixed a problem with the way lua was handling the variables :P

Kingly_Krab 01-20-2014 03:05 AM

Quote:

Originally Posted by demonstar55 (Post 227772)
Pushed it, it also fixed a problem with the way lua was handling the variables :P

Great, thanks for the push.

lerxst2112 01-20-2014 02:55 PM

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.

Kingly_Krab 01-20-2014 03:15 PM

Quote:

Originally Posted by lerxst2112 (Post 227780)
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.


All times are GMT -4. The time now is 05:28 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.