I'm trying to make a plugin so the witch would die from a headshot from any weapon. I tried SDKHooks_TakeDamage and Entity_Hurt, both of those methods work, but show incorrect damage amount in witch damage announce plugin. Is there a way to fix it?
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <smlib>
public OnPluginStart()
{
HookEvent("infected_hurt", WitchHurt_Event, EventHookMode_Post);
}
public WitchHurt_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
new victimEntId = GetEventInt(event, "entityid");
new hitgroup = GetEventInt(event, "hitgroup"); //headshot is 1
if (IsWitch(victimEntId) && hitgroup == 1)
{
//set damage amount to
// SDKHooks_TakeDamage(victimEntId, attacker, attacker, 300.0, DMG_BULLET, -1, NULL_VECTOR, NULL_VECTOR);
Entity_Hurt(victimEntId, 300, attacker);
}
}
stock bool:IsWitch(iEntity)
{
if(iEntity > 0 && IsValidEntity(iEntity) && IsValidEdict(iEntity))
{
decl String:strClassName[64];
GetEdictClassname(iEntity, strClassName, sizeof(strClassName));
return StrEqual(strClassName, "witch");
}
return false;
}
Working code:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <smlib>
public OnEntityCreated(entity, const String:Classname[])
{
if(StrEqual(Classname, "witch"))
{
SDKHook(entity, SDKHook_TraceAttack, Event_TraceAttack);
}
}
public Action:Event_TraceAttack(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotype, hitbox, hitgroup)
{
if(hitgroup == 1)
{
damage += 300.0;
return Plugin_Changed;
}
return Plugin_Continue;
}
stock bool:IsWitch(iEntity)
{
if(iEntity > 0 && IsValidEntity(iEntity) && IsValidEdict(iEntity))
{
decl String:strClassName[64];
GetEdictClassname(iEntity, strClassName, sizeof(strClassName));
return StrEqual(strClassName, "witch");
}
return false;
}