View Single Post
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