- /* 
- 	Copyleft 2015 @ HamletEagle 
- 	Topic: https://forums.alliedmods.net/showthread.php?t=245803&page=1 
-   
- 	Weapons Menu Creator is free software; 
- 	you can redistribute it and/or modify it under the terms of the 
- 	GNU General Public License as published by the Free Software Foundation. 
-   
- 	This program is distributed in the hope that it will be useful, 
- 	but WITHOUT ANY WARRANTY; without even the implied warranty of 
- 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	 
- 	GNU General Public License for more details. 
-   
- 	You should have received a copy of the GNU General Public License 
- 	along with Weapons Menu Creator; if not, write to the 
- 	Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
- 	Boston, MA 02111-1307, USA. 
- */ 
-   
- #include <amxmodx> 
- #include <amxmisc> 
- #include <hamsandwich> 
- #include <cstrike> 
- #include <fun> 
- #include <fakemeta> 
-   
- #if defined _stripweapons_included 
-   #endinput 
- #endif 
- #define _stripweapons_included 
-   
- enum /* Weapon types */ 
- { 
- 	Primary = 1 
- 	, Secondary 
- 	, Knife 
- 	, Grenades 
- 	, C4 
- }; 
-   
- stock StripWeapons(id, Type, bool: bSwitchIfActive = true) 
- { 
- 	new iReturn; 
-   
- 	if(is_user_alive(id)) 
- 	{ 
- 		new iEntity, iWeapon; 
- 		while((iWeapon = GetWeaponFromSlot(id, Type, iEntity)) > 0) 
- 			iReturn = ham_strip_user_weapon(id, iWeapon, Type, bSwitchIfActive); 
- 	} 
-   
- 	return iReturn; 
- } 
-   
- stock GetWeaponFromSlot( id , iSlot , &iEntity ) 
- { 
-     if ( !( 1 <= iSlot <= 5 ) ) 
-         return 0; 
-   
-     iEntity = 0; 
-     const m_rgpPlayerItems_Slot0 = 367; 
-     const m_iId = 43; 
-     const EXTRAOFFSET_WEAPONS = 4; 
-   
-     iEntity = get_pdata_cbase( id , m_rgpPlayerItems_Slot0 + iSlot , EXTRAOFFSET_WEAPONS ); 
-   
-     return ( iEntity > 0 ) ? get_pdata_int( iEntity , m_iId , EXTRAOFFSET_WEAPONS ) : 0; 
- }   
-   
- stock ham_strip_user_weapon(id, iCswId, iSlot = 0, bool:bSwitchIfActive = true) 
- { 
-     new iWeapon 
-     if( !iSlot ) 
-     { 
-         static const iWeaponsSlots[] = { 
-             -1, 
-             2, //CSW_P228 
-             -1, 
-             1, //CSW_SCOUT 
-             4, //CSW_HEGRENADE 
-             1, //CSW_XM1014 
-             5, //CSW_C4 
-             1, //CSW_MAC10 
-             1, //CSW_AUG 
-             4, //CSW_SMOKEGRENADE 
-             2, //CSW_ELITE 
-             2, //CSW_FIVESEVEN 
-             1, //CSW_UMP45 
-             1, //CSW_SG550 
-             1, //CSW_GALIL 
-             1, //CSW_FAMAS 
-             2, //CSW_USP 
-             2, //CSW_GLOCK18 
-             1, //CSW_AWP 
-             1, //CSW_MP5NAVY 
-             1, //CSW_M249 
-             1, //CSW_M3 
-             1, //CSW_M4A1 
-             1, //CSW_TMP 
-             1, //CSW_G3SG1 
-             4, //CSW_FLASHBANG 
-             2, //CSW_DEAGLE 
-             1, //CSW_SG552 
-             1, //CSW_AK47 
-             3, //CSW_KNIFE 
-             1 //CSW_P90 
-         } 
-         iSlot = iWeaponsSlots[iCswId] 
-     } 
-   
-     const XTRA_OFS_PLAYER = 5 
-     const m_rgpPlayerItems_Slot0 = 367 
-   
-     iWeapon = get_pdata_cbase(id, m_rgpPlayerItems_Slot0 + iSlot, XTRA_OFS_PLAYER) 
-   
-     const XTRA_OFS_WEAPON = 4 
-     const m_pNext = 42 
-     const m_iId = 43 
-   
-     while( iWeapon > 0 ) 
-     { 
-         if( get_pdata_int(iWeapon, m_iId, XTRA_OFS_WEAPON) == iCswId ) 
-         { 
-             break 
-         } 
-         iWeapon = get_pdata_cbase(iWeapon, m_pNext, XTRA_OFS_WEAPON) 
-     } 
-   
-     if( iWeapon > 0 ) 
-     { 
-         const m_pActiveItem = 373 
-         if( bSwitchIfActive && get_pdata_cbase(id, m_pActiveItem, XTRA_OFS_PLAYER) == iWeapon ) 
-         { 
-             ExecuteHamB(Ham_Weapon_RetireWeapon, iWeapon) 
-         } 
-   
-         if( ExecuteHamB(Ham_RemovePlayerItem, id, iWeapon) ) 
-         { 
-             user_has_weapon(id, iCswId, 0) 
-             ExecuteHamB(Ham_Item_Kill, iWeapon) 
-             return 1 
-         } 
-     } 
-   
-     return 0 
- }  
-   
- #define PluginName    "Weapons Menu Creator" 
- #define PluginVersion "1.0" 
- #define PluginAuthor  "HamletEagle" 
-   
- enum 
- { 
- 	PrimaryWeapons, 
- 	SecondaryWeapons, 
- 	PrimaryMenu, 
- 	SecondaryMenu 
- } 
-   
- enum _:WeaponInfo 
- { 
- 	WeaponName [64], 
- 	WeaponAcces[64],   
- 	WeaponBullets,	 
- 	WeaponPrice 
- } 
-   
- enum 
- { 
- 	PrimarySection = 1, 
- 	SecondarySection   
- } 
-   
- const m_iAccount = 115 
- const XO_PLAYER  = 5 
-   
- new const ConfigFileName[] = "weapons_menu_creator.ini" 
-   
- new HandleConfigFile[256] 
- new HandlePrimaryMenu        
- new HandleSecondaryMenu  
- new CvarControlTeamAcces 
- new AdminDefault 
- new Array:ArrayPrimaryWeapons 
- new Array:ArraySecondaryWeapons 
- new bool:ChoosedWeapons[2][33]  
-   
- public plugin_init() 
- { 
- 	register_plugin(PluginName,PluginVersion,PluginAuthor) 
-   
- 	ArrayPrimaryWeapons   = ArrayCreate(WeaponInfo) 
- 	ArraySecondaryWeapons = ArrayCreate(WeaponInfo) 
-   
- 	register_clcmd("say /fegyverek"     , "ClientCommand_Weapons") 
- 	register_clcmd("say_team /fegyverek", "ClientCommand_Weapons") 
-   
- 	RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn", true) 
- 	register_event("TeamInfo", "OnTeamInfo_Event", "a") 
-   
- 	CvarControlTeamAcces = register_cvar( "team_acces", "0" ) 
- 	CreateWeaponsFile() 
- } 
-   
- public ClientCommand_Weapons(id) 
- { 
- 	new TeamAcces = get_pcvar_num(CvarControlTeamAcces) 
- 	if(!is_user_alive(id))  
- 	{ 
- 		client_print(id, print_chat, "Nem nyithatod meg a menut mert halott vagy!") 
- 	} 
-   
- 	else if(TeamAcces !=0 && get_user_team(id) != TeamAcces) 
- 	{ 
- 		client_print(id, print_chat, "Nincs elerhetoseged ehez a parancshoz!") 
- 	} 
-   
- 	else  
- 	{ 
- 		ChooseBestMenu(id, 1) 
- 	}	 
- } 
-   
- CreateWeaponsFile() 
- { 
- 	new HandleConfigsDir[128] 
- 	get_configsdir(HandleConfigsDir, charsmax(HandleConfigsDir)) 
- 	formatex(HandleConfigFile, charsmax(HandleConfigFile), "%s/%s", HandleConfigsDir, ConfigFileName) 
-   
- 	if(!file_exists(HandleConfigFile)) 
- 	{ 
- 		new FilePointer = fopen(HandleConfigFile, "w"), i 
- 		if(FilePointer) 
- 		{ 
- 			new const Weapons[][] = 
- 			{ 
- 				"Scout", "XM1014", "MAC10",  
- 				"Aug", "UMP45", "SG550",  
- 				"Galil", "Famas", "Awp", 
- 				"MP5NAVY", "M249", "M3",  
- 				"M4A1", "TMP", "G3SG1",  
- 				"SG552", "AK47", "P90",  
- 				"P228", "Elite", "Fiveseven", //pistols starts from here. line 18 
- 				"USP", "GLOCK18", "Deagle"    //line 23 
- 			}; 
-   
- 			fputs(FilePointer, ";Fegyver Menu Keszito^n") 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, ";Itt van egy lista az ElsodlegesFegyverek+MasodlagosFegyverek-rol^n") 
- 			fputs(FilePointer, ";Valassz annyit amennyit szeretnel^n") 
- 			fputs(FilePointer, ";Hiba lehet:  [FUN] Targy ^"fegyver_nev^" sikertelen keszites^n") 
- 			fputs(FilePointer, ";A fegyver neveben kell a hibakat keresni^n") 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, ";Pelda:^n") 
- 			fputs(FilePointer, ";(FegyverNev) (Tolteny) (Kihasznalhatja) (A'ra)^n") 
- 			fputs(FilePointer, ";AK47 120 ALL 0^n") 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, ";A fegyver nevet kell hasznalni:^n") 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, ";1.Fegyver Nevek:^n") 
-   
- 			//add PrimaryWeapons weapons to file 
- 			for(i = 0; i < sizeof Weapons - 6; i++) 
- 			{ 
- 				fprintf(FilePointer, ";%s^n", Weapons[i]) 
- 			} 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, ";2.Pisztoly Nevek^n") 
-   
- 			//add SecondaryWeapons weapons to file 
- 			for(i = sizeof Weapons - 5 ; i < sizeof Weapons; i++) 
- 			{ 
- 				fprintf(FilePointer, ";%s^n", Weapons[i]) 
- 			} 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, ";Admin Beallitasok a fegyvereknek:^n") 
- 			fputs(FilePointer, ";ALL    - osszes jatekos hasznalhatja^n") 
- 			fputs(FilePointer, ";NOONE  - Korlatozott mindenkinek. A targy nem latszik a menuben!^n") 
- 			fputs(FilePointer, ";ADMIN  - Csak azok hasznalhatjak akiknek van ^"AdminAcces^" jogosultsaga^n") 
- 			fputs(FilePointer, "AdminAcces: d betu^n") 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, ";Menu keszites inditasa:^n") 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, "[ElsodlegesFegyverek]^n") 
- 			fputs(FilePointer, "^n") 
- 			fputs(FilePointer, "[MasodlagosFegyverek]^n")	 
- 		}	 
- 		fclose(FilePointer) 
- 	} 
-   
- 	ReadWeaponsFile() 
- } 
-   
- ReadWeaponsFile() 
- { 
- 	new FilePointer = fopen(HandleConfigFile , "rt") 
- 	if(!FilePointer) 
- 	{ 
- 		return 
- 	} 
-   
- 	new FileData[90], FileSection, Name[64], Bullets[8], Access[24], Price[8] 
- 	new Data[WeaponInfo] 
-   
- 	while(!feof(FilePointer)) 
- 	{ 
- 		fgets(FilePointer, FileData, charsmax(FileData)) 
- 		trim(FileData) 
-   
- 		if(!FileData[0] || FileData[0] == ';' || FileData[0] == '#' || FileData[0] == '/') 
- 		{ 
- 			continue 
- 		} 
-   
- 		if(FileData[0] == '[') 
- 		{ 
- 			FileSection++ 
- 			continue 
- 		} 
-   
- 		if(equal(FileData, "AdminAcces", 10)) 
- 		{ 
- 			parse 
- 			( 
- 				FileData,  
- 				Name, charsmax(Name),  
- 				Access, charsmax(Access) 
- 			) 
- 			AdminDefault = read_flags(Access) 
- 		} 
- 		else 
- 		{ 
- 			parse  
- 			( 
- 				FileData, 
- 				Name	, charsmax(Name), 
- 				Bullets , charsmax(Bullets), 
- 				Access	, charsmax(Access), 
- 				Price	, charsmax(Price) 
- 			) 
-   
- 			if(equal(Access, "NOONE")) 
- 			{ 
- 				continue 
- 			} 
-   
- 			else 
- 			{ 
- 				copy(Data[WeaponName], charsmax(Data[WeaponName] ), Name) 
- 				copy(Data[WeaponAcces], charsmax(Data[WeaponAcces] ), Access) 
-   
- 				Data[WeaponBullets] = str_to_num(Bullets) 
- 				Data[WeaponPrice]   = str_to_num(Price) 
-   
- 				switch(FileSection) 
- 				{ 
- 					case PrimarySection: 
- 					{ 
- 						ArrayPushArray(ArrayPrimaryWeapons, Data) 
- 					}	 
-   
- 					case SecondarySection: 
- 					{ 
- 						ArrayPushArray(ArraySecondaryWeapons,Data) 
- 					}	 
- 				} 
- 			} 
- 		} 
- 	} 
-   
- 	fclose(FilePointer) 
- 	BuildMenu() 
- } 
-   
- BuildMenu() 
- { 
- 	HandlePrimaryMenu   = menu_create("Elsodleges Fegyverek", "PrimaryWeapMenuHandle") 
- 	HandleSecondaryMenu = menu_create("Masodlagos Fegyverek", "SecondaruWeapMenuHandle") 
-   
- 	new Data[WeaponInfo] 
-   
- 	new Size = ArraySize(ArrayPrimaryWeapons), i 
- 	for(i = 0; i < Size; i++ )  
- 	{ 
- 		ArrayGetArray(ArrayPrimaryWeapons, i, Data) 
- 		AddItemToMenu(HandlePrimaryMenu, Data) 
- 	} 
-   
- 	Size = ArraySize(ArraySecondaryWeapons) 
- 	for(i = 0; i < Size; i++)  
- 	{ 
- 		ArrayGetArray(ArraySecondaryWeapons, i, Data) 
- 		AddItemToMenu(HandleSecondaryMenu, Data) 
- 	} 
- } 
-   
- public PrimaryWeapMenuHandle(id, HandlePrimaryMenu, item) 
- { 
- 	if(item == MENU_EXIT && is_user_connected(id)) 
- 	{ 
- 		menu_cancel(id) 
- 		return 
- 	} 
- 	ChoosedWeapons[PrimaryWeapons][id] = true 
- 	HandleBothMenus(id,item, 1) 
- } 
-   
- public SecondaruWeapMenuHandle(id, HandleSecondaryMenu, item) 
- {	 
- 	if(item == MENU_EXIT && is_user_connected(id)) 
- 	{ 
- 		menu_cancel(id) 
- 		return 
- 	} 
- 	ChoosedWeapons[SecondaryWeapons][id] = true 
- 	HandleBothMenus(id,item, 2) 
- } 
-   
- public CBasePlayer_Spawn(id) 
- { 
- 	if(!is_user_alive(id)) 
- 	{ 
- 		return 
- 	} 
-   
- 	ChoosedWeapons[PrimaryWeapons  ][id] = false 
- 	ChoosedWeapons[SecondaryWeapons][id] = false 
-   
- 	new TeamAcces = get_pcvar_num(CvarControlTeamAcces) 
- 	if(TeamAcces !=0 && get_user_team(id) != TeamAcces) 
- 	{ 
- 		return 
- 	} 
-   
- 	ChooseBestMenu(id, 0) 
- } 
-   
- ChooseBestMenu(id, Message) 
- { 
- 	if(!ChoosedWeapons[PrimaryWeapons][id]) 
- 	{ 
- 		if(ArraySize(ArrayPrimaryWeapons)) 
- 		{ 
- 			DisplayMenu(id, PrimaryMenu) 
- 		} 
- 		else if(!ChoosedWeapons[SecondaryWeapons][id]) 
- 		{ 
- 			DisplayMenu(id, SecondaryMenu) 
- 			ChoosedWeapons[PrimaryWeapons][id] = true 
- 		} 
- 	} 
- 	else if(!ChoosedWeapons[SecondaryWeapons][id]) 
- 	{ 
- 		if(ArraySize(ArraySecondaryWeapons)) 
- 		{ 
- 			DisplayMenu(id, SecondaryMenu) 
- 		} 
- 		else if(!ChoosedWeapons[PrimaryWeapons][id]) 
- 		{ 
- 			DisplayMenu(id, PrimaryMenu) 
- 			ChoosedWeapons[SecondaryWeapons][id] = true 
- 		} 
- 	} 
- 	else if(Message) 
- 	{ 
- 		client_print(id, print_chat, "Mar kivalasztottad a fegyvered!") 
- 	} 
- } 
-   
- public OnTeamInfo_Event() 
- { 
- 	show_menu(read_data(1), 0, "^n", 1) 
- } 
-   
- public plugin_end() 
- { 
- 	ArrayDestroy(ArrayPrimaryWeapons) 
- 	ArrayDestroy(ArraySecondaryWeapons) 
-   
- 	menu_destroy(HandlePrimaryMenu) 
- 	menu_destroy(HandleSecondaryMenu) 
- } 
-   
- AddItemToMenu(Menu, Data[WeaponInfo]) 
- { 
- 	new MenuText[64] 
-   
- 	if(equal(Data[WeaponAcces], "ALL")) 
- 	{ 
- 		formatex(MenuText, charsmax(MenuText),"%s\R\w%i", Data[WeaponName], Data[WeaponPrice]) 
- 		menu_additem(Menu, MenuText, "", 0) 
- 	}	 
- 	else 
- 	{ 
- 		if(equal(Data[WeaponAcces], "ADMIN")) 
- 		{ 
- 			formatex(MenuText, charsmax(MenuText), "%s\R\w%i", Data[WeaponName], Data[WeaponPrice]) 
- 			menu_additem(Menu, MenuText, "", AdminDefault) 
- 		}	 
- 	} 
- } 
-   
- HandleBothMenus(id, item, Type) 
- { 
- 	if(!is_user_alive(id)) 
- 	{ 
- 		return 
- 	} 
-   
- 	new Data[WeaponInfo], Money = get_pdata_int(id, m_iAccount, XO_PLAYER), FinalWeaponName[64] 
-   
- 	switch(Type) 
- 	{ 
- 		case 1: 
- 		{ 
- 			ArrayGetArray(ArrayPrimaryWeapons, item, Data) 
- 			menu_cancel(id) 
-   
-   
- 			if(ArraySize(ArraySecondaryWeapons) != 0) 
- 			{ 
- 				menu_display(id, HandleSecondaryMenu, 0) 
- 			} 
- 		} 
-   
- 		case 2:  
- 		{ 
- 			ArrayGetArray(ArraySecondaryWeapons, item, Data) 
- 			menu_cancel(id)	 
- 		} 
- 	} 
-   
- 	//not enough money to buy 
- 	if(Money < Data[WeaponPrice]) 
- 	{ 
- 		client_print(id, print_chat, "Sajnos nincs eleg penzed!") 
- 		menu_display(id, HandlePrimaryMenu, 0) 
- 	} 
-   
- 	else if(Data[WeaponPrice] != 0)  
- 	{ 
- 		cs_set_user_money(id, Money - Data[WeaponPrice], 1) 
- 	} 
-   
- 	for(new i; i < sizeof Data[WeaponName]; i++)  
- 	{ 
- 		FinalWeaponName[i] = tolower(Data[WeaponName][i]) 
- 	} 
-   
- 	format(FinalWeaponName, charsmax(FinalWeaponName), "weapon_%s", FinalWeaponName) 
-   
- 	give_item(id, FinalWeaponName) 
- 	StripWeapons(id, Type) 
- 	cs_set_user_bpammo(id, get_weaponid(FinalWeaponName), Data[WeaponBullets]) 
- }  
-   
- DisplayMenu(id, MenuType) 
- { 
- 	switch(MenuType) 
- 	{ 
- 		case PrimaryMenu: 
- 		{ 
- 			if(ArraySize(ArrayPrimaryWeapons)) 
- 			{ 
- 				menu_display(id, HandlePrimaryMenu, 0) 
- 			} 
- 		} 
- 		case SecondaryMenu: 
- 		{ 
- 			if(ArraySize(ArraySecondaryWeapons)) 
- 			{ 
- 				menu_display(id, HandleSecondaryMenu, 0) 
- 			} 
- 		} 
- 	} 
- } 
-