AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [CS][Forward] client_buy (https://forums.alliedmods.net/showthread.php?t=149380)

ConnorMcLeod 02-06-2011 03:20

[CS][Forward] client_buy
 
5 Attachment(s)
client_buy Forward



.: Description :.


The plugin offers a forward that allow you to hook any buy attempt.



.: Forward :.

client_buy < player index > < item type >

Returns : PLUGIN_CONTINUE , PLUGIN_HANDLED


.: Item indexes :.

For weapons, index is the weapon type, so CSW_AK47 or CSW_MP5NAVY for example.
For vest and helmet, this is amxx defines : CSW_VEST and CSW_VESTHELM.
I had to introduce new indexes for the plugin, here they are :
  • CSW_DEFUSER : defusal kit
  • CSW_NVGS : nightvision
  • CSW_SHIELD : shield
  • CSW_PRIMAMMO : primary ammo
  • CSW_SECAMMO : secondary ammo
Spoiler

ConnorMcLeod 02-06-2011 03:20

Re: [CS][Forward] client_buy
 
Plugin example :

AWP Restriction

PHP Code:

#include <amxmodx>
#include <cl_buy>

#define VERSION "0.0.1"
#define PLUGIN "No Awp"

new g_iTextMsg

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
    
g_iTextMsg get_user_msgid("TextMsg")
}

public 
client_buy(idiItem)
{
    if( 
iItem == CSW_AWP && !user_has_weapon(idCSW_AWP) )
    {
        
message_beginMSG_ONE_UNRELIABLEg_iTextMsg, .player=id )
        {
            
write_byteprint_center )
            
write_string"#Alias_Not_Avail" )
            
write_string"#ArcticWarfareMagnum" )
        }
        
message_end()

        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE



ConnorMcLeod 02-06-2011 03:25

Re: [CS][Forward] client_buy
 
Some misc things you could find usefull :
PHP Code:

new const g_szLabelsShort[][] = {
    
"",
    
"#P228Compact",
    
"",
    
"#Schmidt",
    
"#HE_Grenade",
    
"#AutoShotgun",
    
""// CSW_C4
    
"#Mac10_Short",
    
"#Aug",
    
"#Smoke_Grenade",
    
"#Dual40",
    
"#ESFiveSeven",
    
"#KMUMP45",
    
"#Krieg550",
    
"#Galil",
    
"#Famas",
    
"#KM45Tactical",
    
"#Sidearm9X19mm",
    
"#Magnum",
    
"#SubMachineGun",
    
"#ESM249",
    
"#Leone12",
    
"#M4A1_Short",
    
"#SchmidtMP",
    
"#D3AU1",
    
"#Flashbang",
    
"#NightHawk",
    
"#Krieg552",
    
"#AK47",
    
""// CSW_KNIFE
    
"#ESC90",
    
"#Kevlar",
    
"#Kevlar_Helmet",
    
"#Defusal_Kit",
    
"#NightVision",
    
"#TactShield",
    
"Prim. Ammo",
    
"Sec. Ammo"


PHP Code:

new const g_szLabels[][] = {
    
"",
    
"#P228",
    
"",
    
"#Scout",
    
"#HE_Grenade",
    
"#xm1014",
    
""// CSW_C4
    
"#MAC10",
    
"#Aug",
    
"#Smoke_Grenade",
    
"#Beretta96G",
    
"#FiveSeven",
    
"#UMP45",
    
"#SG550",
    
"#Galil",
    
"#Famas",
    
"#USP45",
    
"#Glock18",
    
"#ArcticWarfareMagnum",
    
"#mp5navy",
    
"#M249",
    
"#Super90",
    
"#M4A1",
    
"#Tmp",
    
"#G3SG1",
    
"#Flashbang",
    
"#DesertEagle",
    
"#SG552",
    
"#AK47",
    
""// CSW_KNIFE
    
"#FNP90",
    
"#Kevlar",
    
"#Kevlar_Helmet",
    
"#Defusal_Kit",
    
"#NightVision",
    
"#TactShield",
    
"Prim. Ammo",
    
"Sec. Ammo"


PHP Code:

new const g_szItemNames[][] = {
    
"",
    
"228 Compact",
    
"",
    
"Schmidt Scout",
    
"HE Grenade",
    
"Auto Shotgun",
    
""// CSW_C4
    
"Mac-10",
    
"Bullpup",
    
"Smoke Grenade",
    
".40 Dual",
    
"Five-Seven",
    
"K&M UMP45",
    
"Krieg 550",
    
"IDF Defender",
    
"Clarion 5.56",
    
"K&M .45",
    
"9X19mm",
    
"Magnum",
    
"SMG",
    
"ES M249",
    
"12 Gauge",
    
"M4A1",
    
"Schmidt MP",
    
"D3AU1",
    
"Flashbang"// "#Cstrike_Flashbang"
    
"Night Hawk",
    
"Krieg 552",
    
"CV-47",
    
""// CSW_KNIFE
    
"ES C90",
    
"Kevlar",
    
"Kevlar+Helmet",
    
"Defusal Kit",
    
"NightVision",
    
"Tactical Shield",
    
"Prim. Ammo",
    
"Sec. Ammo"


PHP Code:

user_has_item(idiItem)
{
    switch( 
iItem )
    {
        case 
CSW_VESTCSW_VESTHELM :
        {
            new 
CsArmorType:iArmorType
            cs_get_user_armor
(idiArmorType)
            return 
iArmorType == (iItem == CSW_VEST CS_ARMOR_KEVLAR CS_ARMOR_VESTHELM)
        }
        case 
CSW_DEFUSER:
        {
            return 
cs_get_user_defuse(id)
        }
        case 
CSW_NVGS:
        {
            return 
cs_get_user_nvg(id)
        }
        case 
CSW_SHIELD:
        {
            
cs_get_user_shield(id)
        }
        case 
CSW_PRIMAMMOCSW_SECAMMO:
        {
            return 
0
        
}
    }
    return 
user_has_weapon(idiItem)


PHP Code:

Message_Alias_Not_Avail(idiId)
{
    if( !
user_has_item(idiId) )
    {
        
message_begin(MSG_ONE_UNRELIABLEg_iTextMsg, .player=id// have to set g_iTextMsg = get_user_msgid("TextMsg") at plugin_init
        
write_byteprint_center )
        
write_string"#Alias_Not_Avail" )
        
write_stringg_szLabels[iId] )
        
message_end()
    }



Asd' 02-06-2011 03:46

Re: [CS][Forward] client_buy
 
Thanks for this contribution, it will help me a lot.
By the way, Good job.

Greetings.

Exolent[jNr] 02-06-2011 04:16

Re: [CS][Forward] client_buy
 
Great work.

Arkshine 02-06-2011 06:36

Re: [CS][Forward] client_buy
 
1 Attachment(s)
Since it's always interesting to show severals ways of something, I post just another way using Orpheu. No harcoding. Also, to piss Connor off. :twisted:

PHP Code:

#include <amxmodx>
#include <orpheu>
#include <fakemeta>

enum
{
    
CSW_DEFUSER 33,
    
CSW_NVGS,
    
CSW_SHIELD,
    
CSW_PRIMAMMO,
    
CSW_SECAMMO
};

const 
BitsPistols = ( << CSW_GLOCK18 << CSW_USP << CSW_P228 << CSW_DEAGLE << CSW_ELITE << CSW_FIVESEVEN );

new const 
itemSlotToWeaponId[] = { -1CSW_VESTCSW_VESTHELMCSW_FLASHBANGCSW_HEGRENADECSW_SMOKEGRENADECSW_NVGSCSW_DEFUSERCSW_SHIELD };
new const 
ammoToWeaponId    [] = { CSW_PRIMAMMOCSW_SECAMMO };

const 
m_iId 43;

new 
HandleForwardBuy;

public 
plugin_natives()
{
    
register_library"cl_buy" );
}

public 
plugin_init()
{
    
register_plugin"Can Buy Item""1.0.0""Arkshine" );

    
OrpheuRegisterHookOrpheuGetFunction"CanBuyThis" ), "CanBuyThis" ); // Weapons
    
OrpheuRegisterHookOrpheuGetFunction"BuyItem" )   , "BuyItem"    ); // Items
    
OrpheuRegisterHookOrpheuGetFunction"BuyGunAmmo" ), "BuyGunAmmo" ); // Ammos
    
    
HandleForwardBuy CreateMultiForward"client_buy"ET_STOPFP_CELLFP_CELL );
}

public 
OrpheuHookReturn:CanBuyThis( const player, const weaponId )
{
    return 
CanBuyItemplayerweaponId );
}

public 
OrpheuHookReturn:BuyItem( const player, const slot )
{
    return 
CanBuyItemplayeritemSlotToWeaponIdslot ] );
}

public 
OrpheuHookReturn:BuyGunAmmo( const player, const item, const bool:displayMsg )
{
    return 
CanBuyItemplayerammoToWeaponId[ !( get_pdata_intitemm_iId) & BitsPistols ) ] );
}

OrpheuHookReturn:CanBuyItem( const player, const itemId )
{
    static 
pluginReturn;
    
ExecuteForwardHandleForwardBuypluginReturnplayeritemId );

    return ( 
pluginReturn != PLUGIN_CONTINUE ) ? OrpheuSupercede OrpheuIgnored;


Plugin not really tested. I won't develop more, it was just to see how it can be handled with orpheu. Feel free to Connor to do what he wants with it. :P

Signatures attached.

bibu 02-06-2011 06:43

Re: [CS][Forward] client_buy
 
:mrgreen:

Will use this for sure in the future.

xPaw 02-06-2011 06:51

Re: [CS][Forward] client_buy
 
Good job connor and arkshine

rx1983 02-06-2011 11:24

Re: [CS][Forward] client_buy
 
I read everything and could not understand anything. :down:

bibu 02-06-2011 12:04

Re: [CS][Forward] client_buy
 
Quote:

Originally Posted by rx1983 (Post 1408578)
I read everything and could not understand anything. :down:

Isn't the right section. And if you do not understand, you don't need to show like that this forward is bad for you. (meant your smile, yes)


All times are GMT -4. The time now is 13:36.

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