/* AMX Mod script. 
* 
* (c) Copyright 2003, OLO for the Best AmxMod 
* This file is provided as is (no warranties). 
* This plugin run only with CS 1.6 deagle, .., m4, suit, shield...
* exemple : give_weapon @CT shield, give_weapon Taz m4 give_weapon @ALL ak, 
* VERSION 1.6.1 : Add Drop weapon for shield and drop C4 (to activate C4), drop Primary Weapon to activate shield
* VERSION 1.6.2 : Add possibility "say" : "giveme suit" , "giveme deagle",...
* TO active (say giveme) you must run "give_say 1" or "give_say 0" to disabled
* [CCC]Taz-Devil Plugin's */

#include <amxmod>
#include <amxmisc>

#define ACCESS_WEAPON ADMIN_LEVEL_B
#define language 0 /* 0= English  1= Francais 2= German */ 
#define NbWeapon 32

/* This part it's for multilanguage */ 
new TxtWeapon[3][] = {"FREE WEAPON","MODE ARMES GRATUITES","FREE WEAPON"} 
new TxtWeaponerror[3][] = {"Not good weapon name","Arme introuvable","Not good weapon name"} 
new TxtWeaponplayer[3][] = {"Not good player name","Joueur introuvable","Not good player name"} 
new TxtUsage[3][] = {"< name > or < @ equipe > < weapon to give >","< nom > or < @ equipe > < nom de l arme >","< nom > or < @ equipe > < weapon to give >"}
new TxtError[3][] = {"not enabled","non activé","nicht ermöglicht"}
new TxtSay[3][] = {"You can say giveme <weapon name>","say giveme <nom de l arme>","sagen giveme < Waffenamen >"}
/* End language part   */ 

/* This part to define weapon */
new TabWeapon[NbWeapon][]={"p228","scout","hegrenade","xm1014","c4","mac10","aug","smokegrenade","elite","fiveseven","ump45","sg550","galil","famas","usp","glock18","awp","mp5navy","m249","m3","m4a1","tmp","g3sg1","flashbang","deagle","sg552","ak47","knife","p90","shield","item_assaultsuit","item_thighpack"}
new WeapoToAmmo[NbWeapon] = {9,2,-1,5,-1,6,4,-1,10,7,6,4,4,4,6,10,1,10,3,5,4,10,2,-1,8,4,2,-1,7,-1,-1,-1}
new TabAmmo[10][] = {"ammo_338magnum","ammo_762nato","ammo_556natobox","ammo_556nato","ammo_buckshot","ammo_45acp","ammo_57mm","ammo_50ae","ammo_357sig","ammo_9mm"}
/* End Weapon part */

public give_weapon(id,level,cid) { 
	if (!cmd_access(id,level,cid,2)) {
		return PLUGIN_HANDLED 
	}
	if (read_argc() != 3) { 
		client_print(id,print_console,"[free give weapon]: %s",TxtUsage[language]) 
		return PLUGIN_HANDLED 
	}
	new arg[32]
	read_argv(1,arg,31) 
	new arg2[32]
	read_argv(2,arg2,31)   
	strtolower(arg2)
	amx_weapon(id,arg,arg2)
	return PLUGIN_HANDLED 
}

public say_weapon(id) { 
	new Speech[192] 
   	read_args(Speech,192) 
   	remove_quotes(Speech) 
   	if (containi(Speech, "giveme")!=-1) { 
    		if (get_cvar_num("sv_sayweapon")==0) {
			client_print(id,print_chat,"[free give weapon]: %s",TxtError[language])
			return PLUGIN_HANDLED 
		}
		strtolower(Speech[10])
		new nom[32]
		get_user_name(id,nom,32)
		amx_weapon(id,nom,Speech[7])
	}
	return PLUGIN_CONTINUE 
}

public enabled_say(id,level,cid) { 
	if (!cmd_access(id,level,cid,2)) {
		return PLUGIN_HANDLED 
	}
	new argstr[12] 
	read_argv(1,argstr,12) 
	new arg = str_to_num(argstr) 
	if ((arg != 1) && (arg != 0)) { 
		client_print(id,print_console,"[free give weapon]: give_say <1 | 0>") 
		return PLUGIN_HANDLED 
	} 
	if (arg == 1) {
		client_print(0,print_chat,"[free give weapon]: %s",TxtSay[language]) 
	}
	set_cvar_string("sv_sayweapon",argstr) 
	return PLUGIN_HANDLED 
}

	
public amx_weapon(id,victim[],weapon_give[]){
	new index_weapon = 0
	index_weapon = find_weapon(weapon_give)
	if (index_weapon<0) {
		client_print(id,print_console,"[free give weapon]: %s",TxtWeaponerror[language])
		return PLUGIN_CONTINUE
	}
	if (equal(victim,"@",1)) {
		new players[32], inum
		new team[32]
		new collect[32]
		collect="ae"
		if (equal(victim,"@CT")) {
			team = "CT"
		}
		else {
			if (equal(victim,"@ALL")) {
				team = ""
				collect= "a"
			}
			else{
				team = "TERRORIST"
			}
		}
		get_players(players,inum,collect,team)
		for(new i = 0 ;i < inum ;++i) {
			free_weapon(players[i],index_weapon)
		}
		if (inum) {
			set_hudmessage(255,100,0, 0.05,0.65, 0, 6.0, 6.0, 0.5, 0.15, 4)
			show_hudmessage(0,"[free give weapon] %s %s", TxtWeapon[language],victim)
			return PLUGIN_CONTINUE
		}
		else {
			client_print(id,print_console,"[free give weapon] %s",TxtWeaponplayer[language])
			return PLUGIN_CONTINUE
		}
	}
	else 
	{
		new player = find_player("lb",victim)
		if (player) {
			free_weapon(player,index_weapon)
			set_hudmessage(255,100,0, 0.05,0.65, 0, 6.0, 6.0, 0.5, 0.15, 4)
			show_hudmessage(0,"[free give weapon] %s %s", TxtWeapon[language],victim)
			return PLUGIN_CONTINUE
		}
		else {
			client_print(id,print_console,"[free give weapon] %s",TxtWeaponplayer[language])
			return PLUGIN_CONTINUE
		}
	}

	return PLUGIN_CONTINUE
}

public find_weapon(txtweapon[]) {
	new weapon_index
	weapon_index = -1
	for(new i = 0 ;i < NbWeapon ;++i) {
		if (containi(TabWeapon[i],txtweapon)>-1) {
			weapon_index = i
			i =  NbWeapon
		}
	}
	return weapon_index
}

public free_weapon(id,weapon_index) {
	new index_ammo
	new txtweapon[32]
	if (containi(TabWeapon[weapon_index],"item")<0) {
		format(txtweapon,32,"weapon_%s",TabWeapon[weapon_index],25)
	}
	else {
		format(txtweapon,32,"%s",TabWeapon[weapon_index],25)
	}
	// To use shield
	if (containi(TabWeapon[weapon_index],"shield")>-1) {
		engclient_cmd(id,"slot1") 
	     	engclient_cmd(id,"drop") 
	}
	give_item(id,txtweapon)
	index_ammo = WeapoToAmmo[weapon_index]-1
	if (index_ammo>-1) {
		give_item(id,TabAmmo[index_ammo])
		give_item(id,TabAmmo[index_ammo])
		give_item(id,TabAmmo[index_ammo])
	} 
	else {
		// To activate C4 drop it and pickup
		if (containi(TabWeapon[weapon_index],"C4")>-1) {
			client_cmd(id,"drop weapon_c4") 
		}
	}
	return PLUGIN_CONTINUE
}

public plugin_init(){
	register_plugin("free_give_weapon","1.6.2","[CCC]Taz-Devil")
	register_cvar("free_give_weapon", "1.6.2", FCVAR_SERVER) 
	register_cvar("sv_sayweapon", "0", FCVAR_SERVER)
	register_clcmd("give_weapon","give_weapon",ACCESS_WEAPON)
	register_clcmd("give_say","enabled_say",ACCESS_WEAPON)
	register_clcmd("say","say_weapon") 
	return PLUGIN_CONTINUE
}