Вопрос по выстрелу

Сообщения
21
Реакции
1
Здравствуйте, хотел бы спросить как заблокировать анимацию выстрела при зажатой кнопки
C++:
#include <amxmodx>
#include <fun>
#include <fakemeta>
#include <hamsandwich>
#include <engine>

//#define ZOMBIE

#if defined ZOMBIE
#include <zombieplague>
#endif

#define WEAPON_KEY 20144

#define WEAPON_OLD "weapon_deagle"         
#define WEAPON_CSW CSW_DEAGLE
#define WEAPON_EVENT "events/deagle.sc"
#define WEAPON_W "models/w_deagle.mdl"

//Cмотреть в HLMV
#define TIME_DRAW 1.5    //Достования
#define TIME_RELOAD 3.0  //Перезарядка
#define TIME_SHOOT 1.0   //Выстрел
#define TIME_IDLE 1.5    //Простой

#define SOUND_SHOOT "weapons/m14ebr.wav"
#define MODEL_SHELL "models/rshell.mdl"
#define MODEL_V "models/zombieplague/weapons/pistol/kopter/v_kopter.mdl"  //Модель оружия в руках
#define MODEL_P "models/zombieplague/weapons/pistol/kopter/p_kopter.mdl"  //Модель оружия в руках модели игрока
#define MODEL_W "models/zombieplague/weapons/pistol/kopter/w_kopter.mdl"  //Модель оружия на земле

const AMMO_CLIP = 7
const AMMO_MAX = 120
const Float:DAMAGE = 1.0
const Float:SPEED = 0.15
const Float:RECOIL = 1.0

enum
{
    IDLE = 0,
    SHOOT1,
    SHOOT2,
    SHOOT_EMPTY,
    RELOAD,
    DRAW
}

new const trace_attack[][] =
{
    "func_breakable",
    "func_wall",
    "func_door",
    "func_plat",
    "func_rotating",
    "worldspawn"
}

new const damage_entity[][] =
{
    "player",
    "func_breakable",
    "hostage_entity"
}

#define get_weapon(%0)   (entity_get_int(%0, EV_INT_impulse) == WEAPON_KEY)
#define set_weapon(%0)   entity_set_int(%0, EV_INT_impulse, WEAPON_KEY)

new g_connect

#define get_bit(%1,%2)   ((%1 & (1 << (%2 & 31))) ? true : false)
#define set_bit(%1,%2)     %1 |= (1 << (%2 & 31))
#define reset_bit(%1,%2) %1 &= ~(1 << (%2 & 31))

const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)

new g_weapon_new[33]
new g_origin_event_weapon, g_shell_index, g_IsInPrimaryAttack

#if defined ZOMBIE
new const item_name[] = "New Weapon"
const item_cost = 5             
new g_item
#endif

public plugin_init()
{
       register_plugin("[Z] Weapon New", "1.0", "batcon")

       RegisterHam(Ham_Item_Deploy, WEAPON_OLD, "Ham_Item_Deploy_Post", 1)
       RegisterHam(Ham_Weapon_Reload, WEAPON_OLD, "Ham_Weapon_Reload")
       RegisterHam(Ham_Item_PostFrame, WEAPON_OLD, "Ham_Item_PostFrame")
       RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_OLD, "Ham_Weapon_PrimaryAttack")
       RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_OLD, "Ham_Weapon_PrimaryAttack_Post", 1)
       RegisterHam(Ham_Item_AddToPlayer, WEAPON_OLD, "Ham_Item_AddToPlayer_Post", 1)
       RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_OLD, "Ham_Weapon_WeaponIdle")
      
       static i

       for(i = 0 ;i < sizeof trace_attack; i++)
       {
                   RegisterHam(Ham_TraceAttack, trace_attack[i], "Ham_TraceAttack_Post", 1)
       }

       for(i = 0 ;i < sizeof damage_entity; i++)
       {
                   RegisterHam(Ham_TraceAttack, damage_entity[i], "Ham_TraceAttack_Pre")   
       }

       register_forward(FM_PlaybackEvent, "FM_PlaybackEvent")
       register_forward(FM_UpdateClientData, "FM_UpdateClientData_Post", 1)
       register_forward(FM_SetModel, "FM_SetModel")

       #if defined ZOMBIE
       g_item = zp_register_extra_item(item_name, item_cost, ZP_TEAM_HUMAN)
       #endif

       register_clcmd("say test", "give_weapon")
}

public plugin_precache()
{
       precache_model(MODEL_V)
       precache_model(MODEL_P)
       precache_model(MODEL_W)

       precache_sound(SOUND_SHOOT)
       g_shell_index = precache_model(MODEL_SHELL)

       register_forward(FM_PrecacheEvent, "FM_PrecacheEvent_Post", 1)
}

#if defined ZOMBIE
public zp_extra_item_selected(id, item)
{
       if(item == g_item)
       {
              give_weapon(id)
       }
}

public zp_user_infected_post(id)
{
       g_weapon_new[id] = false
}
#endif

public weapon_hook(id)
{
       engclient_cmd(id, WEAPON_OLD)
       return PLUGIN_HANDLED
}

public client_putinserver(id)
{
       set_bit(g_connect, id)
}

public client_disconnected(id)
{
       g_weapon_new[id] = false
}

public FM_PrecacheEvent_Post(type, name[])
{
       if(equal(WEAPON_EVENT, name))
       {
                g_origin_event_weapon = get_orig_retval()
                return FMRES_HANDLED
       }

       return FMRES_IGNORED
}

public FM_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
       if(eventid != g_origin_event_weapon || !g_IsInPrimaryAttack)
       return FMRES_IGNORED

       if(!(1 < invoker <= get_maxplayers()))
       return FMRES_IGNORED

       playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
       return FMRES_SUPERCEDE
}

public FM_UpdateClientData_Post(id, SendWeapons, CD_Handle)
{
       if(!is_user_alive(id))
       return FMRES_IGNORED

       static item; item = get_player_item(id)
    
       if(!get_weapon(item))
       return FMRES_IGNORED

       set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001)
       return FMRES_HANDLED
}

public give_weapon(id)
{
       drop_weapons(id, 1)

       g_weapon_new[id] = true
       static weapon; weapon = give_item(id, WEAPON_OLD)
       set_weapon(weapon)
       set_ammo_clip(weapon, AMMO_CLIP)
       set_ammo(id, AMMO_MAX, WEAPON_CSW)
       entity_set_string(id, EV_SZ_viewmodel, MODEL_V)
       entity_set_string(id, EV_SZ_weaponmodel, MODEL_P)
       UTIL_PlayWeaponAnimation(id, DRAW)
       set_next_attack(id, TIME_DRAW)
}

public Ham_Item_Deploy_Post(weapon_ent)
{
       if(!is_valid_ent(weapon_ent))
       return HAM_IGNORED

       static id; id = get_player(weapon_ent)

       if(!g_weapon_new[id])
       return HAM_IGNORED
      
       entity_set_string(id, EV_SZ_viewmodel, MODEL_V)
       entity_set_string(id, EV_SZ_weaponmodel, MODEL_P)
       UTIL_PlayWeaponAnimation(id, DRAW)
       set_next_attack(id, TIME_DRAW)

       return HAM_IGNORED
}

public Ham_Weapon_Reload(weapon_ent)
{
       if(!is_valid_ent(weapon_ent))
       return HAM_IGNORED

       static id, clip
       id = get_player(weapon_ent)

       if(!g_weapon_new[id])
       return HAM_IGNORED

       if(get_ammo(id, WEAPON_CSW) <= 0 || get_ammo_clip(weapon_ent) >= AMMO_CLIP)
       return HAM_SUPERCEDE

       clip = get_ammo_clip(weapon_ent)

       set_ammo_clip(weapon_ent, 0)
       ExecuteHam(Ham_Weapon_Reload, weapon_ent)
       set_ammo_clip(weapon_ent, clip)

       UTIL_PlayWeaponAnimation(id, RELOAD)
       set_next_attack(id, TIME_RELOAD)
       set_next_idle(weapon_ent, TIME_RELOAD)

       return HAM_SUPERCEDE
}

public Ham_Item_PostFrame(weapon_ent)
{
       if(!is_valid_ent(weapon_ent))
       return HAM_IGNORED

       static id; id = get_player(weapon_ent)
       static ammo; ammo = get_ammo(id, WEAPON_CSW)
       static clip; clip = get_ammo_clip(weapon_ent)     
       static Float:NextAttack, Reload

       if(!g_weapon_new[id])
       return HAM_IGNORED

       NextAttack = get_pdata_float(id, 83, 5)
       Reload = get_pdata_int(weapon_ent, 54, 4)

       if(Reload && NextAttack <= 0.0)
       {
             static old; old = min(AMMO_CLIP - clip, ammo) 

             set_ammo_clip(weapon_ent, clip + old)
             set_ammo(id, ammo - old, WEAPON_CSW)

             set_pdata_int(weapon_ent, 54, 0, 4)
             Reload = 0
       }

       return HAM_IGNORED
}

public Ham_Weapon_PrimaryAttack_Post(weapon_ent)
{
        g_IsInPrimaryAttack = 1
       if(!is_valid_ent(weapon_ent))
       return HAM_IGNORED

       static id; id = get_player(weapon_ent)

        if(!g_weapon_new[id])
       return HAM_IGNORED

       if(get_ammo_clip(weapon_ent) == 0)
       return HAM_IGNORED

       ExecuteHam(Ham_Weapon_PrimaryAttack, weapon_ent)

       emit_sound(id, CHAN_WEAPON, SOUND_SHOOT, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
       set_weapon_reloil(weapon_ent, RECOIL)
       UTIL_PlayWeaponAnimation(id, random_num(SHOOT1, SHOOT2))
       set_next_attack(id, SPEED)
       set_next_idle(weapon_ent, TIME_SHOOT)
       create_shell(weapon_ent, id, g_shell_index)

       return HAM_SUPERCEDE
}

public Ham_Weapon_WeaponIdle(weapon_ent)
{
       if(!is_valid_ent(weapon_ent))
       return HAM_IGNORED

       static id, Float:time_idle
       id = get_player(weapon_ent)

       if(!g_weapon_new[id])
       return HAM_IGNORED

       time_idle = get_pdata_float(weapon_ent, 48, 4)   

       if(time_idle > 0.0)
       return HAM_IGNORED

       UTIL_PlayWeaponAnimation(id, IDLE)

       set_next_idle(weapon_ent, TIME_IDLE)

       return HAM_SUPERCEDE
}

public Ham_Item_AddToPlayer_Post(weapon_ent, id)
{
       if(!is_valid_ent(weapon_ent))
       return HAM_IGNORED

       if(get_weapon(weapon_ent))
       {
              g_weapon_new[id] = true
              return HAM_HANDLED
       }

       return HAM_IGNORED
}

public Ham_TraceAttack_Post(entity, attacker, Float:damage, Float:fDir[3], ptr, damagetype)
{
       static item; item = get_player_item(attacker)

       if(!get_weapon(item))
       return HAM_HANDLED
    
       new Float:vecEnd[3]
  
       get_tr2(ptr, TR_vecEndPos, vecEnd);

       message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
       write_byte(TE_GUNSHOTDECAL)
       engfunc(EngFunc_WriteCoord, vecEnd[0])
       engfunc(EngFunc_WriteCoord, vecEnd[1])
       engfunc(EngFunc_WriteCoord, vecEnd[2])
       write_short(entity)
       write_byte(random_num(41, 45))
       message_end()

       return HAM_IGNORED
}

public Ham_TraceAttack(entity, attacker, Float:damage)
{
       if(get_bit(g_connect, attacker))
       {
                if(get_user_weapon(attacker) == WEAPON_CSW && g_weapon_new[attacker])
                {
                         SetHamParamFloat(3, damage * DAMAGE)
                         return HAM_IGNORED
                }
       }
       return HAM_IGNORED
}

public FM_SetModel(entity, model[])
{
       if(!is_valid_ent(entity))
       return FMRES_IGNORED
    
       static szClassName[33]
       entity_get_string(entity, EV_SZ_classname, szClassName, charsmax(szClassName))
        
       if(!equal(szClassName, "weaponbox"))
       return FMRES_IGNORED
    
       static id; id = entity_get_edict(entity, EV_ENT_owner)
    
       if(equal(model, WEAPON_W))
       {
        static iStoredAugID; iStoredAugID = find_ent_by_owner(-1, WEAPON_OLD, entity)
    
        if(!is_valid_ent(iStoredAugID))
        return FMRES_IGNORED
    
        if(g_weapon_new[id])
        {           
            entity_set_model(entity, MODEL_W)
                        g_weapon_new[id] = false

            return FMRES_SUPERCEDE
        }
       }

       return FMRES_IGNORED
}

stock set_ammo_clip(weapon, amount)
{
      set_pdata_int(weapon, 51, amount, 4)
}

set_ammo(const player, const amount, const ammo_type)
{
        if(amount == -1)
        {
              return 0
        }

        switch(ammo_type)
        {
              case CSW_AWP: set_pdata_int(player, 377, amount, 5)
              case CSW_SCOUT: set_pdata_int(player, 378, amount, 5)
              case CSW_G3SG1: set_pdata_int(player, 378, amount, 5)
              case CSW_AK47: set_pdata_int(player, 378, amount, 5)
              case CSW_M249: set_pdata_int(player, 379, amount, 5)
              case CSW_M4A1: set_pdata_int(player, 380, amount, 5)
              case CSW_FAMAS: set_pdata_int(player, 380, amount, 5)
              case CSW_AUG: set_pdata_int(player, 380, amount, 5)
              case CSW_SG550: set_pdata_int(player, 380, amount, 5)
              case CSW_GALIL: set_pdata_int(player, 380, amount, 5)
              case CSW_SG552: set_pdata_int(player, 380, amount, 5)
              case CSW_M3: set_pdata_int(player, 381, amount, 5)
              case CSW_XM1014: set_pdata_int(player, 381, amount, 5)
              case CSW_USP: set_pdata_int(player, 382, amount, 5)
              case CSW_UMP45: set_pdata_int(player, 382, amount, 5)
              case CSW_MAC10: set_pdata_int(player, 382, amount, 5)
              case CSW_FIVESEVEN: set_pdata_int(player, 383, amount, 5)
              case CSW_P90: set_pdata_int(player, 383, amount, 5)
              case CSW_DEAGLE: set_pdata_int(player, 384, amount, 5)
              case CSW_P228: set_pdata_int(player, 385, amount, 5)
              case CSW_GLOCK18: set_pdata_int(player, 386, amount, 5)
              case CSW_TMP: set_pdata_int(player, 386, amount, 5)
              case CSW_ELITE: set_pdata_int(player, 386, amount, 5)
        }
        return 1
}

get_ammo(const player, const ammo_type)
{
        switch(ammo_type)
        {
              case CSW_AWP: return get_pdata_int(player, 377, 5)
              case CSW_SCOUT: return get_pdata_int(player, 378, 5)
              case CSW_G3SG1: return get_pdata_int(player, 378, 5)
              case CSW_AK47: return get_pdata_int(player, 378, 5)
              case CSW_M249: return get_pdata_int(player, 379, 5)
              case CSW_M4A1: return get_pdata_int(player, 380, 5)
              case CSW_FAMAS: return get_pdata_int(player, 380, 5)
              case CSW_AUG: return get_pdata_int(player, 380, 5)
              case CSW_SG550: return get_pdata_int(player, 380, 5)
              case CSW_GALIL: return get_pdata_int(player, 380, 5)
              case CSW_SG552: return get_pdata_int(player, 380, 5)
              case CSW_M3: return get_pdata_int(player, 381, 5)
              case CSW_XM1014: return get_pdata_int(player, 381, 5)
              case CSW_USP: return get_pdata_int(player, 382, 5)
              case CSW_UMP45: return get_pdata_int(player, 382, 5)
              case CSW_MAC10: return get_pdata_int(player, 382, 5)
              case CSW_FIVESEVEN: return get_pdata_int(player, 383, 5)
              case CSW_P90: return get_pdata_int(player, 383, 5)
              case CSW_DEAGLE: return get_pdata_int(player, 384, 5)
              case CSW_P228: return get_pdata_int(player, 385, 5)
              case CSW_GLOCK18: return get_pdata_int(player, 386, 5)
              case CSW_TMP: return get_pdata_int(player, 386, 5)
              case CSW_ELITE: return get_pdata_int(player, 386, 5)
        }
        return 1
}

stock get_ammo_clip(weapon)
{
      return get_pdata_int(weapon, 51, 4)
}

stock get_player(weapon)
{
      return get_pdata_cbase(weapon, 41, 4)
}

stock get_player_item(player)
{
      return get_pdata_cbase(player, 373, 5)
}

stock set_next_attack(player, Float:time)
{
      set_pdata_float(player, 83, time, 5)
}

stock set_next_idle(weapon, Float:time)
{
      set_pdata_float(weapon, 48, time, 4)
}

stock set_weapon_reloil(weapon, Float:recoil)
{
      set_pdata_float(weapon, 62, recoil, 4)
}

stock create_shell(weapon, player, shell_index)
{
      set_pdata_int(weapon, 57, shell_index, 4)
      set_pdata_float(player, 111, get_gametime())
}

stock UTIL_PlayWeaponAnimation(const Player, const Sequence)
{
      entity_set_int(Player, EV_INT_weaponanim, Sequence)
    
      message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = Player)
      write_byte(Sequence)
      write_byte(0)
      message_end()
}

stock drop_weapons(player, dropwhat)
{
     static weapons[32], num, i, weaponid
     num = 0
     get_user_weapons(player, weapons, num)
    
     for (i = 0; i < num; i++)
     {
          weaponid = weapons[i]
          
          if (dropwhat == 1 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM))
          {
               static wname[32]
               get_weaponname(weaponid, wname, sizeof wname - 1)
               engclient_cmd(player, "drop", wname)
          }
     }
}
 
Сообщения
1,420
Реакции
2,511
Помог
58 раз(а)
Возможно хукать Ham_CS_Weapon_SendWeaponAnim? Хотя это по сути замена анимации, не уверен что можно убрать анимацию вообще через этот хук. Нужно чтобы оружие стреляло и не было никакой анимации?
 
Сообщения
2,491
Реакции
2,794
Помог
61 раз(а)
MurJonyBoy, а Ham_Weapon_PrimaryAttack_Post тут разве не должно быть Pre хук? Вы юлочите выстрел в посте, что уже поздно делать
 

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

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