#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>
//#include <fun>
#include <halomod>

#define PLUGIN "HaloMod Misc"
#define VERSION HALOVERSION
#define AUTHOR "Soccdoodcss"

#define FALL_VELOCITY 350.0
#define TASK 1337

new pOn, pGravity, pSpeed, pType

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_cvar(AUTHOR, VERSION, FCVAR_SERVER|FCVAR_SPONLY)
	register_cvar("HaloMod", AUTHOR, FCVAR_SERVER|FCVAR_SPONLY)
	register_cvar("halo_version", VERSION, FCVAR_SERVER|FCVAR_SPONLY)
	
	pOn = register_cvar("halo_on", "1", FCVAR_SERVER)
	pGravity = register_cvar("halo_gravity", "400", FCVAR_SERVER)
	pSpeed = register_cvar("halo_speed", "300.0", FCVAR_SERVER)
	pType = register_cvar("halo_type", "0", FCVAR_SERVER)
	
	register_event("HLTV", "onRound", "a")
	register_event("CurWeapon","onChangeWeapon","be","1=1")
	
	register_forward(FM_SetModel, "onModel", 1)
	register_forward(FM_GetGameDescription, "onGameDescription")
}

public onRound()
{
	setup_plugin();
}

public onChangeWeapon(id)
{
	set_pev(id, pev_maxspeed, get_pcvar_float(pSpeed))
}

public onModel(ent)
{
	new class[33]
	pev(ent, pev_classname, class, 32)
	if (equal(class, "weaponbox"))
		set_pev(ent, pev_nextthink, get_gametime() + 60.0)
}

public onGameDescription()
{
	if(!is_halo_on())
		return FMRES_HANDLED
	
	new gametype[33]
	format(gametype, 32, "Halo Mod v%s", VERSION)
	
	forward_return( FMV_STRING, gametype);
	return FMRES_SUPERCEDE;
}

public setup_plugin()
{
	if(!get_pcvar_num(pOn) || get_cvar_num("sv_gravity") == get_pcvar_num(pGravity))
		return PLUGIN_HANDLED
	
	server_cmd("sv_gravity %d", get_pcvar_num(pGravity))
	server_cmd("sv_maxspeed 2000")
	
	return PLUGIN_HANDLED
}

public client_connect(id)
{
	if(!is_halo_on())
		return PLUGIN_HANDLED
		
	play_sound(id, "guitar")
	
	return PLUGIN_HANDLED
}


public plugin_precache()
{
	precache_generic("sound/halomodv3/guitar.mp3")
}

public no_compile_errors()
	get_pcvar_num(pType)
