AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
07-02-2017
, 13:47
Re: Can somebody fix this plugin
#10
Quote:
Originally Posted by
FR0NTLINE
Surprise me hamlet and where is your donation link?
Try this:
PHP Code:
#include <amxmodx>
#include <orpheu>
#include <fakemeta>
#define PluginName "Price changer"
#define PluginVersion "0.0.2"
#define PluginAuthor "HamletEagle"
#define CSW_SHIELD_ORIG 99
#define CSW_GLOCK 2
enum
{
CSW_DEFUSER = 33 ,
CSW_NVGS ,
CSW_SHIELD ,
CSW_PRIMAMMO ,
CSW_SECAMMO
}
new const ExtraItemNames [][] =
{
"vest" ,
"vesthelm" ,
"defuser" ,
"nvgs" ,
"shield" ,
"primammo" ,
"secammo"
}
new const ItemsFromMenu [] =
{
CSW_VEST ,
CSW_VESTHELM ,
CSW_FLASHBANG ,
CSW_HEGRENADE ,
CSW_SMOKEGRENADE ,
CSW_NVGS ,
CSW_DEFUSER ,
CSW_SHIELD
}
new const AmmoType [] =
{
CSW_PRIMAMMO ,
CSW_SECAMMO
}
const SecondaryWeaponBitsum = ( 1 << CSW_P228 | 1 << CSW_ELITE | 1 << CSW_FIVESEVEN | 1 << CSW_USP | 1 << CSW_GLOCK18 | 1 << CSW_DEAGLE )
const m_iId = 43
const XoCBasePlayerItem = 4
const NoItem = - 1
new HandleCvars [ CSW_SECAMMO + 1 ]
new ItemToBuy [ 33 ] = { NoItem , ...}
public plugin_init ()
{
register_plugin
(
. plugin_name = PluginName ,
. version = PluginVersion ,
. author = PluginAuthor
)
OrpheuRegisterHook ( OrpheuGetFunction ( "CanBuyThis" ), "OnCanBuyThis" , OrpheuHookPre )
OrpheuRegisterHook ( OrpheuGetFunction ( "BuyItem" ), "OnBuyItem" , OrpheuHookPre )
OrpheuRegisterHook ( OrpheuGetFunction ( "BuyGunAmmo" ), "OnBuyGunAmmo" , OrpheuHookPre )
OrpheuRegisterHook ( OrpheuGetFunction ( "AddAccount" , "CBasePlayer" ), "CBasePlayer_AddAccount" , OrpheuHookPre )
new WeaponName [ 32 ], CvarName [ 64 ]
for(new i = CSW_P228 ; i <= CSW_SECAMMO ; i ++)
{
if( i == CSW_GLOCK )
{
continue
}
get_weaponname_ex ( i , WeaponName , charsmax ( WeaponName ))
formatex ( CvarName , charsmax ( CvarName ), "%s_price" , WeaponName )
HandleCvars [ i ] = register_cvar ( CvarName , "-1" )
}
}
public OrpheuHookReturn : OnCanBuyThis (const id , const WeaponId )
{
if( is_user_alive ( id ))
{
ItemToBuy [ id ] = WeaponId
}
}
public OrpheuHookReturn : OnBuyItem (const id , const Slot )
{
if( is_user_alive ( id ))
{
ItemToBuy [ id ] = ItemsFromMenu [ Slot - 1 ]
new name [ 32 ]
get_weaponname_ex ( ItemToBuy [ id ], name , charsmax ( name ))
}
}
public OrpheuHookReturn : OnBuyGunAmmo (const id , const entity , const bool : blinkMoney )
{
if( is_user_alive ( id ))
{
if( pev_valid ( entity ))
{
new weaponId = get_pdata_int ( entity , m_iId , XoCBasePlayerItem )
if(( 1 << weaponId ) & SecondaryWeaponBitsum )
{
ItemToBuy [ id ] = AmmoType [ 1 ]
}
else
{
ItemToBuy [ id ]= AmmoType [ 0 ]
}
}
}
}
public CBasePlayer_AddAccount (const id , const Ammount , const bool : TrackChange )
{
if( ItemToBuy [ id ] != NoItem )
{
//In game CSW_SHIELD has index 99, the best solution is to check and adjust it instead of sizing the array by 99.
if( ItemToBuy [ id ] == CSW_SHIELD_ORIG )
{
ItemToBuy [ id ] = CSW_SHIELD
}
new CvarValue = get_pcvar_num ( HandleCvars [ ItemToBuy [ id ]])
if( CvarValue != - 1 )
{
OrpheuSetParam ( 2 , (- 1 ) * CvarValue )
ItemToBuy [ id ] = NoItem
}
}
}
get_weaponname_ex (const WeaponIndex , WeaponName [], const Size )
{
if( CSW_P228 <= WeaponIndex <= CSW_P90 )
{
get_weaponname ( WeaponIndex , WeaponName , Size )
replace ( WeaponName , Size , "weapon_" , "" )
}
else
{
copy ( WeaponName , Size , ExtraItemNames [ WeaponIndex - CSW_VEST ])
}
}
And the needed signatures:
Spoiler
Code:
{
"name" : "CanBuyThis",
"library" : "mod",
"arguments" :
[
{
"type" : "CBasePlayer *"
},
{
"type" : "int"
}
],
"return" :
{
"type" : "bool"
},
"identifiers":
[
{
"os" : "windows",
"mod" : "cstrike",
"value" : [0x53,0x8B,"*","*","*","*","*",0x56,0x8B,"*","*","*",0x57,0x8B,"*",0xE8]
},
{
"os" : "linux",
"mod" : "cstrike",
"value" : "_Z10CanBuyThisP11CBasePlayeri"
}
]
}
Code:
{
"name" : "BuyItem",
"library" : "mod",
"arguments" :
[
{
"type" : "CBasePlayer *"
},
{
"type" : "int"
}
],
"identifiers":
[
{
"os" : "windows",
"mod" : "cstrike",
"value" : [0x53,0x56,0x8B,"*","*","*",0xBB,"*","*","*","*",0x57,0x53,0x8B,"*",0xE8]
},
{
"os" : "linux",
"mod" : "cstrike",
"value" : "_Z7BuyItemP11CBasePlayeri"
}
]
}
Code:
{
"name" : "BuyGunAmmo",
"library" : "mod",
"arguments" :
[
{
"type" : "CBasePlayer *"
},
{
"type" : "CBasePlayerItem *"
},
{
"type" : "bool"
}
],
"identifiers":
[
{
"os" : "windows",
"mod" : "cstrike",
"value" : [0x56,0x57,0x8B,"*","*","*",0x6A,"*",0x8B,"*",0xE8,"*","*","*","*",0x84,"*",0x0F]
},
{
"os" : "linux",
"mod" : "cstrike",
"value" : "_Z10BuyGunAmmoR11CBasePlayerR15CBasePlayerItemb"
}
]
}
Code:
{
"name" : "AddAccount",
"class" : "CBasePlayer",
"library" : "mod",
"arguments" :
[
{
"type" : "int",
"info" : "ammount"
},
{
"type" : "bool",
"info" : "bTrackChange.If 1, the amount of money added will be displayed"
}
],
"identifiers" :
[
{
"os" : "windows",
"mod" : "cstrike",
"value" : [0x8B,"*","*","*",0x56,0x8B,"*",0x8B,"*","*","*","*","*",0x03,"*",0x89,"*","*","*","*","*",0x8B,"*",0x79]
},
{
"os" : "linux",
"mod" : "cstrike",
"value" : "_ZN11CBasePlayer10AddAccountEib"
}
]
}
First 3 must be put directly in "functions", the last one must be inside orpheu/functions/CBasePlayer.
Set the new prices by cvars. The patter it's weaponname_price. weaponname is without weapon_.
For the less common stuff use this names:
Code:
"vest",
"vesthelm",
"defuser",
"nvgs",
"shield",
"primammo",
"secammo"
For example: p228_price or primammo_price.
A full list of cvars:
Code:
p228_price
scout_price
hegrenade_price
xm1014_price
c4_price
mac10_price
aug_price
smokegrenade_price
elite_price
fiveseven_price
ump45_price
sg550_price
galil_price
famas_price
usp_price
glock18_price
awp_price
mp5navy_price
m249_price
m3_price
m4a1_price
tmp_price
g3sg1_price
flashbang_price
deagle_price
sg552_price
ak47_price
knife_price
p90_price
vest_price
vesthelm_price
defuser_price
nvgs_price
shield_price
primammo_price
secammo_price
Cvars are by default -1, which means: use default value. So when you want an item to use it's default price, simply set the cvar to -1.
I did not test much, it's up to you to make sure it works in all cases.
About the donation, I never asked for money for plugins. It does not feel right, so I don't do it.
__________________
Last edited by HamletEagle; 07-04-2017 at 08:51 .
Reason: Fixed a bug with shield.