Senior Member
Join Date: Aug 2009
Location: Bulgaria
|
09-11-2010
, 12:20
Re: Improving WeaponMod
|
#29
|
Check this out:
PHP Code:
#include <amxmodx> #include <fakemeta> #include <weaponmod> #include <weaponmod_stocks> #include <wmodimprov>
#define PLUGIN "HK 417 Sniper" #define VERSION "1.0" #define AUTHOR "SeriousSamBG"
// Weapon information new WPN_NAME[] = "HK 417 Sniper"; new WPN_SHORT[] = "hk417";
// Model information new P_MODEL[] = "models/CS17/p_hk417.mdl"; new V_MODEL[] = "models/CS17/v_hk417.mdl"; new W_MODEL[] = "models/CS17/w_hk417.mdl";
new s_FIRE_1[] = "weapons/CS17/hk417-fire.wav"; new s_ZOOM[] = "weapons/zoom.wav";
// Weapon's defines #define RELOAD_TIME 3.0 #define RECOIL1 16.0 #define REFIRE1_RATE 0.25 #define REFIRE2_RATE 0.06 #define RUN_SPEED 210.0 #define CLIP_AMMO 20 #define TOTAL_AMMO 100 #define WPN_COST 5500 #define BULLET_PER_SHOT 1 #define DMG_PER_BULLET_MAX 77 #define DMG_PER_BULLET_MIN 74 #define ACCURACY 2.0 #define ACCURACY_MIN 0.2 #define ARMOR_PENETRATION 1.21 #define DISTANCE_MULTIPLIER 1.16
// Sequences enum { anim_idle_unsil, anim_shoot1_unsil, anim_shoot2_unsil, anim_reload_unsil, anim_deploy_unsup }
// Variables new g_wpnid; new g_MaxPlayers; new Float:gtime[33] = 0.0; new g_ZoomACT[33]; new g_ZoomPercent[33]; new ponter[33]; new Float:prev_shots[8][33];
public plugin_precache() { precache_model(P_MODEL); precache_model(V_MODEL); precache_model(W_MODEL); precache_sound(s_FIRE_1); precache_sound(s_ZOOM); }
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR); create_weapon(); }
create_weapon() { new wpnid = wpn_register_weapon(WPN_NAME,WPN_SHORT); if(!wpnid) return PLUGIN_CONTINUE; wpn_set_string(wpnid, wpn_viewmodel, V_MODEL); wpn_set_string(wpnid, wpn_weaponmodel, P_MODEL); wpn_set_string(wpnid, wpn_worldmodel, W_MODEL); wpn_register_event(wpnid, event_attack1, "ev_attack1"); wpn_register_event(wpnid, event_attack2, "ev_attack2"); wpn_register_event(wpnid, event_draw, "ev_draw"); wpn_register_event(wpnid, event_reload, "ev_reload"); wpn_set_float(wpnid, wpn_refire_rate1, REFIRE1_RATE); wpn_set_float(wpnid, wpn_refire_rate2, REFIRE2_RATE); wpn_set_float(wpnid, wpn_reload_time, RELOAD_TIME); wpn_set_float(wpnid, wpn_run_speed, RUN_SPEED); wpn_set_integer(wpnid, wpn_ammo1, CLIP_AMMO); wpn_set_integer(wpnid, wpn_ammo2, TOTAL_AMMO); wpn_set_integer(wpnid, wpn_bullets_per_shot1, BULLET_PER_SHOT); wpn_set_integer(wpnid, wpn_bullets_per_shot2, 0); wpn_set_integer(wpnid, wpn_cost, WPN_COST); g_wpnid = wpnid; return PLUGIN_CONTINUE; }
public ev_attack1(id) { if (gtime[id] < (get_gametime() - 0.5)) { wpn_playanim(id, random_num(anim_shoot1_unsil, anim_shoot2_unsil)); emit_sound(id, CHAN_WEAPON, s_FIRE_1, 1.0, ATTN_NORM, 0, PITCH_NORM); if (g_ZoomACT[id] == 0) { wpn_bullet_shot2(g_wpnid, id, 0,random_num(DMG_PER_BULLET_MIN, DMG_PER_BULLET_MAX),ACCURACY, ACCURACY_MIN*6, ARMOR_PENETRATION, DISTANCE_MULTIPLIER); custom_recoil(id); client_cmd(id, "-attack"); } else { wpn_bullet_shot2(g_wpnid, id, 0,random_num(DMG_PER_BULLET_MIN, DMG_PER_BULLET_MAX),ACCURACY, ACCURACY_MIN, ARMOR_PENETRATION, DISTANCE_MULTIPLIER); custom_recoil(id); client_cmd(id, "-attack"); } } else { new usrwpn = wpn_has_weapon(id,g_wpnid); wpn_set_userinfo(id,usr_wpn_ammo1,usrwpn,wpn_get_userinfo(id,usr_wpn_ammo1,usrwpn)+1); } return PLUGIN_CONTINUE; }
public ev_attack2(id) { if(((g_ZoomACT[id]==0) || (g_ZoomACT[id]==1)) && (g_ZoomPercent[id] > 18)) { g_ZoomPercent[id] = (g_ZoomPercent[id] <= 18) ? 18 : g_ZoomPercent[id]-3; wpn_set_user_zoom(id, g_ZoomPercent[id]); ShowZoomPercent(id); emit_sound(id, CHAN_WEAPON, s_ZOOM, 1.0, ATTN_NORM, 0, PITCH_NORM); g_ZoomACT[id] = 1; } else if((g_ZoomACT[id]==1) && (g_ZoomPercent[id] <= 18)) { g_ZoomACT[id] = 2; emit_sound(id, CHAN_WEAPON, s_ZOOM, 1.0, ATTN_NORM, 0, PITCH_NORM); client_cmd(id, "-attack2"); } else { emit_sound(id, CHAN_WEAPON, s_ZOOM, 1.0, ATTN_NORM, 0, PITCH_NORM); wpn_set_user_zoom(id, 90); ShowNoZoomPercent(id); g_ZoomACT[id] = 0; g_ZoomPercent[id] = 45; client_cmd(id, "-attack2"); } return PLUGIN_CONTINUE; }
ShowZoomPercent(id) { new zoom[51]; formatex(zoom, 50, "Zoom: %.1fx", 90.0/float(g_ZoomPercent[id]));
message_begin(MSG_ONE, get_user_msgid("StatusText"), {0,0,0}, id); write_byte(0); write_string(zoom); message_end(); }
ShowNoZoomPercent(id) { message_begin(MSG_ONE, get_user_msgid("StatusText"), {0,0,0}, id); write_byte(0); message_end(); }
custom_recoil(id) { static Float:recoil[3]; static Float:ctime; static Float:hk_recoil[33]; static indx; static shotsCount[33]; ctime = get_gametime(); if(ponter[id] == 8) ponter[id] = 0; prev_shots[ponter[id]++][id] = ctime; shotsCount[id] = 0; for (indx = 0; indx < 8; ++ indx) { if (prev_shots[indx][id] == 0.0) break; if (prev_shots[indx][id] > (ctime - 1.0)) ++shotsCount[id]; } hk_recoil[id] = RECOIL1*(shotsCount[id]/8.0); recoil[0] = -hk_recoil[id]; // up - down recoil[1] = random_float(hk_recoil[id]/4.0, - (hk_recoil[id]/4.0)); // right - left recoil[2] = 0.0; // Screen rotation set_pev(id, pev_punchangle, recoil); }
public ev_draw(id) { wpn_playanim(id, anim_deploy_unsup); wpn_set_user_zoom(id, 90); g_ZoomACT[id] = 0; g_ZoomPercent[id] = 45; gtime[id] = get_gametime(); return PLUGIN_CONTINUE; }
public ev_reload(id) { wpn_playanim(id, anim_reload_unsil); wpn_set_user_zoom(id, 90); g_ZoomPercent[id] = 45; g_ZoomACT[id] = 0; return PLUGIN_CONTINUE; }
public client_connect(id) { wpn_set_user_zoom(id, 90); g_ZoomACT[id] = 0; g_ZoomPercent[id] = 45; return PLUGIN_CONTINUE; }
This is the code of my semi-automatic sniper. I've set it to zoom-in smoothly, but, if I don't zoom to the max 5x zoom and release the secondary attack button, the next time I press it, it continues to zoom-in, but I want it to reset the zoom. Right now, when it zooms-in to the max 5x zoom it stops zooming-in, and the next button press resets the zoom.
How to make it to reset the zoom before it zooms-in to the max 5x zoom if I release the button and press it again? (Hint: look at ev_attack2 function)
__________________
Last edited by SeriousSam; 09-11-2010 at 12:25.
|
|