AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [solved]catch smoke grenade bought (https://forums.alliedmods.net/showthread.php?t=108874)

Owyn 11-10-2009 14:00

[solved]catch smoke grenade bought
 
code to catch HE nade bought, but i'd like to do the same for the smoke greneade, i'm not very familar with "<<" things + is there a cl_cmd like hegren for smoke one?
PHP Code:

// HE nade
        // Old Style
        
register_menucmdregister_menuid"BuyItem" )    , (1<<3)    , "cmd_hegren"    );

        
// VGUI
        
register_menucmd( -34    , (1<<3)    , "cmd_hegren"    );

        
// Steam
        
register_clcmd"hegren"    "cmd_hegren"    ); 


Exolent[jNr] 11-10-2009 14:02

Re: catch smoke grenade bought
 
cstrike/autobuy.txt

ConnorMcLeod 11-10-2009 14:02

Re: catch smoke grenade bought
 
With this code you only catch the attempt to buy a HE.
And i'm not sure the VGUI thing works.

Jon 11-10-2009 14:12

Re: catch smoke grenade bought
 
Probably catches if you have smoke grenade in game_player_equip. Not sure if this catches picking up from the ground too.

PHP Code:

#include <amxmodx>
#include <engine>
#include <hamsandwich>

public plugin_init( )
{
    
RegisterHamHam_AddPlayerItem"player""ReceiveGrenade" )
}

public 
ReceiveGrenadeidEnt )
{
    new Class[ 
32 ]
    
entity_get_stringEntEV_SZ_classname, Class, 31 )
    
    if( 
equal( Class, "weapon_smokegrenade" ) )
    {
        
// .. 
    
}



ConnorMcLeod 11-10-2009 14:29

Re: catch smoke grenade bought
 
PHP Code:

#include <amxmodx>
#include <cstrike>

#define VERSION "0.0.1"

public plugin_init()
{
    
register_plugin("Hook Buy SmokeGrenade"VERSION"Author")

    
register_menucmd(register_menuid("T_BuyItem"1), (1<<4), "BuySmokeGrenade")

}

public 
BuySmokeGrenadeid )
{
    
// attempt to buy a smoke grenade
}

public 
client_command(id)
{
    static 
szCommand[7// sgren

    
if( read_argv(0szCommandcharsmax(szCommand)) == && equal(szCommand"sgren") )
    {
        
// attempt to buy a smoke grenade
    
}
}

public 
CS_InternalCommand(id, const szCommand[])
{
    if( 
equal(szCommand"sgren") )
    {
        
// attempt to buy a smoke grenade
    
}



Exolent[jNr] 11-10-2009 14:43

Re: catch smoke grenade bought
 
DO NOT USE THE CODE IN THIS POST

/win

PHP Code:

#include < amxmodx >
#include < cstrike >
#include < engine >

public client_PreThinkiPlayer ) {
    if( 
is_user_aliveiPlayer ) ) {
        static 
iOldMoney33 ], bool:bHadSmoke33 ];
        static 
Float:fLastMoneyChange33 ], Float:fLastSmokeChange33 ];
        
        new 
iMoney cs_get_user_moneyiPlayer );
        new 
iSmoke cs_get_user_bpammoiPlayerCSW_SMOKEGRENADE );
        
        if( 
iMoney iOldMoneyiPlayer ] ) {
            
fLastMoneyChangeiPlayer ] = get_gametime( );
        }
        
        if( 
iSmoke && !bHadSmokeiPlayer ] ) {
            
fLastSmokeChangeiPlayer ] = get_gametime( );
        }
        
        if( 
floatabsfLastMoneyChangeiPlayer ] - fLastSmokeChangeiPlayer ] ) < 0.3 ) {
            
// player bought smoke
        
}
        
        
iOldMoneyiPlayer ] = iMoney;
        
bHadSmokeiPlayer ] = ( iSmoke );
    }


lol

xPaw 11-10-2009 15:13

Re: [solved]catch smoke grenade bought
 
lol exolent wtf

meTaLiCroSS 11-10-2009 15:22

Re: [solved]catch smoke grenade bought
 
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

const m_pPlayer 41

public plugin_init()
    
RegisterHam(Ham_Item_AddToPlayer"weapon_smokegrenade""fw_SmokeGren_AddToPlayer")
    
public 
fw_SmokeGren_AddToPlayer(sg)
{
    static 
iOwner
    iOwner 
get_pdata_cbase(sgm_pPlayer4)
    
    if(
is_user_connected(iOwner))
    {
        
// A player has received an Smoke grenade
    
}


:crab:?

ConnorMcLeod 11-10-2009 18:17

Re: [solved]catch smoke grenade bought
 
@xolent
VEN's method with client command hook should be better than hooking client prethink.

PHP Code:

#include <amxmodx>

#define MAX_CLIENTS 32
new g_weapons[MAX_CLIENTS 1]

public 
plugin_init() {
        
register_event("Money""event_money""be")
}

public 
client_command(id) {
        
g_weapons[id] = get_user_weapons(iddummydummy2)
}

public 
event_money(id) {
        new 
old_weapons g_weapons[id]
        
client_command(id)

        new 
new_weapon g_weapons[id] & ~old_weapons
        
if (new_weapon) {
                new 
= -1
                
do ++x; while ((new_weapon /= 2) >= 1)
                static 
wname[32]
                
get_weaponname(xwnamesizeof wname 1)
                
server_print("Player [ClientIndex=%d] has bought ^"%s^" [WeaponIndex=%d]"idwnamex)
        }


Should work for smokegrenade, not sure if the money check is required :
PHP Code:

#include <amxmodx>

#define MAX_CLIENTS 32
new g_bHasSmokeGren[MAX_CLIENTS 1]
new 
g_bUserMoney[MAX_CLIENTS 1]

public 
plugin_init() {
        
register_event("Money""event_money""be")
}

public 
client_command(id)
{
        
g_bHasSmokeGren[id] = user_has_weapon(idCSW_SMOKEGRENADE)
}

public 
event_money(id)
{
    new 
iNewMoney read_data(1)
    if(    !
g_bHasSmokeGren[id]
    &&    (
g_bHasSmokeGren[id] = user_has_weapon(idCSW_SMOKEGRENADE))    )
    {
        if( 
g_bUserMoney[id] - iNewMoney == 300 )
        {
            
client_print(idprint_chat"Enjoy the smoke.")
        }
    }

    
g_bUserMoney[id] = iNewMoney



Exolent[jNr] 11-10-2009 18:24

Re: [solved]catch smoke grenade bought
 
My way was just a joke, not to be taken seriously. :P


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

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