#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <fakemeta>
#include <hamsandwich>
#include <xs>
#include <zombieplague>

#define PLUGIN "[ZP] Grenade Models for classes."
#define VERSION "1.0"
#define AUTHOR "=)"

new g_gender[33]
new Array:g_psmoke1,  Array:g_psmoke2 , Array:g_psmoke3, Array:g_psmoke4 ,  Array:g_psmoke5, Array:g_psmoke6 , Array:g_psmoke7 , Array:g_psmoke ,
Array:g_vsmoke1,  Array:g_vsmoke2 , Array:g_vsmoke3, Array:g_vsmoke4 ,  Array:g_vsmoke5, Array:g_vsmoke6 , Array:g_vsmoke7 , Array:g_vsmoke

enum (+= 100)
{
	TASK_BLOOD
}

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_event("CurWeapon","CurrentWeapon","be","1=1")
}

public plugin_precache()
{
	
	g_vsmoke1 = ArrayCreate(32, 1)
	g_vsmoke2 = ArrayCreate(32, 1)
	g_vsmoke3 = ArrayCreate(32, 1)
	g_vsmoke4 = ArrayCreate(32, 1)
	g_vsmoke5 = ArrayCreate(32, 1)
	g_vsmoke6 = ArrayCreate(32, 1)
        g_vsmoke7 = ArrayCreate(32, 1)
	g_vsmoke = ArrayCreate(32, 1)
	g_psmoke1 = ArrayCreate(32, 1)
	g_psmoke2 = ArrayCreate(32, 1)
	g_psmoke3 = ArrayCreate(32, 1)
	g_psmoke4 = ArrayCreate(32, 1)
	g_psmoke5 = ArrayCreate(32, 1)
	g_psmoke6 = ArrayCreate(32, 1)
        g_psmoke7 = ArrayCreate(32, 1)
	g_psmoke = ArrayCreate(32, 1)

	load_custom()

	new buffer2[128]
	for (new i = 0; i < ArraySize(g_vsmoke); i++)
	{
		ArrayGetString(g_vsmoke, i, buffer2, charsmax(buffer2))
		precache_model(buffer2)
	}
	for (new i = 0; i < ArraySize(g_psmoke); i++)
	{
		ArrayGetString(g_psmoke, i, buffer2, charsmax(buffer2))
		precache_model(buffer2)
	}
}

public CurrentWeapon(id)
{
	new weapon = read_data(2)
	new v_model[128] , p_model[128]

	if(weapon == CSW_SMOKEGRENADE && zp_get_user_zombie(id) || zp_get_user_zombie(id) && weapon == CSW_FLASHBANG)
	{
		if(g_gender[id] == 1) ArrayGetString(g_vsmoke1, random_num(0, ArraySize(g_vsmoke1) - 1), v_model, charsmax(v_model))
		if(g_gender[id] == 2) ArrayGetString(g_vsmoke2, random_num(0, ArraySize(g_vsmoke2) - 1), v_model, charsmax(v_model))
		if(g_gender[id] == 3) ArrayGetString(g_vsmoke3, random_num(0, ArraySize(g_vsmoke3) - 1), v_model, charsmax(v_model))
		if(g_gender[id] == 4) ArrayGetString(g_vsmoke4, random_num(0, ArraySize(g_vsmoke4) - 1), v_model, charsmax(v_model))
		if(g_gender[id] == 5) ArrayGetString(g_vsmoke5, random_num(0, ArraySize(g_vsmoke5) - 1), v_model, charsmax(v_model))
		if(g_gender[id] == 6) ArrayGetString(g_vsmoke6, random_num(0, ArraySize(g_vsmoke6) - 1), v_model, charsmax(v_model))
                if(g_gender[id] == 7) ArrayGetString(g_vsmoke7, random_num(0, ArraySize(g_vsmoke7) - 1), v_model, charsmax(v_model))
		if(g_gender[id] == 1) ArrayGetString(g_psmoke1, random_num(0, ArraySize(g_psmoke1) - 1), p_model, charsmax(p_model))
		if(g_gender[id] == 2) ArrayGetString(g_psmoke2, random_num(0, ArraySize(g_psmoke2) - 1), p_model, charsmax(p_model))
		if(g_gender[id] == 3) ArrayGetString(g_psmoke3, random_num(0, ArraySize(g_psmoke3) - 1), p_model, charsmax(p_model))
		if(g_gender[id] == 4) ArrayGetString(g_psmoke4, random_num(0, ArraySize(g_psmoke4) - 1), p_model, charsmax(p_model))
		if(g_gender[id] == 5) ArrayGetString(g_psmoke5, random_num(0, ArraySize(g_psmoke5) - 1), p_model, charsmax(p_model))
		if(g_gender[id] == 6) ArrayGetString(g_psmoke6, random_num(0, ArraySize(g_psmoke6) - 1), p_model, charsmax(p_model))
                if(g_gender[id] == 7) ArrayGetString(g_psmoke7, random_num(0, ArraySize(g_psmoke7) - 1), p_model, charsmax(p_model))
		set_pev(id, pev_viewmodel2, v_model)
		set_pev(id, pev_weaponmodel2, p_model)
	}
}
public zp_user_infected_post(id, infector)
{
	g_gender[id] = zp_get_user_zombie_class(id) + 1
}

public load_custom()
{
	// Build customization file path
	new path[64]
	get_configsdir(path, charsmax(path))
	format(path, charsmax(path), "%s/zp_classgranade.ini", path)
	
	// File not present
	if (!file_exists(path))
	{
		new error[100]
		formatex(error, charsmax(error), "Cannot load customization file %s!", path)
		set_fail_state(error)
		return;
	}
	
	// Set up some vars to hold parsing info
	new linedata[1024], key[64], value[960], section
	
	// Open customization file for reading
	new file = fopen(path, "rt")
	
	while (file && !feof(file))
	{
		// Read one line at a time
		fgets(file, linedata, charsmax(linedata))
		
		// Replace newlines with a null character to prevent headaches
		replace(linedata, charsmax(linedata), "^n", "")
		
		// Blank line or comment
		if (!linedata[0] || linedata[0] == ';') continue;
		
		// New section starting
		if (linedata[0] == '[')
		{
			section++
			continue;
		}
		
		// Get key and value(s)
		strtok(linedata, key, charsmax(key), value, charsmax(value), '=')
		
		// Trim spaces
		trim(key)
		trim(value)
		
		if (equal(key, "VMODEL_SMOKE1"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_vsmoke, key)	
				ArrayPushString(g_vsmoke1, key)
			}
		}
		if (equal(key, "VMODEL_SMOKE2"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_vsmoke, key)	
				ArrayPushString(g_vsmoke2, key)
			}
		}
		if (equal(key, "VMODEL_SMOKE3"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_vsmoke, key)	
				ArrayPushString(g_vsmoke3, key)
			}
		}
		if (equal(key, "VMODEL_SMOKE4"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_vsmoke, key)	
				ArrayPushString(g_vsmoke4, key)
			}
		}
		if (equal(key, "VMODEL_SMOKE5"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_vsmoke, key)	
				ArrayPushString(g_vsmoke5, key)
			}
		}
		if (equal(key, "VMODEL_SMOKE6"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_vsmoke, key)	
				ArrayPushString(g_vsmoke6, key)
			}
		}
                if (equal(key, "VMODEL_SMOKE7"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_vsmoke, key)	
				ArrayPushString(g_vsmoke7, key)
			}
		}
		if (equal(key, "PMODEL_SMOKE1"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_psmoke, key)	
				ArrayPushString(g_psmoke1, key)
			}
		}
		if (equal(key, "PMODEL_SMOKE2"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_psmoke, key)	
				ArrayPushString(g_psmoke2, key)
			}
		}
		if (equal(key, "PMODEL_SMOKE3"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_psmoke, key)	
				ArrayPushString(g_psmoke3, key)
			}
		}
		if (equal(key, "PMODEL_SMOKE4"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_psmoke, key)	
				ArrayPushString(g_psmoke4, key)
			}
		}
		if (equal(key, "PMODEL_SMOKE5"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_psmoke, key)	
				ArrayPushString(g_psmoke5, key)
			}
		}
		if (equal(key, "PMODEL_SMOKE6"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_psmoke, key)	
				ArrayPushString(g_psmoke6, key)
			}
		}
                if (equal(key, "PMODEL_SMOKE7"))
		{
			// Parse weapons
			while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
			{
				trim(key)
				trim(value)
				ArrayPushString(g_psmoke, key)	
				ArrayPushString(g_psmoke7, key)
			}
		}
	}
	if (file) fclose(file)
}