Untitled - MARKUP 5.18 KB
                                
                                    #include <amxmodx>
#include <fakemeta>
#include <posmv>

#define PLAYERS 18
#define PREFIX "EasyBlock"

#define VERSION "0.1"

new spriteBeacon;
new bool:g_bEnabled[33];
new  const g_sSound[] = "radar/detector.wav";

public plugin_init() {
	register_plugin("Detektor", VERSION, "diablix")
	register_forward(FM_PlayerPreThink, "fwPreThink");
	
	set_task(2.75, "taskCheck4Beacon", 0, _, _, "b");
	
	addSayCommand("/detektor", "cmdDetektor");
	addSayCommand("/radar", "cmdDetektor");
}

public cmdDetektor(id){
	g_bEnabled[id] = !g_bEnabled[id];
	
	Print(id, "Detektor zostal %s", g_bEnabled[id] ? "wlaczony" : "wylaczony");
	
	return 1;
}

public plugin_precache(){
	spriteBeacon = engfunc(EngFunc_PrecacheModel, "sprites/beacon.spr");
	
	engfunc(EngFunc_PrecacheSound, g_sSound);
}

public client_connect(id) g_bEnabled[id] = true;

public fwPreThink(id){
	if(!g_bEnabled[id])	return 1;
	if(!is_user_alive(id)) 	return 1;
	
	new iClosestPlayer = getClosestPlayer(id, IGNORUJ_SWOICH);
	if(is_user_connected(iClosestPlayer) && is_user_alive(iClosestPlayer)){
		new Float:flRange = fm_entity_range(id, iClosestPlayer);
		
		if(flRange > 2000.0) return 1;
		
		new iColor[3], sMetry[7];
		add(sMetry, sizeof sMetry - 1, "metr");
		dodajOw(flRange, sMetry, sizeof sMetry - 1);
		getHudColorsByRange(flRange, iColor);
		
		set_hudmessage(iColor[0], iColor[1], iColor[2], 0.40, 0.02, 0, 0.1, 0.01, 0.1, 0.1, 3);
		show_hudmessage(id, "^tWrog jest w poblizu^n ^t^t^t^t%.1f %s", flRange / 100.0, sMetry);
	}
	
	return 0;
}

public taskCheck4Beacon(){
	new iPlayers[32], iNum;
	get_players(iPlayers, iNum, "ae", "TERRORIST");
	
	if(iNum == 1){
		for(new i = 0 ; i < iNum; i++){
			createBeacon(iPlayers[i]);
		}
	}
}

stock createBeacon(index)
{	
	if(get_playersnum() >= 3)
	{	
		new Float:flOrigin[3];
		pev(index, pev_origin, flOrigin);
	
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
		write_byte(TE_BEAMCYLINDER);
		engfunc(EngFunc_WriteCoord, flOrigin[0]);
		engfunc(EngFunc_WriteCoord, flOrigin[1]);
		engfunc(EngFunc_WriteCoord, flOrigin[2] - 20.0);
		engfunc(EngFunc_WriteCoord, flOrigin[0]);   
		engfunc(EngFunc_WriteCoord, flOrigin[1]);
		engfunc(EngFunc_WriteCoord, flOrigin[2] + 200.0);
		write_short(spriteBeacon);
		write_byte(0);
		write_byte(1);
		write_byte(6);
		write_byte(2);       
		write_byte(1);      
		write_byte(255);     
		write_byte(40);    
		write_byte(10);
		write_byte(200);
		write_byte(6);
		message_end();
	
		emit_sound(index, CHAN_STATIC, g_sSound, 1.0, ATTN_NORM, 0, PITCH_NORM);
	}
	return PLUGIN_HANDLED;		
}

stock getHudColorsByRange(Float:flRange, iColor[3]){
	switch(floatround(flRange)){
		case 0..400: 		iColor = { 255, 0, 0 };
		case 401..1000: 	iColor = { 255, 255, 0 };
		case 1001..2000: 	iColor = { 0, 255, 0 };
		default: 		iColor = { 0, 255, 0 };
	}
	return 1;
}

stock Float:fm_entity_range(ent1, ent2) {
	new Float:origin1[3], Float:origin2[3];
	pev(ent1, pev_origin, origin1);
	pev(ent2, pev_origin, origin2);
	
	return get_distance_f(origin1, origin2);
}

stock dodajOw(Float:flRange, sTablica[], iLen){
	new iRange = floatround(flRange);
	new sToAdd[3];
	
	formatex(sToAdd, sizeof sToAdd - 1, "%s", iRange <= 199 ? "a" : "ow");
	
	add(sTablica, iLen, sToAdd);
}

addSayCommand(const s_Command[], const s_Handle[]){
	new s_TempCommand[64];
	formatex(s_TempCommand, sizeof s_TempCommand - 1, "say %s", s_Command);
	register_clcmd(s_TempCommand, s_Handle);
	formatex(s_TempCommand, sizeof s_TempCommand - 1, "say_team %s", s_Command);
	register_clcmd(s_TempCommand, s_Handle);
}
stock Print(id, const message_fmt[], any:...)
{
	static i; i = id ? id : GetPlayer();
	if ( !i ) return;
	
	static message[256], len;
	len = formatex(message, charsmax(message), "^4[%s]^3 ", PREFIX);
	vformat(message[len], charsmax(message) - len, message_fmt, 3);
	message[192] = 0;
	
	static msgid_SayText;
	if ( !msgid_SayText ) msgid_SayText = get_user_msgid("SayText");
	
	static const team_names[][] = {	"", "TERRORIST", "CT", "SPECTATOR" };
	
	static team; team = get_user_team(i);
	TeamInfo(i, id, team_names[0]);
	
	message_begin(id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgid_SayText, _, id);
	write_byte(i);
	write_string(message);
	message_end();
	
	TeamInfo(i, id, team_names[team]);
}

TeamInfo(receiver, sender, team[])
{
	static msgid_TeamInfo;
	if ( !msgid_TeamInfo ) msgid_TeamInfo = get_user_msgid("TeamInfo");
	
	message_begin(sender ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgid_TeamInfo, _, sender);
	write_byte(receiver);
	write_string(team);
	message_end();
}

GetPlayer()
{
	for ( new id = 1; id <= PLAYERS; id++ )
	{
		if ( !is_user_connected(id) ) continue;
		return id;
	}
	return 0;
}
                                
                            

Paste Hosted With By Wklejamy.pl