|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quests::Q&A This is the quest support section |
01-19-2014, 08:19 AM
|
Discordant
|
|
Join Date: Aug 2007
Posts: 307
|
|
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?
|
01-19-2014, 08:45 AM
|
Administrator
|
|
Join Date: May 2013
Location: United States
Posts: 1,589
|
|
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?
|
01-19-2014, 09:37 PM
|
Discordant
|
|
Join Date: Aug 2007
Posts: 307
|
|
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.
|
01-19-2014, 09:57 PM
|
Demi-God
|
|
Join Date: Apr 2008
Location: MA
Posts: 1,165
|
|
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));
|
01-19-2014, 11:07 PM
|
Discordant
|
|
Join Date: Aug 2007
Posts: 307
|
|
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");
}
|
01-19-2014, 11:17 PM
|
Demi-God
|
|
Join Date: Apr 2008
Location: MA
Posts: 1,165
|
|
Well, it's setting data, but I don't think it's being exported :P
|
01-19-2014, 11:18 PM
|
|
Administrator
|
|
Join Date: Feb 2009
Location: MN
Posts: 2,071
|
|
Quote:
Originally Posted by demonstar55
Well, it's setting data, but I don't think it's being exported :P
|
Helping Kingly work on exporting it right now
|
01-19-2014, 11:20 PM
|
Demi-God
|
|
Join Date: Apr 2008
Location: MA
Posts: 1,165
|
|
Quote:
Originally Posted by Akkadius
Helping Kingly work on exporting it right now
|
Only caveat I see is that the player event and NPC event have different data.
|
|
|
|
01-20-2014, 02:21 AM
|
Administrator
|
|
Join Date: May 2013
Location: United States
Posts: 1,589
|
|
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.
|
|
|
|
01-20-2014, 02:49 AM
|
|
Developer
|
|
Join Date: Dec 2012
Posts: 515
|
|
Tested this as well and it worked nicely for me
|
01-20-2014, 03:03 AM
|
Demi-God
|
|
Join Date: Apr 2008
Location: MA
Posts: 1,165
|
|
Pushed it, it also fixed a problem with the way lua was handling the variables :P
|
01-20-2014, 03:05 AM
|
Administrator
|
|
Join Date: May 2013
Location: United States
Posts: 1,589
|
|
Quote:
Originally Posted by demonstar55
Pushed it, it also fixed a problem with the way lua was handling the variables :P
|
Great, thanks for the push.
|
01-20-2014, 02:55 PM
|
Demi-God
|
|
Join Date: Aug 2010
Posts: 1,743
|
|
Shouldn't need this:
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.
|
01-20-2014, 03:15 PM
|
Administrator
|
|
Join Date: May 2013
Location: United States
Posts: 1,589
|
|
Quote:
Originally Posted by lerxst2112
Shouldn't need this:
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.
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 02:15 AM.
|
|
|
|
|
|
|
|
|
|
|
|
|