#pragma semicolon 1
#include <amxmodx>
#include <fakemeta>
#include <reapi>
enum _:eCvars
{
Float: ENT_LIFETIME,
GLOW,
PERCENT_LOOSE,
MIN_NUM
};
new g_eCvar[eCvars];
new const ENT_CLASSNAME[] = "cashbrick";
new const ENT_MODEL[] = "models/cashbrick.mdl";
new const SND_PICKUP[] = "items/moneypickup.wav";
public plugin_init( )
{
register_plugin( "[ReAPI] Cashbrick", "1.1.1", "Nvoymax" );
RegisterHookChain(RG_CBasePlayer_Killed, "@CBasePlayer_Killed_Post", true);
RegisterHookChain(RG_CSGameRules_RestartRound, "@CSGameRules_RestartRound_Post", true);
}
public plugin_cfg()
{
bind_pcvar_float(create_cvar("cashbrik_ent_life", "7.0", FCVAR_NONE), g_eCvar[ENT_LIFETIME]);
bind_pcvar_num(create_cvar("cashbrik_ent_glow", "1", FCVAR_NONE), g_eCvar[GLOW]);
bind_pcvar_num(create_cvar("cashbrik_per_loose", "10", FCVAR_NONE), g_eCvar[PERCENT_LOOSE]);
bind_pcvar_num(create_cvar("cashbrik_min_num", "100", FCVAR_NONE), g_eCvar[MIN_NUM]);
}
public plugin_precache()
{
precache_model(ENT_MODEL);
precache_sound(SND_PICKUP);
}
@CSGameRules_RestartRound_Post()
{
new iEntity = NULLENT;
while((iEntity = rg_find_ent_by_class(iEntity, ENT_CLASSNAME)) > 0) {
SetThink(iEntity, "");
SetTouch(iEntity, "");
set_entvar(iEntity, var_flags, FL_KILLME);
}
}
@CBasePlayer_Killed_Post(pVictim, pAttacker, pGib)
{
new iMoney = get_member(pVictim, m_iAccount);
if(iMoney < g_eCvar[MIN_NUM] || g_eCvar[MIN_NUM] < 100)
return;
new Float: vecOrigin[3];
new Float: vecVelocity[3];
get_entvar(pVictim, var_origin, vecOrigin);
new iEntity = rg_create_entity("info_target", false);
if(is_nullent(iEntity))
return;
new iResult;
if(g_eCvar[PERCENT_LOOSE] < 1 || g_eCvar[PERCENT_LOOSE] > 100)
iResult = iMoney / random_num(1, 100);
else
iResult = iMoney / g_eCvar[PERCENT_LOOSE];
rg_add_account(pVictim, -iResult);
vecVelocity[0] = random_float(-200.0, 200.0);
vecVelocity[1] = random_float(-200.0, 200.0);
vecVelocity[2] = random_float(1.0, 200.0);
engfunc(EngFunc_SetModel, iEntity, ENT_MODEL);
engfunc(EngFunc_SetSize, iEntity, {-9.0, -7.0, -0.0}, {9.0, 7.0, 6.0});
set_entvar(iEntity, var_origin, vecOrigin);
set_entvar(iEntity, var_classname, ENT_CLASSNAME);
set_entvar(iEntity, var_iuser1, iResult);
set_entvar(iEntity, var_movetype, MOVETYPE_TOSS);
set_entvar(iEntity, var_solid, SOLID_TRIGGER);
set_entvar(iEntity, var_velocity, vecVelocity);
set_entvar(iEntity, var_nextthink, get_gametime() + g_eCvar[ENT_LIFETIME]);
if(g_eCvar[GLOW])
{
set_entvar(iEntity, var_rendermode, kRenderGlow);
set_entvar(iEntity, var_renderamt, 1.0);
set_entvar(iEntity, var_rendercolor, Float: { 0.0, 255.0, 0.0 });
set_entvar(iEntity, var_renderfx, kRenderFxGlowShell);
}
SetThink(iEntity, "@Cashbrick_Think");
SetTouch(iEntity, "@Cashbrick_Touch");
}
@Cashbrick_Think(pEntity)
{
if(!is_entity(pEntity))
return;
if(get_entvar(pEntity, var_iuser2))
{
new Float: fRenderAmt;
get_entvar(pEntity, var_renderamt, fRenderAmt);
if(fRenderAmt > 20.0)
{
set_entvar(pEntity, var_renderamt, fRenderAmt - 20.0);
set_entvar(pEntity, var_nextthink, get_gametime() + 0.1);
}
else
set_entvar(pEntity, var_flags, FL_KILLME);
}
else
{
set_entvar(pEntity, var_iuser2, 1);
set_entvar(pEntity, var_rendermode, kRenderTransTexture);
set_entvar(pEntity, var_renderamt, 255.0);
set_entvar(pEntity, var_nextthink, get_gametime() + 1.5);
}
}
@Cashbrick_Touch(pEntity, pToucher)
{
if(!is_entity(pEntity) || !is_user_connected(pToucher))
return;
new iResult = get_entvar(pEntity, var_iuser1);
rg_add_account(pToucher, iResult);
rh_emit_sound2(pToucher, 0, CHAN_ITEM, SND_PICKUP, VOL_NORM, ATTN_NORM);
set_entvar(pEntity, var_flags, FL_KILLME);
}