Brandon Дата: Четверг, 07.06.2012, 00:55 | Сообщение # 1
Сообщения: 6
Награды: 0
Замечания:
how to make that functio work on a flash grenades instead of smoke grenades
#include <amxmodx> #include <cstrike> #include <engine> #include <fakemeta> #include <hamsandwich> #include <xs> #define PLUGIN "Head Hunter SmokeGrenade" #define AUTHOR "OT" #define VERSION "1.5" new const DMG_CS_BULLETS_KNIFE = (DMG_NEVERGIB | DMG_BULLET) #define OFFSET_LAST_HIT_GROUP 75 #define EV_INT_colisions EV_INT_iuser2 #define EV_ENT_target EV_ENT_euser2 #define EV_ENT_lasttarget EV_ENT_euser3 #define EV_FL_removetime EV_FL_dmgtime #define IMPACT_TIMES get_pcvar_num(pcv_impact_times) #define DISTANCE_SENSE get_pcvar_float(pcv_dist_sense_player) #define DISTANCE_CUT_HEAD get_pcvar_float(pcv_dist_cut_head) #define DISTANCE_CUT_OWNER_HEAD get_pcvar_float(pcv_dist_owner_head) #define EXTRA_VELOCITY get_pcvar_float(pcv_velocity_follow) #define EXTRA_VELOCITY_Z get_pcvar_float(pcv_velocity_follow_z) #define VELOCITY_ADD get_pcvar_float(pcv_velocity_add) #define VELOCITY_BORDER get_pcvar_float(pcv_velocity_border) #define VELOCITY_AIMFORHEAD get_pcvar_float(pcv_velocity_aimfhead) #define RETHINK_BLACK_OUT_TIME 0.02 #define REMOVE_TIME get_pcvar_float(pcv_removetime) #define RGB_R_COLOR get_pcvar_num(pcv_color_red) #define RGB_G_COLOR get_pcvar_num(pcv_color_green) #define RGB_B_COLOR get_pcvar_num(pcv_color_blue) new g_maxplayers new pcv_velocity_follow new pcv_velocity_follow_z new pcv_velocity_border new pcv_velocity_add new pcv_velocity_aimfhead new pcv_dist_sense_player new pcv_dist_owner_head new pcv_dist_cut_head new pcv_impact_times new pcv_color_red new pcv_color_green new pcv_color_blue new pcv_effects new pcv_ignore_friendly new pcv_ignore_owner new pcv_damage new pcv_removetime new spr_nadebits new spr_blood_drop new spr_blood_spray new spr_trail new spr_explosion new const nade_model[] = { //"w_hegrenade.mdl" //"w_flashbang.mdl" "w_smokegrenade.mdl" } public plugin_precache() { spr_nadebits = precache_model("models/chromegibs.mdl") spr_blood_drop = precache_model("sprites/blood.spr") spr_blood_spray = precache_model("sprites/bloodspray.spr") spr_trail = precache_model("sprites/laserbeam.spr") spr_explosion = precache_model("sprites/shockwave.spr") } public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_cvar("sm_headhunt_vs", VERSION, FCVAR_SPONLY | FCVAR_SERVER) pcv_dist_cut_head = register_cvar("smhdh_distance_head_cut", "100.0") pcv_dist_sense_player = register_cvar("smhdh_distance_sense", "400.0") pcv_dist_owner_head = register_cvar("smhdh_distance_owner_head_cut", "10.0") pcv_impact_times = register_cvar("smhdh_impact_times", "8") pcv_color_red = register_cvar("smhdh_color_red", "0") pcv_color_green = register_cvar("smhdh_color_green", "214") pcv_color_blue = register_cvar("smhdh_color_blue", "198") pcv_velocity_follow = register_cvar("smhdh_velocity_correction", "150.0") pcv_velocity_follow_z = register_cvar("smhdh_height_correction", "25.0") pcv_velocity_add = register_cvar("smhdh_velocity_add", "50.0") pcv_velocity_border = register_cvar("smhdh_velocity_border", "200.0") pcv_velocity_aimfhead = register_cvar("smhdh_velocity_aim_for_head", "800.0") pcv_damage = register_cvar("smhdh_hit_damage", "500.0") pcv_removetime = register_cvar("smhdh_remove_time", "60.0") pcv_ignore_friendly = register_cvar("smhdh_ignore_friendly", "1") pcv_ignore_owner = register_cvar("smhdh_ignore_owner", "1") pcv_effects = register_cvar("smhdh_effects", "1") RegisterHam(Ham_Think, "grenade", "fw_grenade_think") RegisterHam(Ham_Touch, "grenade", "fw_touch") register_forward(FM_SetModel, "fw_setmodel", 1) g_maxplayers = get_maxplayers() } public fw_setmodel(ent, model[]) { if (!pev_valid(ent)) { return FMRES_IGNORED } // Not yet thrown if (entity_get_float(ent, EV_FL_gravity) == 0.0) { return FMRES_IGNORED } if (contain(model, nade_model) == -1) return FMRES_IGNORED entity_set_int(ent, EV_INT_movetype, MOVETYPE_BOUNCEMISSILE) entity_set_int(ent, EV_INT_colisions, 0) entity_set_edict(ent, EV_ENT_target, 0) entity_set_size(ent, Float:{-2.0,-4.0,-2.0}, Float:{2.0, 4.0, 2.0}) new color[3] color[0] = RGB_R_COLOR color[1] = RGB_G_COLOR color[2] = RGB_B_COLOR set_rendering(ent, kRenderFxGlowShell, RGB_R_COLOR, RGB_G_COLOR, RGB_B_COLOR, kRenderTransTexture, 16) set_beamfollow(ent, 20, 10, color, 50) entity_set_float(ent, EV_FL_removetime, get_gametime() + REMOVE_TIME) return FMRES_IGNORED } public fw_grenade_think(ent) { if (entity_get_int(ent, EV_INT_movetype) != MOVETYPE_BOUNCEMISSILE) return HAM_IGNORED if (entity_get_float(ent, EV_FL_removetime) > get_gametime() + REMOVE_TIME) { entity_set_float(ent, EV_FL_removetime, get_gametime() + REMOVE_TIME) } new owner = pev(ent, pev_owner) new Float:origin[3] entity_get_vector(ent, EV_VEC_origin, origin) if (entity_get_float(ent, EV_FL_removetime) < get_gametime() || !is_user_connected(owner) || is_user_connecting(owner)) { clear_beamfollow(ent) entity_set_int(ent, EV_INT_flags, FL_KILLME) metal_gibs(origin) return HAM_SUPERCEDE } new team = _:cs_get_user_team(owner) new target, Float:velocity[3], oldtarget target = entity_get_edict(ent, EV_ENT_target) oldtarget = entity_get_edict(ent, EV_ENT_lasttarget) if (target == owner && get_pcvar_num(pcv_ignore_owner)) { target = 0 entity_set_edict(ent, EV_ENT_target, 0) } if (target == 0) { entity_get_vector(ent, EV_VEC_velocity, velocity) if (xs_vec_len(velocity) < VELOCITY_BORDER) { xs_vec_mul_scalar(velocity, xs_vec_len(velocity) + VELOCITY_ADD, velocity) entity_set_vector(ent, EV_VEC_velocity, velocity) } new i = -1, Float:distance = DISTANCE_SENSE, Float:junk[3], pcvar = get_pcvar_num(pcv_ignore_friendly), targetteam while ((i = find_ent_in_sphere(i, origin, distance))) { if (i > g_maxplayers) break if (i == owner) continue if (i == oldtarget) continue if (!is_user_connected(i) || is_user_connecting(i)) continue if (!is_user_alive(i)) continue targetteam = _:cs_get_user_team(i) if ((team != targetteam && targetteam != _:CS_TEAM_SPECTATOR && targetteam != _:CS_TEAM_UNASSIGNED) || (team == targetteam && !pcvar)) { static Float:o[3] entity_get_vector(i, EV_VEC_origin, o) entity_get_vector(i, EV_VEC_view_ofs, junk) xs_vec_add(o, junk, o) static Float:new_distance new_distance = get_distance_f(o, origin) if (new_distance < distance) { distance = new_distance entity_set_edict(ent, EV_ENT_target, i) } } } if (!get_pcvar_num(pcv_ignore_owner) && entity_range(owner, ent) < distance && entity_get_int(ent, EV_INT_colisions) > 0) { entity_set_edict(ent, EV_ENT_target, owner) } entity_set_float(ent, EV_FL_nextthink, get_gametime() + RETHINK_BLACK_OUT_TIME) return HAM_SUPERCEDE } else if (!is_user_alive(target)) { entity_get_vector(ent, EV_VEC_velocity, velocity) if (xs_vec_len(velocity) < VELOCITY_BORDER) { xs_vec_mul_scalar(velocity, xs_vec_len(velocity) + VELOCITY_ADD, velocity) entity_set_vector(ent, EV_VEC_velocity, velocity) } entity_set_edict(ent, EV_ENT_target, 0) entity_set_float(ent, EV_FL_nextthink, get_gametime() + RETHINK_BLACK_OUT_TIME) return HAM_SUPERCEDE } else { new Float:aim[3], Float:targetorigin[3], Float:velocity_normal[3], Float:aim_normal[3] entity_get_vector(target, EV_VEC_origin, targetorigin) xs_vec_add(targetorigin, Float:{0.0, 0.0, 30.0}, targetorigin) if (!is_point_visible(origin, targetorigin, ent)) { entity_set_edict(ent, EV_ENT_target, 0) entity_set_float(ent, EV_FL_nextthink, get_gametime() + RETHINK_BLACK_OUT_TIME) return HAM_SUPERCEDE } xs_vec_sub(targetorigin, origin, aim) if (xs_vec_len(aim) <= DISTANCE_CUT_HEAD) { xs_vec_mul_scalar(aim, VELOCITY_AIMFORHEAD/xs_vec_len(aim), aim) entity_set_vector(ent, EV_VEC_velocity, aim) if (target == owner && !get_pcvar_num(pcv_ignore_owner) && get_distance_f(targetorigin, origin) <= DISTANCE_CUT_OWNER_HEAD) { new Float:torigin[3] entity_get_vector(owner, EV_VEC_origin, torigin) blood(torigin) set_pdata_int(owner, OFFSET_LAST_HIT_GROUP, HIT_HEAD, 5) ExecuteHamB(Ham_TakeDamage, owner, ent, owner, get_pcvar_float(pcv_damage), DMG_CS_BULLETS_KNIFE) entity_set_edict(ent, EV_ENT_target, 0) entity_set_edict(ent, EV_ENT_lasttarget, owner) new color[3] , impacts color[0] = RGB_R_COLOR color[1] = RGB_G_COLOR color[2] = RGB_B_COLOR create_blast(origin, color) impacts = entity_get_int(ent, EV_INT_colisions) impacts++ entity_set_int(ent, EV_INT_colisions, impacts) if (impacts >= IMPACT_TIMES) { clear_beamfollow(ent) entity_set_int(ent, EV_INT_flags, FL_KILLME) metal_gibs(origin) } } entity_set_float(ent, EV_FL_nextthink, get_gametime() + RETHINK_BLACK_OUT_TIME) return HAM_SUPERCEDE } entity_get_vector(ent, EV_VEC_velocity, velocity) xs_vec_sub(targetorigin, origin, aim) xs_vec_normalize(velocity, velocity_normal) xs_vec_normalize(aim, aim_normal) if (xs_vec_len(velocity) < VELOCITY_BORDER) { xs_vec_mul_scalar(velocity, xs_vec_len(velocity) + VELOCITY_ADD, velocity) } if (xs_vec_dot(aim_normal, velocity_normal) < 0) { entity_set_edict(ent, EV_ENT_target, 0) entity_set_float(ent, EV_FL_nextthink, get_gametime() + RETHINK_BLACK_OUT_TIME) entity_set_vector(ent, EV_VEC_velocity, velocity) return HAM_SUPERCEDE } if (velocity_normal[0] < aim_normal[0]) { velocity[0] += EXTRA_VELOCITY } else if (velocity_normal[0] > aim_normal[0]) { velocity[0] -= EXTRA_VELOCITY } if (velocity_normal[1] < aim_normal[1]) { velocity[1] += EXTRA_VELOCITY } else if (velocity_normal[1] > aim_normal[1]) { velocity[1] -= EXTRA_VELOCITY } if (velocity_normal[2] < aim_normal[2]) { velocity[2] += EXTRA_VELOCITY_Z } else if (velocity_normal[2] > aim_normal[2]) { velocity[2] -= EXTRA_VELOCITY_Z } velocity[2] += 5.0 entity_set_vector(ent, EV_VEC_velocity, velocity) } entity_set_float(ent, EV_FL_nextthink, get_gametime() + RETHINK_BLACK_OUT_TIME) return HAM_SUPERCEDE } public fw_touch(toucher, touched) { if (entity_get_int(toucher, EV_INT_movetype) != MOVETYPE_BOUNCEMISSILE) return HAM_IGNORED new Float:origin[3] new impacts = entity_get_int(toucher, EV_INT_colisions) new owner = entity_get_edict(toucher, EV_ENT_owner) entity_get_vector(toucher, EV_VEC_origin, origin) if (1 <= touched <= g_maxplayers) { new CsTeams:team[2] team[0] = cs_get_user_team(touched) team[1] = cs_get_user_team(owner) if ((team[0] != team[1] && team[0] != CS_TEAM_SPECTATOR && team[0] != CS_TEAM_UNASSIGNED)|| (team[0] == team[1] && !get_pcvar_num(pcv_ignore_friendly))) { new Float:origin[3] entity_get_vector(touched, EV_VEC_origin, origin) blood(origin) set_pdata_int(touched, OFFSET_LAST_HIT_GROUP, HIT_HEAD, 5) ExecuteHamB(Ham_TakeDamage, touched, toucher, owner, get_pcvar_float(pcv_damage), DMG_CS_BULLETS_KNIFE) entity_set_edict(toucher, EV_ENT_target, 0) entity_set_edict(toucher, EV_ENT_lasttarget, touched) new color[3] color[0] = RGB_R_COLOR color[1] = RGB_G_COLOR color[2] = RGB_B_COLOR create_blast(origin, color) } } if (touched > g_maxplayers || touched == 0) { msg_ricochet(origin) } impacts++ entity_set_int(toucher, EV_INT_colisions, impacts) if (impacts >= IMPACT_TIMES) { clear_beamfollow(toucher) entity_set_int(toucher, EV_INT_flags, FL_KILLME) metal_gibs(origin) } return HAM_IGNORED } bool:is_point_visible(Float:start[3], Float:end[3], ignore_ent) { static ptr ptr = create_tr2() engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, ignore_ent, ptr) static Float:dist get_tr2(ptr, TR_flFraction, dist) free_tr2(ptr) return ((dist == 1.0) ? true : false) } metal_gibs(const Float: origin[3]) { if (!get_pcvar_num(pcv_effects)) return engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0) write_byte(TE_BREAKMODEL) // TE_BREAKMODEL engfunc(EngFunc_WriteCoord,origin[0]) // x engfunc(EngFunc_WriteCoord,origin[1]) // y engfunc(EngFunc_WriteCoord,origin[2] + 24) // z engfunc(EngFunc_WriteCoord,20.0) // size x engfunc(EngFunc_WriteCoord,20.0) // size y engfunc(EngFunc_WriteCoord,20.0) // size z engfunc(EngFunc_WriteCoord,random_num(-50,50)) // velocity x engfunc(EngFunc_WriteCoord,random_num(-50,50)) // velocity y engfunc(EngFunc_WriteCoord,25.0) // velocity z write_byte(10) // random velocity write_short(spr_nadebits) // model write_byte(10) // count write_byte(25) // life write_byte(2) // flags: BREAK_METAL message_end() } blood(const Float:origin[3]) { if (!get_pcvar_num(pcv_effects)) return engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0) write_byte(TE_BLOODSPRITE) engfunc(EngFunc_WriteCoord, origin[0]) engfunc(EngFunc_WriteCoord, origin[1]) engfunc(EngFunc_WriteCoord, origin[2] + 30.0) write_short(spr_blood_spray) write_short(spr_blood_drop) write_byte(248) // color index write_byte(15) // size message_end() } create_blast(Float:originF[3], rgb[3]) { if (!get_pcvar_num(pcv_effects)) return new origin[3] FVecIVec(originF,origin) // smallest ring message_begin(MSG_BROADCAST,SVC_TEMPENTITY) write_byte(TE_BEAMCYLINDER) write_coord(origin[0]) // x write_coord(origin[1]) // y write_coord(origin[2]) // z write_coord(origin[0]) // x axis write_coord(origin[1]) // y axis write_coord(origin[2] + 50) // z axis write_short(spr_explosion) // sprite write_byte(0) // start frame write_byte(0) // framerate write_byte(4) // life write_byte(60) // width write_byte(0) // noise write_byte(rgb[0]) // red write_byte(rgb[1]) // green write_byte(rgb[2]) // blue write_byte(100) // brightness write_byte(0) // speed message_end() } // give an entity a beam trail set_beamfollow(ent, life,width, rgb[3], brightness) { if (!get_pcvar_num(pcv_effects)) return message_begin(MSG_BROADCAST,SVC_TEMPENTITY) write_byte(TE_BEAMFOLLOW) write_short(ent) // entity write_short(spr_trail) // sprite write_byte(life) // life write_byte(width) // width write_byte(rgb[0]) // red write_byte(rgb[1]) // green write_byte(rgb[2]) // blue write_byte(brightness) // brightness message_end() } clear_beamfollow(ent) { if (!get_pcvar_num(pcv_effects)) return message_begin(MSG_ALL,SVC_TEMPENTITY) write_byte(TE_KILLBEAM) write_short(ent) // entity message_end() } msg_ricochet(Float:origin[3]) { if (!get_pcvar_num(pcv_effects)) return engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0) write_byte(TE_ARMOR_RICOCHET) engfunc(EngFunc_WriteCoord, origin[0]) engfunc(EngFunc_WriteCoord, origin[1]) engfunc(EngFunc_WriteCoord, origin[2]) write_byte(5) message_end() }