/*
* Weapon Return
*
* Author: nikhilgupta345 (AKA H3avY Ra1n)
*
* Description
* -----------
* This plugin allows players to return their
* weapons back to the store for a refund.
*
* Client Commands
* ---------------
* say /return - Returns current weapon of player.
*
* CVars
* -----
* rw_percent <percentage> <default:0.80>
* - How much money players should get back.
* - MUST BE A DECMIAL.
*
*
* rw_buyzone <0/1> <default:1>
* - Whether players must be in a buyzone
* to return their weapon(s).
*
* Changelog
* ---------
* July 30, 2011 - v1.0 - Plugin Release
* - v1.1 - Few optimizations
* - v1.2 - Added support for shield return
*
* Credits
* -------
* XxAvalanchexX - ham_strip_weapon stock
* Exolent - cs_set_user_shield stock
*
* Installation
* ------------
* - Compile this file
* - Place 'weapon_return.amxx' in the plugins folder
* - Add 'weapon_return.amxx' to plugins.ini
* - Restart server or change map
*
* Plugin Thread
* -------------
* http://forums.alliedmods.net/showthread.php?t=163397
*
* Fordította: BBk - Death of Legend
*
*/
#include < amxmodx >
#include < cstrike >
#include < hamsandwich >
#include < fakemeta >
#include < fun >
new const g_iWeaponCost[ CSW_P90 + 1 ] =
{
0,
600,
2200,
2750,
300,
3000,
0, // c4
1400,
3500,
300,
800,
750,
1700,
4200,
2000,
2250,
500,
400,
4750,
1500,
5750,
1700,
3100,
1250,
5000,
200,
650,
3500,
2500,
0, // knife
2350
};
const g_iShieldCost = 2200;
new g_pReturnPercent;
new g_pBuyzoneOnly;
public plugin_init()
{
register_plugin( "Fegyver visszaadas", "1.0", "H3avY Ra1n" );
register_clcmd( "say /vissza", "Cmd_Return" );
g_pReturnPercent = register_cvar( "rw_percent", ".80" );
g_pBuyzoneOnly = register_cvar( "rw_buyzone", "1" );
}
public Cmd_Return( id )
{
if( !is_user_alive( id ) )
{
client_print( id, print_chat, "Halott vagy, nem hasznalhatod ezt a parancsot." );
return PLUGIN_HANDLED;
}
if( !cs_get_user_buyzone( id ) && get_pcvar_num( g_pBuyzoneOnly ) )
{
client_print( id, print_center, "Nem a vasarlasi zonanal tartozkodsz!" );
return PLUGIN_HANDLED;
}
new Float:fPercent = get_pcvar_float( g_pReturnPercent );
if( fPercent == 0.0 )
{
client_print( id, print_chat, "A fegyver vissza vasarlasa egyelore nem lehetseges." );
return PLUGIN_HANDLED;
}
new iWeapon = get_user_weapon( id );
new bool:bShield = cs_get_user_shield( id ) && iWeapon == CSW_KNIFE;
new iCost;
if( bShield )
{
iCost = g_iShieldCost;
}
else
{
iCost = g_iWeaponCost[ iWeapon ];
}
if( iCost <= 0 )
{
client_print( id, print_center, "Nem tudod vissza vasarolni a fegyvered." );
return PLUGIN_HANDLED;
}
new iRefund = floatround( iCost * fPercent, floatround_round );
if( iRefund == 0 )
{
client_print( id, print_center, "Nem tudod vissza vasarolni a fegyvered." );
return PLUGIN_HANDLED;
}
if( bShield )
{
cs_set_user_shield( id, 0 );
}
else
{
new szWeaponName[ 32 ];
get_weaponname( iWeapon, szWeaponName, charsmax( szWeaponName ) );
ham_strip_weapon( id, szWeaponName );
}
cs_set_user_money( id, min( cs_get_user_money( id ) + iRefund, 16000 ) );
client_print( id, print_chat, "A fegyvereid vissza vasaroltad $%i -ert.", iRefund );
return PLUGIN_HANDLED;
}
// By XxAvalanchexX
stock ham_strip_weapon(id,weapon[])
{
if(!equal(weapon,"weapon_",7)) return 0;
new wId = get_weaponid(weapon);
if(!wId) return 0;
new wEnt;
while((wEnt = engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != id) {}
if(!wEnt) return 0;
if(get_user_weapon(id) == wId) ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
if(!ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) return 0;
ExecuteHamB(Ham_Item_Kill,wEnt);
set_pev(id,pev_weapons,pev(id,pev_weapons) & ~(1<<wId));
return 1;
}
// By Exolent
stock cs_set_user_shield(id, set)
{
if(set)
{
give_item(id, "weapon_shield");
}
else
{
const m_iUserPrefs = 510;
const USING_SHIELD = (1<<16);
const HAS_SHIELD = (1<<24);
new prefs = get_pdata_int(id, m_iUserPrefs) & ~USING_SHIELD;
if(prefs & HAS_SHIELD)
{
new model[64];
pev(id, pev_viewmodel2, model, charsmax(model));
if(equal(model, "models/shield/v_shield_", 23))
{
replace(model, charsmax(model), "shield/v_shield", "v");
set_pev(id, pev_viewmodel2, model);
}
pev(id, pev_weaponmodel2, model, charsmax(model));
if(equal(model, "models/shield/p_shield_", 23))
{
replace(model, charsmax(model), "shield/p_shield", "p");
set_pev(id, pev_weaponmodel2, model);
}
set_pdata_int(id, m_iUserPrefs, (prefs & ~HAS_SHIELD));
}
}
return 1;
}