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

new g_Enable;
new g_bwEnt[33];
new g_CachedStringInfoTarget;

public plugin_init() {
	register_plugin( "Santa Hat", "1.2", "xPaw" );
	register_cvar("santa_hat", "1.2", FCVAR_SERVER);
	g_Enable = register_cvar("amx_santahat", "1");

	RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1);
	g_CachedStringInfoTarget = engfunc( EngFunc_AllocString, "info_target" );
}

public plugin_precache()
	precache_model("models/santa_hat.mdl");

public fwHamPlayerSpawnPost( const player ) {
	if ( get_pcvar_num( g_Enable ) && is_user_alive( player ) ) {
		new iEnt = g_bwEnt[ player ];
		if( !pev_valid( iEnt ) ) {
			g_bwEnt[ player ] = iEnt = engfunc ( EngFunc_CreateNamedEntity, g_CachedStringInfoTarget );
			set_pev( iEnt, pev_movetype, MOVETYPE_FOLLOW );
			set_pev( iEnt, pev_aiment, player );
			engfunc( EngFunc_SetModel, iEnt, "models/santa_hat.mdl" );
		}
	}
}