/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <codmod>
#include <fakemeta>
#include <xs>

#define CS_PLAYER_HEIGHT 72.0

new const perk_name[] = "Teleport";
new const perk_desc[] = "Uzyj, aby przeniesc sie w miejsce wskazane celownikiem";


new bool:ma_perk[33];
new bool:uzyl[33];


public plugin_init()
{
	register_plugin(perk_name, "1.0", "Play")
	cod_register_perk(perk_name, perk_desc);
	register_event("ResetHUD", "ResetHUD", "abe");
}
public cod_class_enabled(id){
	uzyl[id] = false;
	return COD_CONTINUE
}
public cod_perk_disabled(id)
	ma_perk[id] = false;


public cod_perk_used(id)
{    
	if(uzyl[id] || !is_user_alive(id))
		return PLUGIN_CONTINUE;
	
	
	new Float:start[3], Float:view_ofs[3];
	pev(id, pev_origin, start);
	pev(id, pev_view_ofs, view_ofs);	
	xs_vec_add(start, view_ofs, start);
	
		
	new Float:dest[3];	
	pev(id, pev_v_angle, dest);	
	engfunc(EngFunc_MakeVectors, dest);	
	global_get(glb_v_forward, dest);	
	xs_vec_mul_scalar(dest, 9999.0, dest);	
	xs_vec_add(start, dest, dest);
	
	
	engfunc(EngFunc_TraceLine, start, dest, 0, id, 0);
	
	new Float:fDstOrigin[3];
	get_tr2(0, TR_vecEndPos, fDstOrigin);
	

	if(engfunc(EngFunc_PointContents, fDstOrigin) == CONTENTS_SKY)	
		return PLUGIN_CONTINUE;
	
	
	new Float:fNormal[3];
	get_tr2(0, TR_vecPlaneNormal, fNormal);	
	xs_vec_mul_scalar(fNormal, 50.0, fNormal);
	xs_vec_add(fDstOrigin, fNormal, fDstOrigin);
	set_pev(id, pev_origin, fDstOrigin);
	
	uzyl[id] = true;
		
	set_task ( 10.0, "ResetHUD", id )
	set_task ( 10.0, "InfoTel", id )
	
	return PLUGIN_CONTINUE	
}
public ResetHUD(id)	
	uzyl[id] = false;

public InfoTel(id)
	client_print(id, print_center, "Mozesz uzyc Teleportacji");