AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CurWeapon event will fire on Fire (https://forums.alliedmods.net/showthread.php?t=344874)

Cuttlas 12-15-2023 14:29

CurWeapon event will fire on Fire
 
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;



WATCH_D0GS UNITED 12-15-2023 16:06

Re: CurWeapon event will fire on Fire
 
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")



EFFx 12-15-2023 20:20

Re: CurWeapon event will fire on Fire
 
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

Bugsy 12-17-2023 13:03

Re: CurWeapon event will fire on Fire
 
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.

Cuttlas 12-17-2023 13:44

Re: CurWeapon event will fire on Fire
 
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.

Bugsy 12-17-2023 20:55

Re: CurWeapon event will fire on Fire
 
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] );
    }



JocAnis 12-17-2023 21:03

Re: CurWeapon event will fire on Fire
 
WATCH_D0GS UNITED's code (and whole message) seems like its generated by chatgpt...

WATCH_D0GS UNITED 12-17-2023 22:35

Re: CurWeapon event will fire on Fire
 
Quote:

Originally Posted by JocAnis (Post 2814596)
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.

Cuttlas 12-17-2023 22:49

Re: CurWeapon event will fire on Fire
 
@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.

101 12-18-2023 15:54

Re: CurWeapon event will fire on Fire
 
Quote:

Originally Posted by Cuttlas (Post 2814583)
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;




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

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