Raised This Month: $51 Target: $400
 12% 

Solved [L4D2] Witch headshot


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alcybery
Member
Join Date: Apr 2016
Old 06-18-2018 , 19:50   [L4D2] Witch headshot
Reply With Quote #1

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_EventEventHookMode_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(victimEntId300attacker);
    }
}

stock bool:IsWitch(iEntity)
{
    if(
iEntity && IsValidEntity(iEntity) && IsValidEdict(iEntity))
    {
        
decl String:strClassName[64];
        
GetEdictClassname(iEntitystrClassNamesizeof(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(entitySDKHook_TraceAttackEvent_TraceAttack);
    }
}

public 
Action:Event_TraceAttack(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup)
{

    if(
hitgroup == 1)
    {
        
damage += 300.0;
        return 
Plugin_Changed;
    }

    return 
Plugin_Continue;

}

stock bool:IsWitch(iEntity

    if(
iEntity && IsValidEntity(iEntity) && IsValidEdict(iEntity)) 
    { 
        
decl String:strClassName[64]; 
        
GetEdictClassname(iEntitystrClassNamesizeof(strClassName)); 
        return 
StrEqual(strClassName"witch"); 
    } 
    return 
false


Last edited by alcybery; 06-26-2018 at 13:17.
alcybery is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 06-18-2018 , 22:25   Re: [L4D2] Witch headshot
Reply With Quote #2

What does it say in that plugin?
__________________
Spirit_12 is offline
alcybery
Member
Join Date: Apr 2016
Old 06-19-2018 , 10:22   Re: [L4D2] Witch headshot
Reply With Quote #3

Quote:
Originally Posted by Spirit_12 View Post
What does it say in that plugin?
This plugin says:
Witch has been killed
52826 [26413%]: alcybery

This plugin:
Damage dealt to Witch
0 [0%] Console

In map transition statistics it says damage to the witch is about 4700000.
alcybery is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 06-19-2018 , 16:18   Re: [L4D2] Witch headshot
Reply With Quote #4

Try to set the damage value for "amount" in the event. Seems like that's where the other plugins are catching the value.

https://sm.alliedmods.net/new-api/events/Event/SetInt
__________________
Spirit_12 is offline
alcybery
Member
Join Date: Apr 2016
Old 06-19-2018 , 17:27   Re: [L4D2] Witch headshot
Reply With Quote #5

Quote:
Originally Posted by Spirit_12 View Post
Try to set the damage value for "amount" in the event. Seems like that's where the other plugins are catching the value.

https://sm.alliedmods.net/new-api/events/Event/SetInt
Like this?
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
// #include <smlib>

public OnPluginStart()
{
    
HookEvent("infected_hurt"WitchHurt_EventEventHookMode_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)
    {
        
PrintToChatAll("Witch headshot registered");
        
//set damage amount to
        // SDKHooks_TakeDamage(victimEntId, attacker, attacker, 300.0, DMG_BULLET, -1, NULL_VECTOR, NULL_VECTOR);
        // Entity_Hurt(victimEntId, 300, attacker);
        
SetEventInt(event"amount"300);
    }
}

stock bool:IsWitch(iEntity)
{
    if(
iEntity && IsValidEntity(iEntity) && IsValidEdict(iEntity))
    {
        
decl String:strClassName[64];
        
GetEdictClassname(iEntitystrClassNamesizeof(strClassName));
        return 
StrEqual(strClassName"witch");
    }
    return 
false;

It doesn't seems to be working, even though headshot still registers.

Last edited by alcybery; 06-19-2018 at 17:28.
alcybery is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 06-19-2018 , 18:20   Re: [L4D2] Witch headshot
Reply With Quote #6

Quote:
Originally Posted by alcybery View Post
Like this?
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
// #include <smlib>

public OnPluginStart()
{
    
HookEvent("infected_hurt"WitchHurt_EventEventHookMode_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)
    {
        
PrintToChatAll("Witch headshot registered");
        
//set damage amount to
        // SDKHooks_TakeDamage(victimEntId, attacker, attacker, 300.0, DMG_BULLET, -1, NULL_VECTOR, NULL_VECTOR);
        // Entity_Hurt(victimEntId, 300, attacker);
        
SetEventInt(event"amount"300);
    }
}

stock bool:IsWitch(iEntity)
{
    if(
iEntity && IsValidEntity(iEntity) && IsValidEdict(iEntity))
    {
        
decl String:strClassName[64];
        
GetEdictClassname(iEntitystrClassNamesizeof(strClassName));
        return 
StrEqual(strClassName"witch");
    }
    return 
false;

It doesn't seems to be working, even though headshot still registers.
Dont you need to FireEvent to SetEventInt?
midnight9 is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 06-20-2018 , 05:15   Re: [L4D2] Witch headshot
Reply With Quote #7

Just change EventHookMode_Pre to EventHookMode_Post or use SDKHooks_TakeDamageAlive

About your last question fire event is creating an event, SetEventInt can either set the int of a new event ( what you think can be done ) or edit the int of an existing event ( what he wants you to do, also you're inside an event's callback after all... )
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334

Last edited by eyal282; 06-20-2018 at 05:16.
eyal282 is offline
alcybery
Member
Join Date: Apr 2016
Old 06-20-2018 , 17:25   Re: [L4D2] Witch headshot
Reply With Quote #8

Can someone help me with that code? I tried FireEvent, but still no luck.
alcybery is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 06-21-2018 , 06:41   Re: [L4D2] Witch headshot
Reply With Quote #9

Quote:
Originally Posted by alcybery View Post
Can someone help me with that code? I tried FireEvent, but still no luck.
FireEvent will destroy the entirety of your purpose, FireEvent is when you CREATE AN EVENT, NOT USE AN EXISTING EVENT. And I just realized the issue you got. You are dealing two different damages. The headshot damage and the 300.0 so your plugin won't combine them.

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_TakeDamageAlive, 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; 
}









Tell me if it works.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
alcybery
Member
Join Date: Apr 2016
Old 06-21-2018 , 09:23   Re: [L4D2] Witch headshot
Reply With Quote #10

Quote:
Originally Posted by eyal282 View Post
FireEvent will destroy the entirety of your purpose, FireEvent is when you CREATE AN EVENT, NOT USE AN EXISTING EVENT. And I just realized the issue you got. You are dealing two different damages. The headshot damage and the 300.0 so your plugin won't combine them.

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_TakeDamageAlive, 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; 
}









Tell me if it works.
I get error "undefined symbol "SDKHook_TakeDamageAlive" on compilation.
alcybery 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 07:58.


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