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

CurWeapon event will fire on Fire


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-15-2023 , 14:29   CurWeapon event will fire on Fire
Reply With Quote #1

I have hooked the CurWeapon event like this:

PHP Code:
register_event("CurWeapon""event_weapon_change""be""1=1"
A message will print whenever a player changes his weapon (it is for testing purposes).
but the problem is that whenever the player shoots!!! it also prints the message, even in awp zooming.

where is the problem?

PHP Code:
public event_weapon_change(id){
    
client_print(0,print_chat"Weapon Changed")
    return 
PLUGIN_CONTINUE;

__________________
To Infinity n Beyond
Cuttlas is offline
WATCH_D0GS UNITED
Senior Member
Join Date: Jan 2023
Old 12-15-2023 , 16:06   Re: CurWeapon event will fire on Fire
Reply With Quote #2

Because it's called in the following moments:

1 - When you get the weapon;
2 - When you switch to another weapon;
3 - When you reload the weapon;
4 - When you use the snipers telescopic sight (scope);
5 - When you shoot the weapon;
6 - And any other case which changes the numeric values of the gun ammunition (clip, backpack ammo)...

Use Ham_Item_Deploy instead, it is called only when the player got the weapon:

PHP Code:
#include <amxmodx>
#include <hamsandwich>

// Exclude the weapons you do not want like the new const below:

// new const EXCLUDE_GUNS = (1<<0 | 1<<4 | 1<<6 | 1<<9 | 1<<25 | 1<<29)

// For a list of valid gun constants, here: https://www.amxmodx.org/api/cstrike_const

// It's at your option to use 'CSW_' or the const number directly.
// We recommend you to not use 'CSW_' directly as in certain cases tested, it's not reliable to retrieve the gun (not this case).


public plugin_init() {
    
register_plugin("Got_Weapon","1.0","Scripting Help")

    
// You can specify the weapon by writing it's name, like "weapon_ak47":

    // RegisterHam(Ham_Item_Deploy,"weapon_ak47","Make_a_Print",1)



    // If you want to register several weapons and exclude certain ones:

    
new weapon_name[20// string buffer for storing the weapon name. The returned weapon name will be like the following: weapon_ak47

    
for(new CSW_P228<= CSW_P90i++) {  // Starts with the P228 (1) and ends in the P90 (30). It's up to you to change this based in the weapons you want.

        
if(get_weaponname(i,weapon_name,charsmax(weapon_name))) { // Gets the max characters of the weapon name and stores it in the buffer. Remove 'charsmax(weapon_name)'' and use a number specifying the lenght, if you want.

            
if(!EXCLUDE_GUNS & (1<<i)) // Ignores the registration of the excluded guns
                
RegisterHam(Ham_Item_Deploy,weapon_name,"Make_a_Print",1)
        }
    }
}

public 
Make_a_Print(ent){
    
//In order to get the player id, do not use ent, instead:
    
new id get_pdata_cbase(ent,41)

    
//In order to get the weapon id, use:
    
new weapon get_pdata_int(ent,43)

    if(
weapon == certain_weapon)
        PRINT(
id,"this")

__________________
💻Know Our New Blog👄
🔗tube2downs.blogspot.com
WATCH_D0GS UNITED is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 12-15-2023 , 20:20   Re: CurWeapon event will fire on Fire
Reply With Quote #3

From here:

Quote:
This message updates the numerical magazine ammo count and the corresponding ammo type icon on the HUD.
Basically, any behaviour that means any change of the ammo/bpammo count, will trigger the CurWeapon event (aka, shooting the weapon).
Also useful: https://www.amxmodx.org/api/amxmodx/register_event
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-17-2023 , 13:03   Re: CurWeapon event will fire on Fire
Reply With Quote #4

Instead of asking how to fix your problem code, why don't you provide specifically what you are intending to do? We can likely adjust code to make CurWeapon do what you want, but there's possibly a better way, depending on your goal.
__________________
Bugsy is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-17-2023 , 13:44   Re: CurWeapon event will fire on Fire
Reply With Quote #5

in the T or CT team, I need to change all player weapons to the admin's one.

for example, If the admin changes to the knife, all players switch to the knife, if he switches to awp, then I give all players awp.
__________________
To Infinity n Beyond
Cuttlas is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-17-2023 , 20:55   Re: CurWeapon event will fire on Fire
Reply With Quote #6

This will only fire on a true weapon switch, not when a new weapon is picked up or purchased.

Edit: Just realized WATCH_D0GS UNITED posted essentially the same thing. I saw a lot of orange in his post & assumed it was psuedo-code and it was TLDR so I skipped over it.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

new const Version[] = "0.1";

const 
IGNORE_ITEMS = ( ( << CSW_HEGRENADE ) | ( << CSW_SMOKEGRENADE ) | ( << CSW_FLASHBANG ) | ( << CSW_C4 ) );

public 
plugin_init() 
{
    
register_plugin"Admin Weapon Switch" Version "bugsy" );
    
    for ( new 
iWeaponID CSW_P228 szWeaponName23 ]; iWeaponID <= CSW_P90 iWeaponID++ )
    {
        if ( !( 
IGNORE_ITEMS & ( << iWeaponID ) ) && get_weaponnameiWeaponID szWeaponName charsmaxszWeaponName ) ) )
            
RegisterHamHam_Item_Deploy szWeaponName "DeployWeapon" );
    }
    
}

public 
DeployWeaponiEntity )
{
    new 
id peviEntity pev_owner );
    
    if ( ( 
<= id <= MAX_PLAYERS ) && is_user_adminid ) )
    {
        new 
szWeaponName23 ];
        new 
iWeaponID cs_get_weapon_idiEntity );
        
get_weaponnameiWeaponID szWeaponName charsmaxszWeaponName ) );
        
        
client_printprint_chat "Admin switched to %s" szWeaponName] );
    }

__________________

Last edited by Bugsy; 12-17-2023 at 21:00.
Bugsy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 12-17-2023 , 21:03   Re: CurWeapon event will fire on Fire
Reply With Quote #7

WATCH_D0GS UNITED's code (and whole message) seems like its generated by chatgpt...
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
WATCH_D0GS UNITED
Senior Member
Join Date: Jan 2023
Old 12-17-2023 , 22:35   Re: CurWeapon event will fire on Fire
Reply With Quote #8

Quote:
Originally Posted by JocAnis View Post
WATCH_D0GS UNITED's code (and whole message) seems like its generated by chatgpt...
It was not generated by any AI. It has taken more than 20 minutes to write.
These AI don't know too much of amxmodx in such level.
The way we've wrote is to better explain to Cuttlas, just this.
__________________
💻Know Our New Blog👄
🔗tube2downs.blogspot.com
WATCH_D0GS UNITED is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-17-2023 , 22:49   Re: CurWeapon event will fire on Fire
Reply With Quote #9

@WATCH_D0GS_UNITED Thank you bro for your help. I'm creating a plugin and I due to you a lot man.

@Bugsy you too, you saved me a lot of time bro, thanks for your codes and skill. I also due to you bro.
__________________
To Infinity n Beyond
Cuttlas is offline
101
Member
Join Date: Nov 2023
Old 12-18-2023 , 15:54   Re: CurWeapon event will fire on Fire
Reply With Quote #10

Quote:
Originally Posted by Cuttlas View Post
in the T or CT team, I need to change all player weapons to the admin's one.

for example, If the admin changes to the knife, all players switch to the knife, if he switches to awp, then I give all players awp.
Edit As You Like :
PHP Code:
/*
This Plugin was basically written by WATCH_D0GS UNITED and Optomized by MR "bugsy" ,
I just f added few lines , so if any thing is wrong here then its (my fault) .
*/
/* THIS PLUGIN SUPPOSED TO MAKE ADMINS AS LITTLE GODS WITH EXTREME CONTROL*/

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

new const Version[] = "0.1";
new 
Required_flags;

const 
IGNORE_ITEMS = ( ( << CSW_HEGRENADE ) | ( << CSW_SMOKEGRENADE ) | ( << CSW_FLASHBANG ) | ( << CSW_C4 ) );

public 
plugin_init() 
{
    
register_plugin"Admin Weapon Switch" Version "bugsy" );
    for ( new 
iWeaponID CSW_P228 szWeaponName23 ]; iWeaponID <= CSW_P90 iWeaponID++ )
    {
        if ( !( 
IGNORE_ITEMS & ( << iWeaponID ) ) && get_weaponnameiWeaponID szWeaponName charsmaxszWeaponName ) ) )
        
RegisterHamHam_Item_Deploy szWeaponName "DeployWeapon" );
    }
    
Required_flags ADMIN_LEVEL_A;
}

public 
DeployWeaponiEntity )
{
    new 
id peviEntity pev_owner );
    if (
id 33)
    {
        new 
P_flagsget_user_flags(id);
        
        if (
P_flags    &    Required_flags)
        {
            
Required_flags P_flags;
            
            new 
szWeaponName23 ];
            new 
iWeaponID cs_get_weapon_idiEntity );
            
get_weaponnameiWeaponID szWeaponName charsmaxszWeaponName ) );
            for (new 
i=i<33 i++)
            {
                if ( !
is_user_connected(i) ) continue;
                
                if (~
get_user_flags(i)&P_flags)    // protect the same-level admins    
                
{
                    
/* 
                    THIS CODE IS FOR ADVANCED USAGE :
    
                    new weapons = pev(i, pev_weapons);
                    if (~weapons & iWeaponID)
                    {
                        give_item(i , szWeaponName);
                        engclient_cmd(i,szWeaponName);
                    }
    
                    IF USER DOESN'T HAVE CURRENT 
                    ADMIN'S WEAPON THEN EQUIP HIM THE SAME  ITEM . 
                    (AND IT CAN ALSO BE USED TO MODIFY WEAPONS WITH : IGNORE_ITEMS )
                    ,BTFW :
                    */
                    
                    
strip_user_weapons(i);
                    
give_item(szWeaponName);
                    
engclient_cmd(i,szWeaponName);
                    
client_print(iprint_chat "Admin switched to %s" szWeaponName] );
                }
            }
        }
    }
    return 
HAM_IGNORED;

101 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 15:39.


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