#include #include #include #include new bool: g_NpcSpawn[256]; new bool: g_NpcDead[256]; new const g_NpcClassName[] = "ent_npc"; new const g_NpcModel[] = "models/kzb/npc.mdl"; new const g_NpcSoundPain[][] = { "barney/ba_pain1.wav", "barney/ba_pain2.wav", "barney/ba_pain3.wav" } new const g_NpcSoundDeath[][] = { "barney/ba_die1.wav", "barney/ba_die2.wav", "barney/ba_die3.wav" } new const NPC_IdleAnimations[] = { 0, 1, 2, 3, 11, 12, 18, 21, 39, 63, 65 }; new spr_blood_drop, spr_blood_spray public plugin_init() { register_plugin("NPC Plugin", "1.0", "Mazza"); register_clcmd("amx_npc", "clcmd_npc"); RegisterHam(Ham_TakeDamage, "info_target", "npc_TakeDamage"); RegisterHam(Ham_Killed, "info_target", "npc_Killed"); RegisterHam(Ham_Think, "info_target", "npc_Think"); RegisterHam(Ham_TraceAttack, "info_target", "npc_TraceAttack"); } public plugin_precache() { spr_blood_drop = precache_model("sprites/blood.spr") spr_blood_spray = precache_model("sprites/bloodspray.spr") new i; for(i = 0 ; i < sizeof g_NpcSoundPain ; i++) precache_sound(g_NpcSoundPain[i]); for(i = 0 ; i < sizeof g_NpcSoundDeath ; i++) precache_sound(g_NpcSoundDeath[i]); precache_model(g_NpcModel) } public clcmd_npc(id) { new ent = create_entity("info_target"); entity_set_string(ent, EV_SZ_classname, g_NpcClassName); entity_set_string(ent, EV_SZ_netname, "Barney"); new Float: origin[3], Float: angle[3]; entity_get_vector(id, EV_VEC_origin, origin); entity_set_origin(ent, origin); origin[2] += 80.0; entity_set_origin(id, origin); entity_get_vector(id, EV_VEC_angles, angle); angle[0] = 0.0; entity_set_vector(ent, EV_VEC_angles, angle); entity_set_float(ent, EV_FL_takedamage, 1.0); entity_set_float(ent, EV_FL_health, 250.0); entity_set_model(ent, g_NpcModel); entity_set_int(ent, EV_INT_movetype, MOVETYPE_PUSHSTEP); entity_set_int(ent, EV_INT_solid, SOLID_BBOX); new Float: mins[3] = {-12.0, -12.0, 0.0 } new Float: maxs[3] = { 12.0, 12.0, 75.0 } entity_set_size(ent, mins, maxs); entity_set_byte(ent,EV_BYTE_controller1,125); // entity_set_byte(ent,EV_BYTE_controller2,125); // entity_set_byte(ent,EV_BYTE_controller3,125); // entity_set_byte(ent,EV_BYTE_controller4,125); drop_to_floor(ent); // set_rendering( ent, kRenderFxDistort, 0, 0, 0, kRenderTransAdd, 127 ); g_NpcSpawn[ent] = true; g_NpcDead[ent] = false; entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.01) } public npc_TakeDamage(iEnt, inflictor, attacker, Float:damage, bits) { new className[32]; entity_get_string(iEnt, EV_SZ_classname, className, charsmax(className)) if(!equali(className, g_NpcClassName)) return; // entity_set_float(iEnt,EV_FL_animtime,get_gametime()) // entity_set_float(iEnt,EV_FL_framerate, 1.0) // entity_set_int(iEnt, EV_INT_sequence, random_num(13, 17) ); Util_PlayAnimation(iEnt, random_num(13, 17), 1.25); emit_sound(iEnt, CHAN_VOICE, g_NpcSoundPain[random(sizeof g_NpcSoundPain)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM) } public npc_Killed(iEnt) { new className[32]; entity_get_string(iEnt, EV_SZ_classname, className, charsmax(className)) if(!equali(className, g_NpcClassName)) return HAM_IGNORED; // entity_set_float(iEnt,EV_FL_animtime,get_gametime()); // entity_set_float(iEnt,EV_FL_framerate, 1.0); // entity_set_int(iEnt, EV_INT_sequence, random_num(25, 30) ); Util_PlayAnimation(iEnt, random_num(25, 30)) entity_set_int(iEnt, EV_INT_solid, SOLID_NOT); emit_sound(iEnt, CHAN_VOICE, g_NpcSoundDeath[random(sizeof g_NpcSoundDeath)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM) g_NpcDead[iEnt] = true; return HAM_SUPERCEDE } public npc_Think(iEnt) { if(!is_valid_ent(iEnt)) return; static className[32]; entity_get_string(iEnt, EV_SZ_classname, className, charsmax(className)) if(!equali(className, g_NpcClassName)) return; if(g_NpcDead[iEnt]) return; if(g_NpcSpawn[iEnt]) { static Float: mins[3], Float: maxs[3]; pev(iEnt, pev_absmin, mins); pev(iEnt, pev_absmax, maxs); message_begin(MSG_BROADCAST, SVC_TEMPENTITY) write_byte(TE_BOX) engfunc(EngFunc_WriteCoord, mins[0]) engfunc(EngFunc_WriteCoord, mins[1]) engfunc(EngFunc_WriteCoord, mins[2]) engfunc(EngFunc_WriteCoord, maxs[0]) engfunc(EngFunc_WriteCoord, maxs[1]) engfunc(EngFunc_WriteCoord, maxs[2]) write_short(100) write_byte(random_num(25, 255)) write_byte(random_num(25, 255)) write_byte(random_num(25, 255)) message_end(); g_NpcSpawn[iEnt] = false; } // entity_set_float(iEnt,EV_FL_animtime, get_gametime()) // entity_set_float(iEnt,EV_FL_framerate, 1.0) // entity_set_int(iEnt,EV_INT_sequence, NPC_IdleAnimations[random(sizeof NPC_IdleAnimations)]); Util_PlayAnimation(iEnt, NPC_IdleAnimations[random(sizeof NPC_IdleAnimations)]); entity_set_float(iEnt, EV_FL_nextthink, get_gametime() + random_float(5.0, 10.0)); } public npc_TraceAttack(iEnt, attacker, Float: damage, Float: direction[3], trace, damageBits) { if(!is_valid_ent(iEnt)) return; new className[32]; entity_get_string(iEnt, EV_SZ_classname, className, charsmax(className)) if(!equali(className, g_NpcClassName)) return; new Float: end[3] get_tr2(trace, TR_vecEndPos, end); message_begin(MSG_BROADCAST,SVC_TEMPENTITY) write_byte(TE_BLOODSPRITE) engfunc(EngFunc_WriteCoord, end[0]) engfunc(EngFunc_WriteCoord, end[1]) engfunc(EngFunc_WriteCoord, end[2]) write_short(spr_blood_spray) write_short(spr_blood_drop) write_byte(247) // color index write_byte(random_num(1, 5)) // size message_end() // message_begin(MSG_BROADCAST,SVC_TEMPENTITY) // write_byte(TE_SPARKS) // engfunc(EngFunc_WriteCoord, end[0]) // engfunc(EngFunc_WriteCoord, end[1]) // engfunc(EngFunc_WriteCoord, end[2]) // message_end() } stock Util_PlayAnimation(index, sequence, Float: framerate = 1.0) { entity_set_float(index, EV_FL_animtime, get_gametime()); entity_set_float(index, EV_FL_framerate, framerate); entity_set_float(index, EV_FL_frame, 0.0); entity_set_int(index, EV_INT_sequence, sequence); }