[AMX] Tổng hợp Code, Plug do Mem chế hoặc giới thiệu

  • Thread starter Thread starter Orpheus
  • Ngày gửi Ngày gửi
Xin hỏi các Pro am hiểu về code CSO-NST là có cách nào để xóa bỏ kiểu set 1 số tiền nhất định lúc đầu trận trong Zombie-Mod 3 không? Mình muốn bắn nhận tiền tự nhiên như ở chế độ mặc định.
Thứ 2 là có cách nào để mua súng nhiều lần trong Zombie-Mod 3 không? Cho mua 1 lần thôi không thích.
Đây chỉ là sở thích cá nhân của mình mong các bác chỉ giúp!
 
cái này trong sma của ZB3 ở cái event new round có 1 cái set money đó, del cái đó đi
 
Trong ini cũng có phần set start money đấy, set về 800 hoặc 0 tùy ý.
 
cái này trong sma của ZB3 ở cái event new round có 1 cái set money đó, del cái đó đi
Cám ơn mình đã sửa được trong file .sma cái MONEY_START giờ không còn bị set tiền cố định ở đầu trận nữa rồi
Thế còn cái mua súng được nhiều lần trong 1 ván đấu Zombie-Mod 3 bạn biết sửa ở đâu không?
 
Cám ơn mình đã sửa được trong file .sma cái MONEY_START giờ không còn bị set tiền cố định ở đầu trận nữa rồi
Thế còn cái mua súng được nhiều lần trong 1 ván đấu Zombie-Mod 3 bạn biết sửa ở đâu không?
Im3 vãi:|
Tự sửa SMA nhé bợn:|
 
Chỉnh sửa cuối:
ai zúp tui làm 1 cái scoreboard đơn zãn k :D
zưới góc trái , tính theo điễm , kill 1 ngừ dc 100 điễm , đội nào 7500 điễm trc thì win :D rùi restart
 
sao ko đặt theo TeamDM ấy :|................................... kill 75 người :|
 
^
người ta nhờ làm thế cho giống MW mà ông cho câu cụt hứng quá =.=
 
Em viết plugin này để dùng cho mod của em. Té ra cũng hoạt động khá tốt. Em chỉ upload plugin thôi. Còn model mọi người phải tự lo :D
Nguyên lý hoạt động là thế này: chuyển qua lại giữa model thường và model sight. Nghe khá đơn giản. Và vì mọi người đều biết ỉon sight là cái gì nên chỉ post 1 hình gọi là demo.

hl_2011-07-21_14-09-00-60.png


Tiện đây cũng hỏi luôn mọi người, nhất là ai rành AMX coding về một số giới hạn em gặp phải khi viết plugin này.
Thứ nhất, có cách nào để xác định khi player đổi weapon không, để em toggle cái crosshair cho đúng?
Thứ hai, em chưa biết làm sao để làm iron sight cho các weapon có attack2 mặc định, và chuyển attack2 mặc định sang một key khác, chẳng hạn M4A1, right click là iron sight, T là silencer. Ai có cao kiến gì xin chỉ giáo.
Trừ hai giới hạn trên ra, những thứ còn lại đã tạm ổn.
Cảm ơn mọi người nhiều.

Đây là toàn bộ code cho ai muốn giúp thì tham khảo:

PHP:
 #include <amxmodx>
 #include <fakemeta>
 #include <hamsandwich>
 #include <engine>
 

 new g_cvarEnabled;
 new g_msgCrosshair;
 new g_insight;
 new g_HideWeapon;

 new crosshair[33];

 public plugin_init()
 {
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_mp5navy", "iron_sight_mp5", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_ak47", "iron_sight_ak47", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_deagle", "iron_sight_deagle", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_galil", "iron_sight_deagle", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_m249", "iron_sight_m249", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_p90", "iron_sight_m249", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_mac10", "iron_sight_mac10", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_p228", "iron_sight_p228", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_fiveseven", "iron_sight_fiveseven", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_m3", "iron_sight_m3", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_xm1014", "iron_sight_m4", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_tmp", "iron_sight_tmp", 1 )
	register_plugin("EIS","1.3","TSA");
	g_HideWeapon = get_user_msgid("HideWeapon")
	register_event("ResetHUD","event_resethud","b");
	register_event("CurWeapon","event_curweapon","b","1=1");
	register_event("DeathMsg","event_deathmsg","a");
	g_cvarEnabled = register_cvar("sc_enabled","1",FCVAR_SERVER);
	}
 //precache the models
 public plugin_precache() 
 { 
 precache_model("models/v_mp5_sight.mdl")
 precache_model("models/v_ak47_sight.mdl")
 precache_model("models/v_deagle_sight.mdl")
 precache_model("models/v_galil_sight.mdl")
 precache_model("models/v_m249_sight.mdl")
 precache_model("models/v_p90_sight.mdl")
 precache_model("models/v_p228_sight.mdl")
 precache_model("models/v_mac10_sight.mdl")
 precache_model("models/v_fiveseven_sight.mdl")
 precache_model("models/v_m3_sight.mdl")
 precache_model("models/v_xm1014_sight.mdl")
 precache_model("models/v_tmp_sight.mdl")
 }
 //events
 public event_resethud(id)
 {
	// spawn with crosshair
	if(is_user_alive(id)) 
         draw_crosshair(id);
 }
 
 
 // the best part of the code
  public client_PreThink(id)
 {
	//using a mp5
	new clip, ammo, weapon = get_user_weapon(id, clip, ammo); 
	new button = entity_get_int(id,EV_INT_button);
	if(weapon == CSW_MP5NAVY) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_mp5(id,0);
	         }
	         else
	         {
		unsight_mp5(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_mp5(id, 1)
	 }
	}
	//using an ak47
	if(weapon == CSW_AK47) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_ak47(id,0);
	         }
	         else
	         {
		unsight_ak47(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_ak47(id, 1)
	 }
	}
	//using a deagle
	if(weapon == CSW_DEAGLE) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_deagle(id,0);
	         }
	         else
	         {
		unsight_deagle(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_deagle(id, 1)
	 }
	}
	//using a galil
	if(weapon == CSW_GALIL) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_galil(id,0);
	         }
	         else
	         {
		unsight_galil(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_galil(id, 1)
	 }
	}
	//using a m249
	if(weapon == CSW_M249) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_m249(id,0);
	         }
	         else
	         {
		unsight_m249(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_m249(id, 1)
	 }
	}
	//using a p90
	if(weapon == CSW_P90) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_p90(id,0);
	         }
	         else
	         {
		unsight_p90(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_p90(id, 1)
	 }
	 }
	 //using a mac10
	if(weapon == CSW_MAC10) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_mac10(id,0);
	         }
	         else
	         {
		unsight_mac10(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_mac10(id, 1)
	 }
	 }
	 //using a p228
	if(weapon == CSW_P228) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_p228(id,0);
	         }
	         else
	         {
		unsight_p228(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_p228(id, 1)
	 }
	 }
	 //using a fiveseven
	if(weapon == CSW_FIVESEVEN) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_fiveseven(id,0);
	         }
	         else
	         {
		unsight_fiveseven(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_fiveseven(id, 1)
	 }
	 }
	  //using a m3
	if(weapon == CSW_M3) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_m3(id,0);
	         }
	         else
	         {
		unsight_m3(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_m3(id, 1)
	 }
	 }
	  //using a m4
	if(weapon == CSW_XM1014) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_m4(id,0);
	         }
	         else
	         {
		unsight_m4(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_m4(id, 1)
	 }
	 }
	  //using a tmp
	if(weapon == CSW_TMP) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_tmp(id,0);
	         }
	         else
	         {
		unsight_tmp(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_tmp(id, 1)
	 }
	 }
	 
	 }

 // ironsight and crosshair related
 public iron_sight_mp5(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_mp5_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_mp5navy 0.5")
 }
 public unsight_mp5(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_mp5.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_mp5navy 0.8")
 }
 public iron_sight_ak47(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_ak47_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_ak47 0.4")
 }
 public unsight_ak47(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_ak47.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_ak47 1.0")
 }
 public iron_sight_deagle(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_deagle_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_deagle 0.72")
 }
 public unsight_deagle(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_deagle.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_deagle 0.96")
 }
 public iron_sight_galil(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_galil_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_galil 0.5")
 }
 public unsight_galil(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_galil.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_galil 0.96")
 }
 public iron_sight_m249(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_m249_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_m249 0.4")
 }
 public unsight_m249(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_m249.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_m249 0.96")
 }
 public iron_sight_p90(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_p90_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_p90 0.4")
 }
 public unsight_p90(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_p90.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_p90 0.96")
 }
 public iron_sight_mac10(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_mac10_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_mac10 0.4")
 }
 public unsight_mac10(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_mac10.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_mac10 0.96")
 }
 public iron_sight_p228(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_p228_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_p228 0.4")
 }
 public unsight_p228(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_p228.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_p228 0.96")
 }
 public iron_sight_fiveseven(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_fiveseven_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_fiveseven 0.4")
 }
 public unsight_fiveseven(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_fiveseven.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_fiveseven 0.96")
 }
 public iron_sight_m3(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_m3_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_m3 0.8")
 }
 public unsight_m3(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_m3.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_m3 0.96")
 }
 public iron_sight_m4(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_xm1014_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_xm1014 0.7")
 }
 public unsight_m4(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_xm1014.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_xm1014 0.96")
 }
 public iron_sight_tmp(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_tmp_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_tmp 0.7")
 }
 public unsight_tmp(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_tmp.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_tmp 0.96")
 }
 public iron_sight_m4a1(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_m4a1_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_tmp 0.7")
 }
 public unsight_m4a1(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_m4a1.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_tmp 0.96")
 }
 
 
 public draw_crosshair(id)
{
    message_begin(MSG_ONE_UNRELIABLE, g_HideWeapon, _,id)
    write_byte(0)
    message_end()
}

public hide_crosshair(id)
{
    message_begin(MSG_ONE_UNRELIABLE, g_HideWeapon, _,id)
    write_byte(1<<6)
    message_end()
}
 
Chỉnh sửa cuối:
Em viết plugin này để dùng cho mod của em. Té ra cũng hoạt động khá tốt. Em chỉ upload plugin thôi. Còn model mọi người phải tự lo :D
Nguyên lý hoạt động là thế này: chuyển qua lại giữa model thường và model sight. Nghe khá đơn giản. Và vì mọi người đều biết ỉon sight là cái gì nên chỉ post 1 hình gọi là demo.

hl_2011-07-21_14-09-00-60.png


Tiện đây cũng hỏi luôn mọi người, nhất là ai rành AMX coding về một số giới hạn em gặp phải khi viết plugin này.
Thứ nhất, có cách nào để xác định khi player đổi weapon không, để em toggle cái crosshair cho đúng?
Thứ hai, em chưa biết làm sao để làm iron sight cho các weapon có attack2 mặc định, và chuyển attack2 mặc định sang một key khác, chẳng hạn M4A1, right click là iron sight, T là silencer. Ai có cao kiến gì xin chỉ giáo.
Trừ hai giới hạn trên ra, những thứ còn lại đã tạm ổn.
Cảm ơn mọi người nhiều.

Đây là toàn bộ code cho ai muốn giúp thì tham khảo:

Mã:
 #include <amxmodx>
 #include <fakemeta>
 #include <hamsandwich>
 #include <engine>
 

 new g_cvarEnabled;
 new g_msgCrosshair;
 new g_insight;
 new g_HideWeapon;

 new crosshair[33];

 public plugin_init()
 {
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_mp5navy", "iron_sight_mp5", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_ak47", "iron_sight_ak47", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_deagle", "iron_sight_deagle", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_galil", "iron_sight_deagle", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_m249", "iron_sight_m249", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_p90", "iron_sight_m249", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_mac10", "iron_sight_mac10", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_p228", "iron_sight_p228", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_fiveseven", "iron_sight_fiveseven", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_m3", "iron_sight_m3", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_xm1014", "iron_sight_m4", 1 )
	RegisterHam ( Ham_Weapon_SecondaryAttack, "weapon_tmp", "iron_sight_tmp", 1 )
	register_plugin("EIS","1.3","TSA");
	g_HideWeapon = get_user_msgid("HideWeapon")
	register_event("ResetHUD","event_resethud","b");
	register_event("CurWeapon","event_curweapon","b","1=1");
	register_event("DeathMsg","event_deathmsg","a");
	g_cvarEnabled = register_cvar("sc_enabled","1",FCVAR_SERVER);
	}
 //precache the models
 public plugin_precache() 
 { 
 precache_model("models/v_mp5_sight.mdl")
 precache_model("models/v_ak47_sight.mdl")
 precache_model("models/v_deagle_sight.mdl")
 precache_model("models/v_galil_sight.mdl")
 precache_model("models/v_m249_sight.mdl")
 precache_model("models/v_p90_sight.mdl")
 precache_model("models/v_p228_sight.mdl")
 precache_model("models/v_mac10_sight.mdl")
 precache_model("models/v_fiveseven_sight.mdl")
 precache_model("models/v_m3_sight.mdl")
 precache_model("models/v_xm1014_sight.mdl")
 precache_model("models/v_tmp_sight.mdl")
 }
 //events
 public event_resethud(id)
 {
	// spawn with crosshair
	if(is_user_alive(id)) 
         draw_crosshair(id);
 }
 
 
 // the best part of the code
  public client_PreThink(id)
 {
	//using a mp5
	new clip, ammo, weapon = get_user_weapon(id, clip, ammo); 
	new button = entity_get_int(id,EV_INT_button);
	if(weapon == CSW_MP5NAVY) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_mp5(id,0);
	         }
	         else
	         {
		unsight_mp5(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_mp5(id, 1)
	 }
	}
	//using an ak47
	if(weapon == CSW_AK47) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_ak47(id,0);
	         }
	         else
	         {
		unsight_ak47(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_ak47(id, 1)
	 }
	}
	//using a deagle
	if(weapon == CSW_DEAGLE) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_deagle(id,0);
	         }
	         else
	         {
		unsight_deagle(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_deagle(id, 1)
	 }
	}
	//using a galil
	if(weapon == CSW_GALIL) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_galil(id,0);
	         }
	         else
	         {
		unsight_galil(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_galil(id, 1)
	 }
	}
	//using a m249
	if(weapon == CSW_M249) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_m249(id,0);
	         }
	         else
	         {
		unsight_m249(id,1);
		}
	         }
		// disable regular zoom
		entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
	 }
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_m249(id, 1)
	 }
	}
	//using a p90
	if(weapon == CSW_P90) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_p90(id,0);
	         }
	         else
	         {
		unsight_p90(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_p90(id, 1)
	 }
	 }
	 //using a mac10
	if(weapon == CSW_MAC10) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_mac10(id,0);
	         }
	         else
	         {
		unsight_mac10(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_mac10(id, 1)
	 }
	 }
	 //using a p228
	if(weapon == CSW_P228) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_p228(id,0);
	         }
	         else
	         {
		unsight_p228(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_p228(id, 1)
	 }
	 }
	 //using a fiveseven
	if(weapon == CSW_FIVESEVEN) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_fiveseven(id,0);
	         }
	         else
	         {
		unsight_fiveseven(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_fiveseven(id, 1)
	 }
	 }
	  //using a m3
	if(weapon == CSW_M3) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_m3(id,0);
	         }
	         else
	         {
		unsight_m3(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_m3(id, 1)
	 }
	 }
	  //using a m4
	if(weapon == CSW_XM1014) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_m4(id,0);
	         }
	         else
	         {
		unsight_m4(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_m4(id, 1)
	 }
	 }
	  //using a tmp
	if(weapon == CSW_TMP) 
	{
	// is user pressing right click?
	if(button & IN_ATTACK2)
	{
		// did he just press it?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
		{
		if(g_insight == false)
		{
		iron_sight_tmp(id,0);
	         }
	         else
	         {
		unsight_tmp(id,1);
		}
	         }
		}
	 if(button & IN_RELOAD)
	{
		// did he just press reload?
		if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_RELOAD))
		unsight_tmp(id, 1)
	 }
	 }
	 
	 }

 // ironsight and crosshair related
 public iron_sight_mp5(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_mp5_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_mp5navy 0.5")
 }
 public unsight_mp5(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_mp5.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_mp5navy 0.8")
 }
 public iron_sight_ak47(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_ak47_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_ak47 0.4")
 }
 public unsight_ak47(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_ak47.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_ak47 1.0")
 }
 public iron_sight_deagle(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_deagle_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_deagle 0.72")
 }
 public unsight_deagle(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_deagle.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_deagle 0.96")
 }
 public iron_sight_galil(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_galil_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_galil 0.5")
 }
 public unsight_galil(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_galil.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_galil 0.96")
 }
 public iron_sight_m249(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_m249_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_m249 0.4")
 }
 public unsight_m249(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_m249.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_m249 0.96")
 }
 public iron_sight_p90(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_p90_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_p90 0.4")
 }
 public unsight_p90(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_p90.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_p90 0.96")
 }
 public iron_sight_mac10(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_mac10_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_mac10 0.4")
 }
 public unsight_mac10(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_mac10.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_mac10 0.96")
 }
 public iron_sight_p228(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_p228_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_p228 0.4")
 }
 public unsight_p228(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_p228.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_p228 0.96")
 }
 public iron_sight_fiveseven(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_fiveseven_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_fiveseven 0.4")
 }
 public unsight_fiveseven(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_fiveseven.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_fiveseven 0.96")
 }
 public iron_sight_m3(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_m3_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_m3 0.8")
 }
 public unsight_m3(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_m3.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_m3 0.96")
 }
 public iron_sight_m4(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_xm1014_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_xm1014 0.7")
 }
 public unsight_m4(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_xm1014.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_xm1014 0.96")
 }
 public iron_sight_tmp(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_tmp_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_tmp 0.7")
 }
 public unsight_tmp(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_tmp.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_tmp 0.96")
 }
 public iron_sight_m4a1(id,enabled)
 {
 	entity_set_string(id,EV_SZ_viewmodel, "models/v_m4a1_sight.mdl");
         g_insight = true
	hide_crosshair(id)
	client_cmd(id,"amx_recoil_tmp 0.7")
 }
 public unsight_m4a1(id,enabled)
 {
	entity_set_string(id,EV_SZ_viewmodel, "models/v_m4a1.mdl");
         g_insight = false
	draw_crosshair(id)
	client_cmd(id,"amx_recoil_tmp 0.96")
 }
 
 
 public draw_crosshair(id)
{
    message_begin(MSG_ONE_UNRELIABLE, g_HideWeapon, _,id)
    write_byte(0)
    message_end()
}

public hide_crosshair(id)
{
    message_begin(MSG_ONE_UNRELIABLE, g_HideWeapon, _,id)
    write_byte(1<<6)
    message_end()
}
Code của bợn dài quá:|dùng array + format string có phải nhanh hơn ko:|
 
Cho cái đoạn code vào trong thẻ php....
Cái vấn đề thứ 2 thì tham khảo ở trong sma NST WPN Rifle
 
nếu bạn dùng ỉonsight cho m4 hay usp
nên add code để disable silencer, như thế này nà :D
PHP:
public plugin_init()
{
RegisterHam(Ham_Weapon_deploy,"weapon_m4a1","fw_blocksilent")
RegisterHam(Ham_Weapon_SecondaryAttack,"weapon_m4a1","fw_blocksilent")
}
public fw_blocksilent(ent)
{
set_pdata_float(ent, 47, 9999.0,4)
}

p/s: đây chỉ là ý tưởng, chưa có test đâu :S
 
Chỉnh sửa cuối:
Bị lỗi thế này: "Undefined symbol: Ham_Weapon_Deploy'"
Plugin này em viết khi chưa biết xài array, nên mới lung tung thế.
 
^
^
PHP:
- new g_weapon[][] = {
 "weapon_ak47",
 "weapon_m4a1",
 "weapon_aug"
}

for(new i = 0; i < sizeof(g_weapon); i++)
{
 RegisterHam(Ham_Weapon_PrimaryAttack, g_weapon[i], "fw_weapon_primaryattack")
}

public fw_weapon_primaryattack(ent)
{
 new id = pev(ent, pev_owner)
 client_print(id, print_center, "[BECAREFUL. I AM FIRING]")
}
... đó là ví dụ về array, nếu trong console báo not found thì thay sizeof thành charsmax

---------- Post added at 20:58 ---------- Previous post was at 20:32 ----------

à nhầm sorry :)). mới post dc 13 bài nên ko cho edit bài viết
----------------------------
PHP:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

// Danh sach vu khi duoc tao = array
new g_weapon[][] = {
	"weapon_ak47",
	"weapon_m4a1",
	"weapon_aug"
}

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	 // Neu Console bao' la entity out of.... thi sua sizeof thanh charsmax
	for(new i = 0; i < sizeof(g_weapon); i++)
	{
		RegisterHam(Ham_Weapon_PrimaryAttack, g_weapon[i], "fw_weapon_primaryattack")
	}
}

public fw_weapon_primaryattack(ent)
{
	new id = pev(ent, pev_owner)
	
	client_print(id, print_center, "[BECAREFUL. I AM FIRING]")
}
 
@TSA: Anh bạn này có tiềm năng đây ^^ . Nhưng mà code của bạn dài dòng quá !!
- Phần amx_set_recoil gì đó , bạn ko nên làm client_cmd . vì sẽ không hiểu quả khi đang chơi server online , client ko thể exec command tinh chỉnh cvar . Nên làm 1 bool g_Bsight rồi nếu true thì set pucnangle lại thôi !
- Đừng hardcode đường dẫn model
- Nên dùng dữ liệu loại bảng , để dễ sắp xếp dữ liệu lại
Vd : weapon_entity , đường dần model sight , hệ số nhân recoil
- { "weapon_ak47" , "models/sight/v_ak47.mdl" , 0.8 }
Cái này tìm thêm TUT về enumeration nhé . Trên AM có .
- Cần thêm check những vũ khí ko ADS đc ( DAO , C4 , lựu đạn )
- Thêm bitsum check nếu vũ khí là USP , FAMAS , M4A1 , GLOCK . Thay nút đổi function thành nút E hoặc là lock luôn ! .
- Chúc may mắn :D
 
Sorry teo quên nó là item,viết bừa mà
à nên dùg set task và sendweaponanim để chuyển wa sight hju wả hơn khi bấm attack2.
 
Mấy anh thông cảm, nào giờ em toàn lập trình bằng VB.NET với tí C++, cho nên hoàn toàn mù Pawn. Cái plugin này là vừa học vừa viết, thêm vô từng tý một. Còn phần client_cmd là để thử nghiệm thôi, không tác dụng gì đâu.
Sẽ tìm thêm tut. Mà sau này chuyển qua mod HL2 rồi nên chắc chả cần plugin này nữa.
 
Back
Top