Raised This Month: $ Target: $400
 0% 

OnWeaponFire identifies specific weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MarceloLopes
New Member
Join Date: Nov 2023
Old 01-16-2024 , 06:06   OnWeaponFire identifies specific weapon
Reply With Quote #1

I need it to be identified if the weapon used was specifically from the entity I created "g_pyro_smg". I know that it is possible to identify the type of weapon, smg, shotgun etc, but what I need is to identify if it is "g_pyro_smg",
Any way to do this? apparently the event does not take any weapon information, such as entID or strings.

PHP Code:
#include <sourcemod>
#include <sdktools>


public void OnPluginStart()
{
    
HookEvent("weapon_fire"OnWeaponFire);

}

int g_pyro_smg = -1;

public 
void OnMapStart()
{
    
g_pyro_smg CreateEntityByName("weapon_smg");
    if (
g_pyro_smg)
    {
        
DispatchKeyValue(g_pyro_smg"targetname""pyro_smg1");
        
DispatchKeyValue(g_pyro_smg"origin""0 0 0");
        
DispatchKeyValue(g_pyro_smg"angles""0 0 0");
        
DispatchKeyValue(g_pyro_smg"OnUser1""FireParticle2,FireUser2,,0,-1");
        
DispatchKeyValue(g_pyro_smg"OnUser1""FireParticle1,FireUser2,,0,-1");
        
DispatchKeyValue(g_pyro_smg"OnUser1""pyro_smg1_Hurt,FireUser1,,0,-1");
        
DispatchSpawn(g_pyro_smg);
        
ActivateEntity(g_pyro_smg);
        
SetEntityRenderColor(g_pyro_smg25500255);
        
CreateTimer(3.0idg_pyro_smg);

        
    }
   
}
public 
Action id(Handle timer)
{
    
    
PrintToChatAll("ID g_pyro_smg: %d"g_pyro_smg);    
            
}
public 
void OnWeaponFire(Event event, const char[] namebool dontBroadcast)
{


    if 
// if is "g_pyro_smg"
    
{
        
        
PrintToChatAll("fired with the g_pyro_smg ");
 
    }

    


Last edited by MarceloLopes; 01-16-2024 at 08:49. Reason: [/php]
MarceloLopes is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-16-2024 , 10:42   Re: OnWeaponFire identifies specific weapon
Reply With Quote #3

https://forums.alliedmods.net/showth...ght=TARGETNAME
__________________
Do not Private Message @me
Bacardi is offline
MarceloLopes
New Member
Join Date: Nov 2023
Old 01-16-2024 , 13:09   Re: OnWeaponFire identifies specific weapon
Reply With Quote #4

Quote:
Originally Posted by Bacardi View Post
I know how to detect the targetname, the problem is that apparently it doesn't work because the event doesn't receive this information from the weapon, I'm trying to find out some way.
MarceloLopes is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-16-2024 , 15:31   Re: OnWeaponFire identifies specific weapon
Reply With Quote #5

I did not know that you know...

Try this. I made quick, have not tested.
PHP Code:



public void OnPluginStart()
{
    
HookEventEx("weapon_fire"weapon_fire);
}

public 
void weapon_fire(Event event, const char[] namebool dontBroadcast)
{

    
char weapon[65];
    
event.GetString("weapon"weaponsizeof(weapon));

    if(!
StrEqual(weapon"weapon_smg"false))
        return;

    
int client GetClientOfUserId(event.GetInt("userid"));

    if(
client == 0)
        return;

    
int entity GetEntPropEnt(clientProp_Send"m_hActiveWeapon");

    if(
entity == -|| !HasEntProp(entityProp_Data"m_iName"))
        return;

    
GetEntPropString(entityProp_Data"m_iName"weaponsizeof(weapon));

    if(!
StrEqual(weapon"pyro_smg1"false))
        return;

    
PrintToServer("Player %N shoot %s"weapon);

__________________
Do not Private Message @me

Last edited by Bacardi; 01-17-2024 at 03:50. Reason: line 12: missing "key"
Bacardi 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 04:04.


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