Баг с гранатами

Сообщения
15
Реакции
2
День добрый, пытался вшить две гранаты в один плагин (по сути все тоже самое, кроме ресурсов, урона) Но когда покупаю одну гранату - Explo Nade, затем вторую -Holy Nade, их совмещает в один слот, получается как будто я купил две одинаковые гранаты. Помогите найти косяк, что я не так сделал?
Код:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta_util>
#include <zombieplague>
#include <colorchat>

new const ZP_PREFIX[] = "ZP"

const PEV_NADE_TYPE = pev_flTimeStepSound
const NADE_TYPE_EXPLO_BOMB = 5418154
const NADE_TYPE_HOLY_BOMB = 434537

#define GRENADE_EXPLO_MODEL_P "models/test/grenade/p_m24grenade.mdl"
#define GRENADE_EXPLO_MODEL_V "models/test/grenade/v_m24grenade.mdl"
#define GRENADE_EXPLO_MODEL_W "models/test/grenade/w_m24grenade.mdl"
#define GRENADE_EXPLO_SOUND  "weapons/explode4.wav"
#define GRENADE_EXPLO_TRAIL "sprites/laserbeam.spr"
#define GRENADE_EXPLO_SPRITE "sprites/test/he_expl.spr"

#define GRENADE_HOLY_MODEL_P "models/test/grenade/p_holybomb.mdl"
#define GRENADE_HOLY_MODEL_V "models/test/grenade/v_holybomb.mdl"
#define GRENADE_HOLY_MODEL_W "models/test/grenade/w_holybomb.mdl"
#define GRENADE_HOLY_SOUND  "test/holywater_explosion.wav"
#define GRENADE_HOLY_SPRITE "sprites/test/exp_frost.spr"

#define GRENADE_EXPLO_RADIUS 200.0
#define GRENADE_EXPLO_DMG 750.0

#define GRENADE_HOLY_RADIUS 200.0
#define GRENADE_HOLY_DMG 1500.0

new g_trailSpr, g_exploSpr, g_exploSpr2
new g_itemID, g_itemID2, g_ExploBomb[33], g_HolyBomb[33]

public plugin_init()
{
    register_plugin("[ZP] Extra Item: Grenades", "1.0", "Test")   
    register_dictionary("zp_addon.txt")
    
    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("Explo Nade", 0, ZP_TEAM_HUMAN)   
    g_itemID2 = zp_register_extra_item("Holy Nade", 0, ZP_TEAM_HUMAN)       
}
    
public plugin_precache()
{
    engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_MODEL_P)
    engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_MODEL_V)
    engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_MODEL_W)

    engfunc(EngFunc_PrecacheModel, GRENADE_HOLY_MODEL_P)
    engfunc(EngFunc_PrecacheModel, GRENADE_HOLY_MODEL_V)
    engfunc(EngFunc_PrecacheModel, GRENADE_HOLY_MODEL_W)
    
    g_trailSpr = engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_TRAIL)
    g_exploSpr = engfunc(EngFunc_PrecacheModel, GRENADE_EXPLO_SPRITE)   
    g_exploSpr2 = engfunc(EngFunc_PrecacheModel, GRENADE_HOLY_SPRITE)       
}

public event_round_start(id)
{
    g_ExploBomb[id] = 0;
    g_HolyBomb[id] = 0;   
}

public client_disconnect(id)
{
    g_ExploBomb[id] = 0;
    g_HolyBomb[id] = 0;       
}

public fw_Killed_Post(id)
{
    g_ExploBomb[id] = 0;
    g_HolyBomb[id] = 0;       
}

public zp_user_infected_post(id)
{
    g_ExploBomb[id] = 0;
    g_HolyBomb[id] = 0;       
}
    
public zp_extra_item_selected(id, itemid)
{
    if(itemid == g_itemID)
    {
        if (g_ExploBomb[id] >= 3)
        {
            client_print_color(id, print_team_default, "^x04[%s]^x01 %L", ZP_PREFIX, id, "GRENADE_LIMIT", g_ExploBomb[id])       
            return ZP_PLUGIN_HANDLED;
        }               
        give_nade_exp(id);   
    }
    if(itemid == g_itemID2)
    {
        if (g_HolyBomb[id] >= 3)
        {
            client_print_color(id, print_team_default, "^x04[%s]^x01 %L", ZP_PREFIX, id, "GRENADE_LIMIT", g_HolyBomb[id])       
            return ZP_PLUGIN_HANDLED;
        }               
        give_nade_holy(id);   
    }
    return ZP_PLUGIN_HANDLED;
}

public give_nade_exp(id)
{   
    if (user_has_weapon(id, CSW_SMOKEGRENADE))
    {
        g_ExploBomb[id]++
        ExecuteHamB(Ham_GiveAmmo, id, 1, "SmokeGrenade", 32);
        emit_sound (id, CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
        client_print_color(id, print_team_default, "^x04[%s]^x01 %L", ZP_PREFIX, id, "GRENADE_EXP_BUY", g_ExploBomb[id])           
    }
    if(give_grenade(id))
    {
        g_ExploBomb[id]++
        emit_sound (id, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
        client_print_color(id, print_team_default, "^x04[%s]^x01 %L", ZP_PREFIX, id, "GRENADE_EXP_BUY", g_ExploBomb[id])           
    }
    else return ZP_PLUGIN_HANDLED;
    
    return 0;
}

public give_nade_holy(id)
{   
    if (user_has_weapon(id, CSW_SMOKEGRENADE))
    {
        g_HolyBomb[id]++
        ExecuteHamB(Ham_GiveAmmo, id, 1, "SmokeGrenade", 32);
        emit_sound (id, CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
        client_print_color(id, print_team_default, "^x04[%s]^x01 %L", ZP_PREFIX, id, "GRENADE_EXP_BUY", g_HolyBomb[id])           
    }
    if(give_grenade(id))
    {
        g_HolyBomb[id]++
        emit_sound (id, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
        client_print_color(id, print_team_default, "^x04[%s]^x01 %L", ZP_PREFIX, id, "GRENADE_EXP_BUY", g_HolyBomb[id])           
    }
    else return ZP_PLUGIN_HANDLED;
    
    return 0;
}
    
public fw_SetModel(entity, const model[])
{
    // We don't care
    if (strlen(model) < 8)
        return FMRES_IGNORED;

    // Narrow down our matches a bit
    if (model[7] != 'w' || model[8] != '_')
        return FMRES_IGNORED;
    
    // Get damage time of grenade
    static Float:dmgtime
    pev(entity, pev_dmgtime, dmgtime)
    
    // Grenade not yet thrown
    if (dmgtime == 0.0)
        return FMRES_IGNORED;
        
    new owner = pev(entity, pev_owner)
    
    if(g_ExploBomb[owner] >= 1 && equal (model [7], "w_sm", 4))
    {           
        fm_set_rendering(entity, kRenderFxGlowShell, 66, 49, 137, kRenderNormal, 16)

        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_BEAMFOLLOW)
        write_short(entity)
        write_short(g_trailSpr)
        write_byte(5) 
        write_byte(5)
        write_byte(66)
        write_byte(49) 
        write_byte(137)
        write_byte(200)
        message_end()

        set_pev(entity, PEV_NADE_TYPE, NADE_TYPE_EXPLO_BOMB)

        g_ExploBomb[owner]--
            
        fm_entity_set_model(entity, GRENADE_EXPLO_MODEL_W);       
        
        return FMRES_SUPERCEDE
    }
    else if(g_HolyBomb[owner] >= 1 && equal (model [7], "w_sm", 4))
    {   
        fm_set_rendering(entity, kRenderFxGlowShell, 001, 100, 200, kRenderNormal, 16)

        // And a colored trail
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_BEAMFOLLOW) // TE id
        write_short(entity) // entity
        write_short(g_trailSpr) // sprite
        write_byte(5) // life
        write_byte(5) // width
        write_byte(000) // r
        write_byte(100) // g
        write_byte(200) // b
        write_byte(200) // brightness
        message_end()

        set_pev(entity, PEV_NADE_TYPE, NADE_TYPE_HOLY_BOMB)

        g_HolyBomb[owner]--
            
        fm_entity_set_model(entity, GRENADE_HOLY_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_ExploBomb[id])   
        {       
            set_pev(id, pev_viewmodel2, GRENADE_EXPLO_MODEL_V)
            set_pev(id, pev_weaponmodel2, GRENADE_EXPLO_MODEL_P)
        }
        else if(g_HolyBomb[id])   
        {       
            set_pev(id, pev_viewmodel2, GRENADE_HOLY_MODEL_V)
            set_pev(id, pev_weaponmodel2, GRENADE_HOLY_MODEL_P)
        }       
    }   
    return   
}   

public fw_ThinkGrenade(entity)
{
    if(!pev_valid(entity))
        return HAM_IGNORED
        
    static Float:dmgtime   
    pev(entity, pev_dmgtime, dmgtime)
    
    if (dmgtime > get_gametime())
        return HAM_IGNORED   
    
    if(pev(entity, pev_flTimeStepSound) == NADE_TYPE_EXPLO_BOMB)
        explo_explode(entity)
    else if(pev(entity, pev_flTimeStepSound) == NADE_TYPE_HOLY_BOMB)
        holy_explode(entity)
        
    return HAM_SUPERCEDE
}

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])
    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 owner = 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, owner, flDamage, DMG_SONIC | DMG_NEVERGIB)
    }
    
    engfunc(EngFunc_RemoveEntity, entity)
}

public holy_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])
    write_short(g_exploSpr2)
    write_byte(20)
    write_byte(17)
    write_byte(0)
    message_end()
        
    emit_sound(entity, CHAN_WEAPON, GRENADE_HOLY_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);

    new owner = pev(entity, pev_owner)   
    
    static iVictim;
    iVictim = -1;
    
    new Float: vecVictimOrigin[3], Float: flDamage
    
    while ((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, vecOrigin, GRENADE_HOLY_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_HOLY_DMG * (1.0 - (get_distance_f(vecOrigin, vecVictimOrigin) / GRENADE_HOLY_RADIUS))
        
        ExecuteHamB(Ham_TakeDamage, iVictim, entity, owner, 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;
    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;
}
 
Сообщения
1,420
Реакции
2,511
Помог
58 раз(а)
Потому что обе гранаты считаются как дымовые: CSW_SMOKEGRENADE.
 
Сообщения
15
Реакции
2
Потому что обе гранаты считаются как дымовые: CSW_SMOKEGRENADE.
есть у меня fw_Item_Deploy_Post идет как:
Код:
RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "fw_Item_Deploy_Post", 1)
и в give_grenade(iPlayer)
Код:
if(g_AllocString_E||(g_AllocString_E=engfunc(EngFunc_AllocString,"weapon_smokegrenade")))
Как тогда правильно в этих местах кода изменить, чтобы было к примеру еще и weapon_hegrenade
 
Сообщения
1,420
Реакции
2,511
Помог
58 раз(а)

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу