Raised This Month: $ Target: $400
 0% 

CurWeapon event will fire on Fire


Post New Thread Reply   
 
Thread Tools Display Modes
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-19-2023 , 15:01   Re: CurWeapon event will fire on Fire
Reply With Quote #11

it seems the codes provided by Bugsy and 101 have a bug with my goal.

whenever the admin drops a gun with G and picks up another one, the event won't call. so does it mean I should change weapons on a pick-up event? Or can I edit the current event?


and how to disable weapon changing for others? just admin can change his weapon, and others' weapons will be the same as the admin and they are not allowed to change or drop their weapons.
__________________
To Infinity n Beyond

Last edited by Cuttlas; 12-19-2023 at 15:14.
Cuttlas is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-19-2023 , 15:24   Re: CurWeapon event will fire on Fire
Reply With Quote #12

Another option is to use CurWeapon with logic to make it apply only when needed.
__________________
Bugsy is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-19-2023 , 15:30   Re: CurWeapon event will fire on Fire
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
Another option is to use CurWeapon with logic to make it apply only when needed.
could you please help me on that?
__________________
To Infinity n Beyond
Cuttlas is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-19-2023 , 15:57   Re: CurWeapon event will fire on Fire
Reply With Quote #14

Can you clarify requirements?

Should it only happen when a true weapon switch happens, and not upon weapon pickup?
Do all weapons apply, excluding nades and c4?
Which admins flags do you care about?
Should the player be given the weapon if he doesn’t have it?
Does it apply to only players on the same team as the admin?
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-19-2023 , 18:57   Re: CurWeapon event will fire on Fire
Reply With Quote #15

This should cover all. I left chat prints in there so you can see what's happening in real-time. I tested it with bots and I see the switch happening. Granted, the player can switch to something else after force-switching their weapon, did you want to block that?
PHP Code:

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

new const Version[] = "0.2";

const 
ADMIN_WEAPON_FLAGS ADMIN_BAN ADMIN_KICK;
const 
IGNORE_ITEMS = ( ( << CSW_HEGRENADE ) | ( << CSW_SMOKEGRENADE ) | ( << CSW_FLASHBANG ) | ( << CSW_C4 ) );
new const 
TeamNamesCsTeams ][] = { "" "TERRORIST" "CT" "" };

enum WeaponInfo
{
    
CurrentWeapon,
    
AllWeaponsBits
}
new 
g_wiDataMAX_PLAYERS ][ WeaponInfo ];


public 
plugin_init() 
{
    
register_plugin"Admin Weapon Switch" Version "bugsy" );
    
    
register_event("CurWeapon" "WeaponChange" "be" "1=1" );
}

public 
WeaponChangeid )
{
    if ( ( 
get_user_flagsid ) & ADMIN_WEAPON_FLAGS ) == ADMIN_WEAPON_FLAGS )
    {
        new 
iWeaponID read_data);
    
        if ( 
g_wiDataid ][ AllWeaponsBits ] & ( << iWeaponID ) )
        {
            if ( ( 
iWeaponID != g_wiDataid ][ CurrentWeapon ] ) && !( IGNORE_ITEMS & ( << iWeaponID ) ) )
            {
                
client_printid print_chat "Changed to weapon id %d" iWeaponID );
                
SetPlayerWeaponsid iWeaponID true );
            }
        }
        else
        {
            
client_printid print_chat "Picked up weapon id %d" iWeaponID );
        }
            
        
g_wiDataid ][ CurrentWeapon ] = iWeaponID;
        
g_wiDataid ][ AllWeaponsBits ] = pevid pev_weapons );
    }


SetPlayerWeaponsid iWeaponID bool:bSameTeamOnly=true )
{
    new 
iPlayersMAX_PLAYERS ] , iNum iPlayer szWeaponName20 ] , CsTeams:csCurTeam cs_get_user_teamid );
    
    
get_playersiPlayers iNum bSameTeamOnly "ae" "a" bSameTeamOnly TeamNamescsCurTeam ] : "" );
    
get_weaponnameiWeaponID szWeaponName charsmaxszWeaponName ) );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        if ( 
iPlayer != id )
        {
            if ( !
user_has_weaponiPlayer iWeaponID ) )
            {
                
client_printid print_chat "Giving id %d weapon %s" iPlayer szWeaponName );
                
give_itemiPlayer szWeaponName );
                
engclient_cmdiPlayer szWeaponName );
            }
            else
            {
                
client_printid print_chat "Setting id %d weapon to %s" iPlayer szWeaponName );
                
engclient_cmdiPlayer szWeaponName );
            }
        }
    }

__________________

Last edited by Bugsy; 12-19-2023 at 19:13.
Bugsy is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 03-30-2024 , 14:40   Re: CurWeapon event will fire on Fire
Reply With Quote #16

I'm trying to do it on weapon pick up, but no success:

PHP Code:
public weapon_pickupiEntity )
{
        new 
wid read_data(2)
          new 
id pevwid pev_owner );
    
        if ( 
iEntity == admin)
        {
            
client_printprint_chat "Admin picked up a weapon");
            new 
szWeaponName23 ];
            new 
iWeaponID cs_get_weapon_idwid );
            
get_weaponnameiWeaponID szWeaponName charsmaxszWeaponName ) );
            
            
client_printprint_chat "Admin picked up %s weapon" szWeaponName);
        }

it will print ""Admin picked up a weapon""

but it can not print the weapon name. how to fix it?
__________________
To Infinity n Beyond
Cuttlas is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-30-2024 , 15:11   Re: CurWeapon event will fire on Fire
Reply With Quote #17

What event is triggering weapon_pickup?
Why are you checking if the weapon entity (iEntity) is equal to admin? This may just be bad variable naming.
What does admin hold?

If you are using CurWeapon to trigger weapon_pickup, this does not give you the entity ID, only the CSW_ weapon id. You cannot use pev_owner to get the owner of this. The owner is passed directly into the CurWeapon event.

This may be what you are trying to do:
PHP Code:
public weapon_pickupiPlayer )
{
    if ( 
iPlayer == admin )
    {
        
//client_print( 0 , print_chat , "Admin picked up a weapon");
        
new szWeaponName23 ];
        
get_weaponnameread_data), szWeaponName charsmaxszWeaponName ) );
        
        
client_printprint_chat "Admin picked up %s weapon" szWeaponName] );
    }

__________________
Bugsy is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 03-30-2024 , 15:48   Re: CurWeapon event will fire on Fire
Reply With Quote #18

I have used this:

register_event("WeapPickup", "weapon_pickup", "b");

with yours and the WeapPickup, again it can not find the weapon name!

the admin is just an example, it will store the admin id in terror Team for example.

also beside the weapon name, I need the weapon id.
__________________
To Infinity n Beyond
Cuttlas is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-30-2024 , 15:51   Re: CurWeapon event will fire on Fire
Reply With Quote #19

Change read_data( 2 ) to read_data( 1 ). What do you need the entity ID for?

Code:
Name:	WeapPickup
Structure:	
byte	WeaponID
__________________

Last edited by Bugsy; 03-30-2024 at 15:53.
Bugsy is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 03-30-2024 , 16:48   Re: CurWeapon event will fire on Fire
Reply With Quote #20

worked well Bugsy.

I'm trying to give the admin's weapon to other players on a team. so the Entity ID (which here is the player id who picks up the weapon) can help me to decide whether the player is admin or not.
__________________
To Infinity n Beyond
Cuttlas 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 21:23.


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