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

Solved [TF2] projectile_direct_hit event issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 11-07-2020 , 03:53   [TF2] projectile_direct_hit event issue
Reply With Quote #1

I'm trying to create a script which increases the Airstrike's clip when a player scores a direct hit with it. However, I'm running into an issue where the "attacker" client index always returns 0. The "victim" client index returns the correct value. I'm guessing perhaps the event is reporting the rocket and/or the world as the attacker instead of the player? If anyone knows if this is fixable or maybe a workaround I would be very appreciative.

PHP Code:
public void OnPluginStart()
{
    
HookEvent("projectile_direct_hit"Direct_Hit);
}

public 
Action Direct_Hit(Event event, const char[] namebool dontBroadcast)
{
    
int attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
int victim GetClientOfUserId(GetEventInt(event"victim"));
    
int iWeapon GetEventInt(event"weapon_def_index");
    
    if (
attacker <= || attacker MaxClients || !IsValidEntity(iWeapon))
    { 
        
PrintToChatAll("Something done fucked up you aint valid son, heres yo client index dawg %i"attacker);
        return 
Plugin_Continue;
    }
    
PrintToChatAll("We made it past the validity check so what now son?");
    if (
TF2_GetPlayerClass(attacker) == TFClass_Soldier && iWeapon == 1104 && attacker != victim)
    {
        
SetEntProp(attackerProp_Send"m_iDecapitations"GetEntProp(attackerProp_Send"m_iDecapitations") + 1);
        
TF2_AddCondition(attackerTFCond_SpeedBuffAlly0.01);
        
PrintToChatAll("You did it right congrats son");
    }
    return 
Plugin_Continue;


Last edited by Ravrob; 11-07-2020 at 07:17.
Ravrob is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-07-2020 , 05:58   Re: [TF2] projectile_direct_hit event issue
Reply With Quote #2

The output of the projectile_direct_hit event provides a byte for the attacker and victim. Try changing your code to view the byte value as an integer.

PHP Code:
#include <TF2_stocks> 

public void OnPluginStart()
{
    
HookEvent("projectile_direct_hit"Direct_Hit);
}

public 
Action Direct_Hit(Event event, const char[] namebool dontBroadcast)
{
    
int attacker view_as<int>(GetEventInt(event"attacker"));
    
int victim view_as<int>(GetEventInt(event"victim"));    
    
int iWeapon GetEventInt(event"weapon_def_index");
    
    if (
attacker <= || attacker MaxClients || !IsValidEntity(iWeapon))
    { 
        
PrintToChatAll("Attacker Name: %N, Index: %i"attackerattacker);
        
PrintToChatAll("Victim Name: %N, Index: %i"victimvictim);        
        return 
Plugin_Continue;
    }
    
PrintToChatAll("We made it past the validity check so what now son?");
    if (
TF2_GetPlayerClass(attacker) == TFClass_Soldier && iWeapon == 1104 && attacker != victim)
    {
        
SetEntProp(attackerProp_Send"m_iDecapitations"GetEntProp(attackerProp_Send"m_iDecapitations") + 1);
        
TF2_AddCondition(attackerTFCond_SpeedBuffAlly0.01);
        
PrintToChatAll("You did it right congrats son");
    }
    return 
Plugin_Continue;

PC Gamer is offline
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 11-07-2020 , 07:16   Re: [TF2] projectile_direct_hit event issue
Reply With Quote #3

Thanks! That fixed it. Didn't work at first and it was reporting the correct values, but I realized iWeapon isn't an entity so I removed that and the whole script worked with and without the valid client check this time.
Ravrob 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 16:44.


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