bizon,
C++:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>
new const g_DecalsShot[] = { 41, 42, 43, 44, 45 } // Декали
// Объекты для прорисовки декалей
new const g_ArrFunc[][] = { "worldspawn", "func_breakable", "func_wall",
"func_door", "func_door_rotating", "func_plat", "func_rotating"};
new g_WpnKeyCustom
#define CustomItem(%0) (get_entvar(%0, var_impulse) == g_WpnKeyCustom)
public plugin_init(){
register_forward(FM_UpdateClientData, "UpdateClientData", true);
// Решил использовать момент атаки, вроде как есть метод через TraceLine, но пока не разобрался с ним
for(new i = 0; i < sizeof(g_ArrFunc); i++){
RegisterHam(Ham_TraceAttack, g_ArrFunc[i], "TraceAttack", true);
}
register_forward(FM_PlaybackEvent, "PlayBackEvent"); // Событие для отдачи оружия
}
public UpdateClientData(const pPlayer, const SendWeapons, const CD){
static iItem; iItem = get_member(pPlayer, m_pActiveItem);
if(iItem <= 0 || !CustomItem(iItem) || !CD || !is_user_alive(pPlayer)){
return FMRES_IGNORED;
}
set_cd(CD, CD_flNextAttack, get_gametime() + 0.001);
return FMRES_HANDLED;
}
public PlayBackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
if (!(1 <= invoker <= MAX_CLIENTS)){
return FMRES_IGNORED;
}
playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
return FMRES_SUPERCEDE;
}
public TraceAttack(this, iAttacker, Float:flDamage, Float:direction[3], traceresult, damagebits)
{
if(!is_user_alive(iAttacker))
return;
static Float:flEnd[3]
get_tr2(traceresult, TR_vecEndPos, flEnd)
if(this){
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_DECAL)
write_coord_f(flEnd[0])
write_coord_f(flEnd[1])
write_coord_f(flEnd[2])
write_byte(g_DecalsShot[random_num (0, sizeof(g_DecalsShot) -1)])
write_short(this)
message_end()
}else{
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_WORLDDECAL)
write_coord_f(flEnd[0])
write_coord_f(flEnd[1])
write_coord_f(flEnd[2])
write_byte(g_DecalsShot[random_num (0, sizeof(g_DecalsShot) -1)])
message_end()
}
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_GUNSHOTDECAL)
write_coord_f(flEnd[0])
write_coord_f(flEnd[1])
write_coord_f(flEnd[2])
write_short(iAttacker)
write_byte(g_DecalsShot[random_num (0, sizeof(g_DecalsShot) -1)])
message_end()
}