AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CurWeapon Event (https://forums.alliedmods.net/showthread.php?t=347145)

LeOp4rD 04-05-2024 21:30

CurWeapon Event
 
Hello, I'm trying to make some actions when a client changes his weapon, but nothing seems to work here :

#include <amxmodx>

public plugin_init(){
register_plugin("knife Buffs" , AMXX_VERSION_STR , "LeOpArD")
register_event("CurWeapon" , "knifeBuff", "a")
}

public knifeBuff(id) {
client_print(0, print_chat, "CurWeapon event triggered for client %d!", id);

return PLUGIN_HANDLED;
}

Bugsy 04-06-2024 00:34

Re: CurWeapon Event
 
Try

register_event("CurWeapon" , "knifeBuff" , "be" , "1=1" );

LeOp4rD 04-06-2024 02:28

Re: CurWeapon Event
 
Quote:

Originally Posted by Bugsy (Post 2820613)
Try

register_event("CurWeapon" , "knifeBuff" , "be" , "1=1" );

THANK YOU SO MUCH !
so 'b' means it will be sent to a single client, and 'e' if hes alive !
IT worked perfectly, but i couldn't understand the condition part

abdelwahab 04-06-2024 19:56

Re: CurWeapon Event
 
Quote:

Originally Posted by LeOp4rD (Post 2820618)
i couldn't understand the condition part


https://www.amxmodx.org/api/amxmodx/register_event

Bugsy 04-07-2024 10:13

Re: CurWeapon Event
 
These are what you have to work with from a conditions perspective in the CurWeapon event.

https://wiki.alliedmods.net/Half-life_1_game_events
Code:

Name: CurWeapon
byte        IsActive
byte        WeaponID
byte        ClipAmmo

You must reference them in the order as listed.
1=IsActive
2=WeaponID
3=ClipAmmo

So the "1=1" you see above means IsActive must be 1 for the event to trigger in your plugin.

Another example using the 2nd argument of WeaponID. With CSW_AK47=28, you could add a condition to make it only fire on the AK47 by adding:
"2=28"

register_event("CurWeapon" , "AK47Only" , "be" , "1=1" , "2=28" );

Or everything except AK47
register_event("CurWeapon" , "AK47Only" , "be" , "1=1" , "2!28" );

mlibre 04-07-2024 16:55

Re: CurWeapon Event
 
sorry to interrupt, I leave this method and withdraw slowly...

PHP Code:

#include <amxmodx>
#include <hamsandwich>

public plugin_precache() 
{
    for(new 
CSW_P228weapon_name[20]; <= CSW_P90i++)
    {
        if(
get_weaponname(iweapon_namecharsmax(weapon_name)))
        {
            
RegisterHam(Ham_Item_Deployweapon_name"Ham_Item_Deploy_Post"true)
        }
    }
}

public 
Ham_Item_Deploy_Post(iWeapon)
{
    const 
OFFSET_WEAPONOWNER 41
    
const OFFSET_LINUX_WEAPONS 4
        
    
new iPlayer get_pdata_cbase(iWeaponOFFSET_WEAPONOWNEROFFSET_LINUX_WEAPONS)
    
    if( !
is_user_connected(iPlayer) )
        return 
HAM_IGNORED

    client_print
(0print_chat"Ham_Item_Deploy event triggered for client %d!"iPlayer);

    return 
HAM_IGNORED



Bugsy 04-08-2024 08:41

Re: CurWeapon Event
 
“and withdraw slowly”? What does that mean?

mlibre 04-08-2024 09:08

Re: CurWeapon Event
 
it's a...

meme

DJEarthQuake 04-08-2024 18:24

Re: CurWeapon Event
 
@LeOp4rD, register_event_ex is easier to read. Flags are in English instead of letters.
Code:
#include amxmodx #define PLUGIN   "Weapon Switch Snitch" #define VERSION  "1.0.0" #define AUTHOR   "SPiNX" #define URL      "https://github.com/djearthquake" #define charsmin -1 public plugin_init() {     #if AMXX_VERSION_NUM != 182     register_plugin(PLUGIN, VERSION, AUTHOR, URL)     #else     register_plugin(PLUGIN, VERSION, AUTHOR)     #endif } public client_command(id) {       if(is_user_alive(id))     {           static szArgCmd[MAX_NAME_LENGTH]         read_argv(0,szArgCmd, charsmax(szArgCmd))         if(contain(szArgCmd, "weapon_")>charsmin)         {             if(user_has_weapon(id,get_weaponid(szArgCmd))) //extra code due to C4 planting aliases.             {                 replace(szArgCmd, charsmax(szArgCmd), "weapon_", "")                 client_print(0, print_chat, "%n switched to %s.", id, szArgCmd)             }         }     }     return PLUGIN_CONTINUE }

Spoiler

Bugsy 04-08-2024 21:14

Re: CurWeapon Event
 
Or just use register_event()…


All times are GMT -4. The time now is 17:50.

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