Raised This Month: $12 Target: $400
 3% 

[CS][Forward] client_buy


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-06-2011 , 03:20   [CS][Forward] client_buy
Reply With Quote #1

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
Attached Files
File Type: sma Get Plugin or Get Source (client_buy.sma - 3071 views - 7.7 KB)
File Type: inc cl_buy.inc (256 Bytes, 1579 views)
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-06-2012 at 21:10.
ConnorMcLeod is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-06-2011 , 03:20   Re: [CS][Forward] client_buy
Reply With Quote #2

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

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 02-06-2011 at 03:25.
ConnorMcLeod is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-06-2011 , 03:25   Re: [CS][Forward] client_buy
Reply With Quote #3

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()
    }

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 02-06-2011 at 03:32.
ConnorMcLeod is offline
Asd'
Senior Member
Join Date: Jun 2009
Location: Argentina
Old 02-06-2011 , 03:46   Re: [CS][Forward] client_buy
Reply With Quote #4

Thanks for this contribution, it will help me a lot.
By the way, Good job.

Greetings.
__________________
Asd' is offline
Send a message via MSN to Asd'
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-06-2011 , 04:16   Re: [CS][Forward] client_buy
Reply With Quote #5

Great work.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-06-2011 , 06:36   Re: [CS][Forward] client_buy
Reply With Quote #6

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.

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.

Signatures attached.
Attached Files
File Type: zip [signatures]can_player_buy.zip (2.9 KB, 460 views)
__________________

Last edited by Arkshine; 02-07-2011 at 11:41.
Arkshine is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 02-06-2011 , 06:43   Re: [CS][Forward] client_buy
Reply With Quote #7



Will use this for sure in the future.
bibu is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 02-06-2011 , 06:51   Re: [CS][Forward] client_buy
Reply With Quote #8

Good job connor and arkshine
__________________
xPaw is offline
rx1983
Senior Member
Join Date: Jan 2009
Location: BRASIL
Old 02-06-2011 , 11:24   Re: [CS][Forward] client_buy
Reply With Quote #9

I read everything and could not understand anything.
__________________
rx1983 is offline
Send a message via MSN to rx1983
bibu
Veteran Member
Join Date: Sep 2010
Old 02-06-2011 , 12:04   Re: [CS][Forward] client_buy
Reply With Quote #10

Quote:
Originally Posted by rx1983 View Post
I read everything and could not understand anything.
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)
bibu is offline
Reply


Thread Tools
Display Modes

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 09:15.


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