AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [L4D2] Setting Damage dealt to witch (https://forums.alliedmods.net/showthread.php?t=330256)

lightphoenix2 01-26-2021 11:48

[L4D2] Setting Damage dealt to witch
 
Hi, I'm wondering how do you set damage dealt to a witch
Code:

public void OnPluginStart()
{
        HookEvent("witch_spawn", eEvent);
}
public void eEvent (Event event, const char[] name, bool dontbroadcast)
{       
        int iWitch = GetEventInt(event, "witchid");
        SDKHook(iWitch, SDKHook_OnTakeDamagePost, OnTakeDamage);
}

I have tried hooking witch_spawn as well as SDKHook_OnTakeDamage before changing to SDKHook_OnTakeDamagePost.

Code:

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
        if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0)
        {
                if (GetClientTeam(victim) == 2)
                {
                        return Plugin_Continue;
                }
                damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
                if(damage > 1024.0)
                {
                        damage = 1023.0;
                }
                return Plugin_Changed;
        }
       
        return Plugin_Continue;
}

Any damage above 1024 seems to not be able to be detected by another plugin that detect damage done to special infected. It will display 0 instead. But it can still deal the damage.
Any Help would be appreciated!

Marttt 01-26-2021 13:20

Re: [L4D2] Setting Damage dealt to witch
 
The order of events are "random"

You can have a plugin messing with OnTakeDamage
But if the plugin that outputs fires first then it may ignore the damage changed.
The plugin that outputs to the chat should use OnTakeDamagePost.

Can you share the other plugin? (if public)

EDIT:

So after trying your code I see that you GetClientTeam(victim) == 2 on the witch
Victim is the witch
Witch is not a client. (So GetClientTeam fails)
Team 2 means survivor

Try testing with this:

PHP Code:

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

public void OnPluginStart()
{
    
HookEvent("witch_spawn"eEvent);
}
public 
void eEvent (Event event, const char[] namebool dontbroadcast)
{
    
int iWitch GetEventInt(event"witchid");
    
SDKHook(iWitchSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    
//if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0)
    
if (<= attacker <= MaxClients && GetClientTeam(attacker) == 2)
    {
        
// if (GetClientTeam(victim) == 2) // Witchs don't have team, also victim = witch and 2 means survivor
        // {
            // return Plugin_Continue;
        // }
        //damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
        
damage GetRandomFloat(512.01536.0);
        if(
damage 1024.0)
        {
            
PrintToChatAll(">>> GREATER >>> damage > 1024. damage %f"damage);
            
//damage = 1023.0;
        
}
        else
        {
            
PrintToChatAll("<<< LESSER <<< damage < 1024. damage %f"damage);
        }
        return 
Plugin_Changed;
    }

    return 
Plugin_Continue;



lightphoenix2 01-27-2021 08:29

Re: [L4D2] Setting Damage dealt to witch
 
2 Attachment(s)
Quote:

Originally Posted by Marttt (Post 2734367)
The order of events are "random"

You can have a plugin messing with OnTakeDamage
But if the plugin that outputs fires first then it may ignore the damage changed.
The plugin that outputs to the chat should use OnTakeDamagePost.

Can you share the other plugin? (if public)

EDIT:

So after trying your code I see that you GetClientTeam(victim) == 2 on the witch
Victim is the witch
Witch is not a client. (So GetClientTeam fails)
Team 2 means survivor

Try testing with this:

PHP Code:

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

public void OnPluginStart()
{
    
HookEvent("witch_spawn"eEvent);
}
public 
void eEvent (Event event, const char[] namebool dontbroadcast)
{
    
int iWitch GetEventInt(event"witchid");
    
SDKHook(iWitchSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    
//if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0)
    
if (<= attacker <= MaxClients && GetClientTeam(attacker) == 2)
    {
        
// if (GetClientTeam(victim) == 2) // Witchs don't have team, also victim = witch and 2 means survivor
        // {
            // return Plugin_Continue;
        // }
        //damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
        
damage GetRandomFloat(512.01536.0);
        if(
damage 1024.0)
        {
            
PrintToChatAll(">>> GREATER >>> damage > 1024. damage %f"damage);
            
//damage = 1023.0;
        
}
        else
        {
            
PrintToChatAll("<<< LESSER <<< damage < 1024. damage %f"damage);
        }
        return 
Plugin_Changed;
    }

    return 
Plugin_Continue;



The main one is over here that version uses hook event like player hurt to detect damage. I made a few changes to it since then and I included it in the attachment.

Code:

if (GetClientTeam(victim) == 2)
                {
                        return Plugin_Continue;
                }

The Code GetClientTeam(victim) == 2 is to detect for the survivor and it will return Plugin_Continue. And no changes will be made.

I'm working on the plugin l4d2_critical_shot_m.sp which will deal extra damage by changing the damage in OnTakeDamage. But it doesn't work for witch. This plugin requires the main l4d2_skills_core_V2.2.sp or the main one linked above. Once you buy the skill from the menu the player will be able to have a chance to deal extra damage. GetClientTeam(victim) == 2 is to prevent changing damage done to Survivor team.
The original plugin can be found here, I'm making a module for Skills that allow you to buy skills from a menu.

Marttt 01-27-2021 11:36

Re: [L4D2] Setting Damage dealt to witch
 
Well try to change OnTakeDamagePost to OnTakeDamage

The signature method is wrong (check here)

PHP Code:

// OnTakeDamage
function Action (int victimint &attackerint &inflictorfloat &damageint &damagetype); 

PHP Code:

// OnTakeDamagePost
function void (int victimint attackerint inflictorfloat damageint damagetype); 

If you wanna change the damage you have to use it on OnTakeDamage (return Plugin_Changed)
If you just wanna check the values check on OnTakeDamagePost (return)

Both plugins have too many dependencies (files and includes) so I can't properly test in my local server.

lightphoenix2 01-27-2021 12:42

Re: [L4D2] Setting Damage dealt to witch
 
Quote:

Originally Posted by Marttt (Post 2734508)
Well try to change OnTakeDamagePost to OnTakeDamage

The signature method is wrong (check here)

PHP Code:

// OnTakeDamage
function Action (int victimint &attackerint &inflictorfloat &damageint &damagetype); 

PHP Code:

// OnTakeDamagePost
function void (int victimint attackerint inflictorfloat damageint damagetype); 

If you wanna change the damage you have to use it on OnTakeDamage (return Plugin_Changed)
If you just wanna check the values check on OnTakeDamagePost (return)

Both plugins have too many dependencies (files and includes) so I can't properly test in my local server.

Initially, I use OnTakeDamage, but it doesn't even detect for witch. Do you know how to capture damage done to witch? I think witch is slightly different than special infected.

I will try to implement OnTakeDamagePost to detect the damage instead of OnTakeDamage. Thanks~!

Marttt 01-27-2021 13:49

Re: [L4D2] Setting Damage dealt to witch
 
My code snippet outputs damage to the witch

If it's not outputting maybe you have some plugin cancelling the damage triggering before.

Also witch is not considered as a SI (client), they are more similar to commons (infected) when we compare them as entities

cravenge 01-28-2021 03:56

Re: [L4D2] Setting Damage dealt to witch
 
PHP Code:

public void OnEntityCreated(int entity, const char[] classname)
{
    if (
entity || entity 2048)
    {
        return;
    }
    
    if (
strcmp(classname"witch") == 0)
    {
        
SDKHook(entitySDKHook_OnTakeDamageOnTakeDamage);
    }



lightphoenix2 01-28-2021 11:08

Re: [L4D2] Setting Damage dealt to witch
 
Quote:

Originally Posted by cravenge (Post 2734591)
PHP Code:

public void OnEntityCreated(int entity, const char[] classname)
{
    if (
entity || entity 2048)
    {
        return;
    }
    
    if (
strcmp(classname"witch") == 0)
    {
        
SDKHook(entitySDKHook_OnTakeDamageOnTakeDamage);
    }



Thanks this help to hook the witch, but it still cant be detected for god knows what so I made this:
Code:

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
        if(GetEntityClassname(victim, "witch", 10) && attacker > 0 && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0 && attacker <= MaxClients && victim > 12)
        {
                damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
                Knockback(attacker, victim, CritForce, 1.5, 2.0);
                if (CritPrint)
                {
                        PrintToChat(attacker, "\x01Critical!\x03 %.2f\x01 damage", damage);
                }
                return Plugin_Changed;
        }
        if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0)
        {
                if (GetClientTeam(victim) == 2)
                {
                        return Plugin_Continue;
                }
                damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
                if(damage > 1024.0)
                {
                        damage = 1023.0;
                }
                if (CritPrint)
                {
                        PrintToChat(attacker, "\x01Critical!\x03 %.2f\x01 damage", damage);
                }
               
                Knockback(attacker, victim, CritForce, 1.5, 2.0);
                return Plugin_Changed;
        }
        return Plugin_Continue;
}

GetEntityClassname(victim, "witch", 10) seems to work for all special infected so I limited them using victim > 12. Anyone got any better idea??

Marttt 01-28-2021 11:21

Re: [L4D2] Setting Damage dealt to witch
 
You should remove all your plugins and test this one as a single alone.

As I said if another plugin does "return Plugin_Stop;" on OnTakeDamage first.
It will not fire your PrintToChat

Witchs are not clients, so you can safely check victim > MaxClients
If you check the classname before then you don't even need the victim check.

The only thing I don't have is that g_iLevel var, maybe this is the problem.

As always, to debug your code, start doing simple checks then add more.
Maybe one of your checks is failing.

From your replies seem that you didn't test my snippet either from cravenge, both are working for us.

lightphoenix2 01-28-2021 13:05

Re: [L4D2] Setting Damage dealt to witch
 
2 Attachment(s)
Quote:

Originally Posted by Marttt (Post 2734645)
You should remove all your plugins and test this one as a single alone.

As I said if another plugin does "return Plugin_Stop;" on OnTakeDamage first.
It will not fire your PrintToChat

Witchs are not clients, so you can safely check victim > MaxClients
If you check the classname before then you don't even need the victim check.

The only thing I don't have is that g_iLevel var, maybe this is the problem.

As always, to debug your code, start doing simple checks then add more.
Maybe one of your checks is failing.

From your replies seem that you didn't test my snippet either from cravenge, both are working for us.

I used cravenge OnEntityCreated in l4d2_critical_shot_m.sp and your OnDamage for l4d2_skills_core_V2.2.sp. You can check it out in the attachment. It seems to work, just that I can't test if its other plugins that are causing the problem.
Also, I change the victim > 10 to victim > MaxClients after you mentioned it, which makes more sense.


All times are GMT -4. The time now is 06:57.

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