Raised This Month: $32 Target: $400
 8% 

Sending "player_death" event doesn't work


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NeoTrantor
Member
Join Date: Mar 2009
Location: Germany
Old 06-17-2009 , 14:47   Sending "player_death" event doesn't work
Reply With Quote #1

Hi,

what I'm trying is, to send a player_death event out of my hooked player_hurt event. I used the SendDeathMessage example from the wiki. The event in fact does get fired, but nothing happens - the player doesn't die. I also tried to use timers instead of firing the event directly from the player_hurt event with no success. Any help would be appreciated!

Code:
public OnPluginStart()
{
  HookEvent("player_hurt", EventPlayerHurt);
  HookEvent("player_death", EventPlayerDeath);
}

public Action:EventPlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new nClientVictim        = GetClientOfUserId(GetEventInt(event, "userid"));
    new nClientAttacker    = GetClientOfUserId(GetEventInt(event, "attacker"));
    new nDamage                    = GetEventInt(event, "dmg_health");
    new String:sWeapon[64];
    GetEventString(event, "weapon", sWeapon, sizeof(sWeapon));

    SendDeathMessage(nClientAttacker, nClientVictim, sWeapon, false);

    return Plugin_Continue;
}

public Action:EventPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new nClientVictim        = GetClientOfUserId(GetEventInt(event, "userid"));

    PrintToChatAll("EventPlayerDeath Client: %d", nClientVictim);

    return Plugin_Continue;
}

public SendDeathMessage(attacker, victim, const String:weapon[], bool:headshot)
{
    new Handle:event = CreateEvent("player_death");
    if(event == INVALID_HANDLE)
        return;
 
    SetEventInt(event, "userid", GetClientUserId(victim));
    SetEventInt(event, "attacker", GetClientUserId(attacker));
    SetEventString(event, "weapon", weapon);
    SetEventBool(event, "headshot", headshot);
    FireEvent(event);
}
NeoTrantor is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 06-17-2009 , 15:24   Re: Sending "player_death" event doesn't work
Reply With Quote #2

Events don't tell the game something is happening, the game tells the events when something is happening.

So firing player_death doesn't kill a player, but killing a player fires player_death.

ForcePlayerSuicide would get the job done, and if you hook the player_death pre (see enum EventHookMode) and then set the weapon, headshot, all the player_death keys then that should work out.

And make sure to return with

Code:
return Plugin_Changed;
at the end of the function.
__________________
Greyscale is offline
NeoTrantor
Member
Join Date: Mar 2009
Location: Germany
Old 06-17-2009 , 17:41   Instant kill with knockback
Reply With Quote #3

Oh, ok seems like I misunderstood the sm event system.
Using your solution kills the victim but the kill doesn't get announced by the game at all, the player just dies.

Code:
...
HookEvent("player_death", EventPlayerDeathPre, EventHookMode_Pre);
...
public Action:EventPlayerDeathPre(Handle:event, const String:name[], bool:dontBroadcast)
{
  SetEventInt(event, "attacker", GetClientUserId(g_nClientAttacker));
  SetEventString(event, "weapon", "knife");

  return Plugin_Changed;
}
What I want to do is to give players instant kills with a nice knockback effect. So what I've got so far is this:

Code:
public Action:EventPlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new nClientVictim      = GetClientOfUserId(GetEventInt(event, "userid"));
    new nClientAttacker    = GetClientOfUserId(GetEventInt(event, "attacker"));
    ImpactKnockback(nClientAttacker, nClientVictim, 800);

    new nOffsetHP = FindDataMapOffs(nClientVictim, "m_iHealth");
    SetEntData(nClientVictim, nOffsetHP, 0, true);

    return Plugin_Continue;
}
public ImpactKnockback(nClientAttacker, nClientVictim, Float:fKnockback)
{
    new Float:pfEyeAngles[3];
    GetClientEyeAngles(nClientAttacker, pfEyeAngles);

    new Float:pfKnockbackAngles[3];
    pfKnockbackAngles[0] = FloatMul(Cosine(DegToRad(pfEyeAngles[1])), fKnockback);
    pfKnockbackAngles[1] = FloatMul(Sine(DegToRad(pfEyeAngles[1])), fKnockback);
    pfKnockbackAngles[2] = FloatMul(Sine(DegToRad(pfEyeAngles[0])), fKnockback);

    TeleportEntity(nClientVictim, NULL_VECTOR, NULL_VECTOR, pfKnockbackAngles);
}
This kills the victim, announces the kill and the attacker gets his frag - so far so good. But the knockback only effects the victmis equipment it drops, like weapons etc. The body just falls as it always does so I think the death animation doesn't get affected by TeleportEntity? I also tried to delay the change of m_iHealth to 0 by a timer, so the player gets knocked back and dies then. For some reason the player doesn't die in this case although he has 0 HP. Setting m_iHealth to 1 in pre-player_hurt doesn't work either.
I'm afraid there is no way to do this in sourcemod... Or am I missing something?

Last edited by NeoTrantor; 06-17-2009 at 17:44.
NeoTrantor is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 06-17-2009 , 21:49   Re: Sending "player_death" event doesn't work
Reply With Quote #4

Setting a player's health to 0 doesn't kill them, you have to actually damage them to 0 to kill them.
Dragonshadow is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-18-2009 , 00:56   Re: Sending "player_death" event doesn't work
Reply With Quote #5

Pre-player_hurt isn't before the player takes damage, it's before the event has fired. The player has already taken the damage at that point.

For throwing around the body, when the player dies a separate ragdoll entity is spawned as a replacement, so pushing the real player before death won't necessarily help. Someone else will probably know more about this.
Fyren is offline
NeoTrantor
Member
Join Date: Mar 2009
Location: Germany
Old 06-18-2009 , 03:53   Re: Sending "player_death" event doesn't work
Reply With Quote #6

Quote:
Originally Posted by Dragonshadow View Post
Setting a player's health to 0 doesn't kill them, you have to actually damage them to 0 to kill them.
In this case it actually does to my own surprise. Try the code above, if you slice a Player with the knife once he instantly dies and you get a regular frag.

Quote:
Originally Posted by Fyren View Post
Pre-player_hurt isn't before the player takes damage, it's before the event has fired. The player has already taken the damage at that point.
Ok, so i have mistaken the event system once again

Quote:
Originally Posted by Fyren View Post
For throwing around the body, when the player dies a separate ragdoll entity is spawned as a replacement, so pushing the real player before death won't necessarily help. Someone else will probably know more about this.
Sounds good, this seems to be the only solution for this problem. I'll try it this way.
NeoTrantor is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 06-18-2009 , 07:02   Re: Sending "player_death" event doesn't work
Reply With Quote #7

Quote:
Originally Posted by NeoTrantor View Post
In this case it actually does to my own surprise. Try the code above, if you slice a Player with the knife once he instantly dies and you get a regular frag.
Once you've set their hp to 0, any damage will kill them.
Dragonshadow is offline
NeoTrantor
Member
Join Date: Mar 2009
Location: Germany
Old 06-18-2009 , 07:12   Re: Sending "player_death" event doesn't work
Reply With Quote #8

If I got it right, the player_hurt event occurs after the player was hit, so this confuses me a bit...
NeoTrantor is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 06-18-2009 , 07:59   Re: Sending "player_death" event doesn't work
Reply With Quote #9

If I remember correctly it depends on when you hook the event.
Edit: I wonder what happens if you set someone's hp to negative?
Dragonshadow is offline
NeoTrantor
Member
Join Date: Mar 2009
Location: Germany
Old 06-18-2009 , 13:07   Instant kill with knockback
Reply With Quote #10

Finally I got it. I use the Dukehacks extension for killing the victim and some pretty dirty code to get that knockback effect

Code:
...
public OnPluginStart()
{
  ...
  HookEvent("player_hurt", EventPlayerHurt);
  ...
}
...
public Action:EventPlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
  new nClientVictim      = GetClientOfUserId(GetEventInt(event, "userid"));
  new nClientAttacker    = GetClientOfUserId(GetEventInt(event, "attacker"));

  ImpactKnockback(nClientAttacker, nClientVictim, 800.0); // see posts above
  CreateTimer(0.1, TimerKillPlayer, nClientAttacker | (nClientVictim << 8));
}

public Action:TimerKillPlayer(Handle:timer, any:nClients)
{
    new nClientVictim      = (nClients & 0xFF00) >> 8;
    new nClientAttacker    = (nClients & 0x00FF);

    dhKillPlayer(nClientVictim, nClientAttacker, "what_ever_weapon_you_want");
}
This knocks the player back and kills him shortly after that which results in what I wanted to have. This will be added to the next version of my "Roll The Dice" plugin (http://forums.alliedmods.net/showthread.php?t=94835) soon so you can see it in action

Many thanks for all your help guys!
NeoTrantor is offline
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 11:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode