AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   [L4D2] Detect if special infected die by headshot (https://forums.alliedmods.net/showthread.php?t=336079)

raizo11 01-26-2022 10:18

[L4D2] Detect if special infected die by headshot
 
I want to detect if special infected die by headshot..How can do that?

xerox8521 01-26-2022 10:37

Re: [L4D2] Detect if infected die by headshot
 
check the bool "headshot" from the player death event for common infected and witch try infected_death

raizo11 01-26-2022 14:08

Re: [L4D2] Detect if infected die by headshot
 
If i use infected_death nothing change...I searched forum but I didn't find any solution

Code:

public OnPluginStart()
{
    HookEvent("player_death",Event_PlayerDeath,EventHookMode_Pre);
}

public Action: Event_PlayerDeath( Handle:hEvent, const String:name[], bool:dontBroadcast )
{
    new victim = GetClientOfUserId( GetEventInt(hEvent, "userid") );
    new attacker = GetClientOfUserId( GetEventInt(hEvent, "attacker") );

    bool headshot = GetEventBool(hEvent, "headshot");

    if ( IS_VALID_INFECTED(victim) )
    {
        new zClass = GetEntProp(victim, Prop_Send, "m_zombieClass");

        switch ( zClass )
        {
            case ZC_SMOKER:
            {
                if(headshot)
                {
                    //g_Headshots[attacker]++;
                    PrintToChatAll("\x03[HEADSHOOT SMOKER]\x01 %N!",attacker);
                }
            }
            case ZC_BOOMER:
            {
                if(headshot)
                {
                    //g_Headshots[attacker]++;
                    PrintToChatAll("\x03[HEADSHOOT BOOMER]\x01 %N!",attacker);
                }
            }
    }
}


Bacardi 01-26-2022 14:18

Re: [L4D2] Detect if infected die by headshot
 
sm_cvar net_showevents 2 output:
Code:

Server event "weapon_fire", Tick 1826:
- "userid" = "2"
- "weapon" = "pistol"
- "weaponid" = "1"
- "count" = "1"
Server event "infected_hurt", Tick 1826:
- "attacker" = "2"
- "entityid" = "426"
- "hitgroup" = "1"
- "amount" = "28"
- "type" = "1073741826"
Server event "player_death", Tick 1826:
- "userid" = "0"
- "entityid" = "426"
- "attacker" = "2"
- "attackername" = ""
- "attackerentid" = "0"
- "weapon" = "dual_pistols"
- "headshot" = "1"
- "attackerisbot" = "0"
- "victimname" = "Infected"
- "victimisbot" = "1"
- "abort" = "0"
- "type" = "1073741826"
- "victim_x" = "772.49"
- "victim_y" = "5566.61"
- "victim_z" = "2690.03"
Server event "infected_death", Tick 1826:
- "attacker" = "2"
- "infected_id" = "0"
- "gender" = "1"
- "weapon_id" = "1"
- "headshot" = "1"
- "minigun" = "0"
- "blast" = "0"
- "submerged" = "0"

spitter
Code:

Server event "player_death", Tick 3935:
- "userid" = "6"
- "entityid" = "0"
- "attacker" = "2"
- "attackername" = ""
- "attackerentid" = "0"
- "weapon" = "dual_pistols"
- "headshot" = "1"
- "attackerisbot" = "0"
- "victimname" = "Spitter"
- "victimisbot" = "1"
- "abort" = "0"
- "type" = "1073741826"
- "victim_x" = "1530.55"
- "victim_y" = "6111.80"
- "victim_z" = "2691.53"

*edit
plugin example
PHP Code:

enum {
    
Infected 0,
    
Smoker,
    
Boomer,
    
Hunter,
    
Spitter,
    
Jockey,
    
Charger,
    
unknown,
    
Tank,
    
Survivor,
    
Witch
};

char infected[][] = {
    
"Infected",
    
"Smoker",
    
"Boomer",
    
"Hunter",
    
"Spitter",
    
"Jockey",
    
"Charger",
    
"unknown",
    
"Tank",
    
"Survivor",
    
"Witch"
}

public 
void OnPluginStart()
{
    
HookEvent("player_death"player_death);
}


public 
void player_death(Event event, const char[] namebool dontBroadcast)
{
    
// no headshot
    
if(!event.GetBool("headshot"))
        return;

    
//if(event.GetBool("attackerisbot"))
    //    return;


    
int attacker GetClientOfUserId(event.GetInt("attacker"));

    
// attacker not found by userid
    
if(!attacker)
        return;

    
int victim event.GetInt("entityid");

    if(!
victim)
    {
        
victim GetClientOfUserId(event.GetInt("userid"));
        
        if(!
victim)
            return;
    }


    
char buffer[15];
    
int m_zombieClass 0;

    if(
HasEntProp(victimProp_Send"m_zombieClass"))
    {
        
m_zombieClass GetEntProp(victimProp_Send"m_zombieClass");
    }
    else
    {
        
event.GetString("victimname"buffersizeof(buffer));

        if(
StrEqual(bufferinfected[Witch], false))
            
m_zombieClass Witch// this class is now customized manually...
    
}

    switch(
m_zombieClass)
    {
        case 
Infected:
        {
        }
    
        default:
        {
            
PrintToChatAll("\x03[HEADSHOT %s]\x01 %N"infected[m_zombieClass], attacker);
        }
    }



raizo11 01-27-2022 14:02

Re: [L4D2] Detect if special infected die by headshot
 
Code:

    switch(m_zombieClass)
    {
        case Infected:
        {
            PrintToChatAll("\x03[INFECTED HS]");  /// This works for all players
        }
        case Smoker:
        {
            PrintToChatAll("\x03[HEADSHOT SMOKER]"); // this only for bots
        }
        case Boomer:
        {
            PrintToChatAll("\x03[HEADSHOT BOOMER]");
        }
        case Hunter:
        {
            PrintToChatAll("\x03[HEADSHOT HUNTER]");
        }
        case Spitter:
        {
            PrintToChatAll("\x03[HEADSHOT SPITTER]");
        }
        case Jockey:
        {
            PrintToChatAll("\x03[HEADSHOT JOCKEY]");
        }
        case Charger:
        {
            PrintToChatAll("\x03[HEADSHOT CHARGER]");
        }
   
        default:
        {
            PrintToChatAll("\x03[HEADSHOT %s]\x01 %N", infected[m_zombieClass], attacker);
        }


Bacardi 01-27-2022 18:50

Re: [L4D2] Detect if special infected die by headshot
 
...show your whole plugin.

raizo11 01-28-2022 00:56

Re: [L4D2] Detect if special infected die by headshot
 
Is your plugin example.. only I added case smoker case hunter ....

Bacardi 01-28-2022 03:27

Re: [L4D2] Detect if special infected die by headshot
 
Please?

raizo11 01-28-2022 04:10

Re: [L4D2] Detect if special infected die by headshot
 
Code:

#include sourcemod

enum {
    Infected = 0,
    Smoker,
    Boomer,
    Hunter,
    Spitter,
    Jockey,
    Charger,
    unknown,
    Tank,
    Survivor,
    Witch
};
char infected[][] = {
    "Infected",
    "Smoker",
    "Boomer",
    "Hunter",
    "Spitter",
    "Jockey",
    "Charger",
    "unknown",
    "Tank",
    "Survivor",
    "Witch"
}
public void OnPluginStart()
{
    HookEvent("player_death", player_death);
}
public void player_death(Event event, const char[] name, bool dontBroadcast)
{
    // no headshot
    if(!event.GetBool("headshot"))
        return;

    //if(event.GetBool("attackerisbot"))
    //    return;


    int attacker = GetClientOfUserId(event.GetInt("attacker"));

    // attacker not found by userid
    if(!attacker)
        return;

    int victim = event.GetInt("entityid");

    if(!victim)
    {
        victim = GetClientOfUserId(event.GetInt("userid"));
       
        if(!victim)
            return;
    }


    char buffer[15];
    int m_zombieClass = 0;

    if(HasEntProp(victim, Prop_Send, "m_zombieClass"))
    {
        m_zombieClass = GetEntProp(victim, Prop_Send, "m_zombieClass");
    }
    else
    {
        event.GetString("victimname", buffer, sizeof(buffer));

        if(StrEqual(buffer, infected[Witch], false))
            m_zombieClass = Witch; // this class is now customized manually...
    }

    switch(m_zombieClass)
    {
        case Infected:
        {
 This for all
        }
      case Smoker:
      {
          This works only for bots
      }
        default:
        {
            PrintToChatAll("\x03[HEADSHOT %s]\x01 %N", infected[m_zombieClass], attacker);
        }
    }
{
}


Bacardi 01-28-2022 10:53

Re: [L4D2] Detect if special infected die by headshot
 
I can't find problem and can't produce that problem.
I can test with bots only and work fine, even L4D2 head shots are inaccurate mostly (client see head exploding -> server not always register that as head shot).

You could try remove entity prop "m_zombieClass" part out from code,
replace it with string check.
Compare event strings "victimname" with infected name.
But I doubt it make any differences.


All times are GMT -4. The time now is 04:53.

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