Добрый вечер, есть плагин на боевую гранату для зомби мода, хотелось бы правильно реализовать обнуление лимита при их дропе, к примеру я могу купить сразу несколько гранат, и при дропе одной или нескольких гранат можно было докупить еще до этого лимита и так по кругу, а не как сейчас у меня в плагине, закупился до лимита выбросил и больше нельзя купить в этом раунде, только ждать следующего. Кому не сложно приведите пример как можно это сделать. Похожих примеров или тем не нашел....
Код:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta_util>
#include <zombieplague>
const NADE_TYPE_SHIELDBOMB = 54181
#define GRENADE_EXPLO_MODEL_V "models/serv/grenade/v_explo.mdl"
#define GRENADE_EXPLO_MODEL_P "models/serv/grenade/p_explo.mdl"
#define GRENADE_EXPLO_MODEL_W "models/serv/grenade/w_grenade.mdl"
#define GRENADE_EXPLO_SOUND "weapons/explode4.wav"
#define GRENADE_EXPLO_TRAIL "sprites/laserbeam.spr"
#define GRENADE_EXPLO_SPRITE "sprites/serv/exp_big.spr"
#define GRENADE_EXPLO_RADIUS 200.0
#define GRENADE_EXPLO_DMG random_float(750.0, 1500.0)
new g_trailSpr, g_exploSpr
new g_itemID, g_ExplBomb[33]
public plugin_init()
{
register_plugin("[ZP] Extra Item: Exp Grenade", "1.0", "0_o")
RegisterHam(Ham_Think, "grenade", "fw_ThinkGrenade")
RegisterHam(Ham_Killed, "player", "fw_Killed_Post")
RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "fw_Item_Deploy_Post", 1)
register_forward(FM_SetModel, "fw_SetModel")
register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
g_itemID = zp_register_extra_item("Test", 0, ZP_TEAM_HUMAN)
}
public plugin_precache()
{
engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_MODEL_V)
engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_MODEL_P)
engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_MODEL_W)
g_trailSpr = engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_TRAIL)
g_exploSpr = engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_SPRITE)
}
public event_round_start(id)
{
g_ExplBomb[id] = 0
}
public client_disconnect(id)
g_ExplBomb[id] = 0;
public fw_Killed_Post(id)
{
g_ExplBomb[id] = 0;
}
public zp_user_infected_post(id)
g_ExplBomb[id] = 0;
public zp_extra_item_selected (id, itemid)
{
if(itemid == g_itemID)
{
if (g_ExplBomb[id] >= 3)
{
return ZP_PLUGIN_HANDLED;
}
give_nade_exp(id);
}
return ZP_PLUGIN_HANDLED;
}
public give_nade_exp(iPlayer)
{
if (user_has_weapon(iPlayer, CSW_SMOKEGRENADE))
{
g_ExplBomb[iPlayer]++
ExecuteHamB(Ham_GiveAmmo, iPlayer, 1, "SmokeGrenade", 32);
emit_sound (iPlayer, CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
}
if(give_grenade(iPlayer))
{
g_ExplBomb[iPlayer]++
emit_sound (iPlayer, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
}
else return ZP_PLUGIN_HANDLED;
return 0;
}
public fw_SetModel(entity, const model[])
{
if(!pev_valid(entity))
return FMRES_IGNORED
if(pev(entity, pev_dmgtime) == 0.0)
return FMRES_IGNORED;
new owner = pev(entity, pev_owner)
if(g_ExplBomb[owner] >= 1 && equal (model [7], "w_sm", 4))
{
fm_set_rendering(entity, kRenderFxGlowShell, 255, 20, 147, kRenderNormal, 16)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_BEAMFOLLOW)
write_short(entity)
write_short(g_trailSpr)
write_byte(10)
write_byte(10)
write_byte(255)
write_byte(10)
write_byte(147)
write_byte(500)
message_end()
set_pev(entity, pev_flTimeStepSound, NADE_TYPE_SHIELDBOMB)
g_ExplBomb[owner]--
fm_entity_set_model(entity, GRENADE_EXPLO_MODEL_W);
return FMRES_SUPERCEDE
}
return FMRES_IGNORED
}
public fw_Item_Deploy_Post(entity)
{
if(!pev_valid(entity))return;
new id = get_pdata_cbase(entity, 41, 4)
if(zp_get_user_zombie(id) || is_user_alive(id))
{
if(g_ExplBomb[id])
{
set_pev(id, pev_viewmodel2, GRENADE_EXPLO_MODEL_V)
set_pev(id, pev_weaponmodel2, GRENADE_EXPLO_MODEL_P)
}
}
return
}
public fw_ThinkGrenade(entity)
{
// Invalid entity
if (!pev_valid(entity)) return HAM_IGNORED;
// Get damage time of grenade
static Float:dmgtime, Float:current_time;
pev(entity, pev_dmgtime, dmgtime);
current_time = get_gametime();
// Check if it's time to go off
if (dmgtime > current_time)
return HAM_IGNORED;
// Check if it's one of our custom nades
switch (pev(entity, pev_flTimeStepSound))
{
case NADE_TYPE_SHIELDBOMB:
{
explo_explode(entity);
return HAM_SUPERCEDE;
}
}
return HAM_IGNORED;
}
public explo_explode(Entity)
{
static Float: vecOrigin[3]
pev( Entity, pev_origin, vecOrigin )
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_EXPLOSION)
engfunc(EngFunc_WriteCoord, vecOrigin[0])
engfunc(EngFunc_WriteCoord, vecOrigin[1])
engfunc(EngFunc_WriteCoord, vecOrigin[2] + 40)
write_short(g_exploSpr)
write_byte(20)
write_byte(17)
write_byte(0)
message_end()
emit_sound(Entity, CHAN_WEAPON, GRENADE_EXPLO_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
new iOwner = pev(Entity, pev_owner)
static iVictim;
iVictim = -1;
new Float: vecVictimOrigin[3], Float: flDamage
while ((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, vecOrigin, GRENADE_EXPLO_RADIUS)))
{
if (!is_user_alive(iVictim) || !zp_get_user_zombie(iVictim))
continue;
set_pev(iVictim, pev_punchangle, Float: {30.0, 30.0, 30.0})
pev(iVictim, pev_origin, vecVictimOrigin)
flDamage = GRENADE_EXPLO_DMG * (1.0 - (get_distance_f(vecOrigin, vecVictimOrigin) / GRENADE_EXPLO_RADIUS))
ExecuteHamB(Ham_TakeDamage, iVictim, Entity, iOwner, flDamage, DMG_SONIC | DMG_NEVERGIB)
}
engfunc(EngFunc_RemoveEntity, Entity)
}
stock give_grenade(iPlayer) {
static iEnt;
static g_AllocString_E;
if(g_AllocString_E||(g_AllocString_E=engfunc(EngFunc_AllocString,"weapon_smokegrenade")))
iEnt = engfunc(EngFunc_CreateNamedEntity, g_AllocString_E);
if(iEnt <= 0) return 0;
g_ExplBomb[iPlayer]++;
set_pev(iEnt, pev_spawnflags, SF_NORESPAWN);
ExecuteHam(Ham_Spawn, iEnt);
if(!ExecuteHamB(Ham_AddPlayerItem, iPlayer, iEnt))
{
engfunc(EngFunc_RemoveEntity, iEnt);
return 0;
}
ExecuteHamB(Ham_Item_AttachToPlayer, iEnt, iPlayer);
return iEnt;
}
Последнее редактирование: