//------------------------------------------------------------------------------
// xIcons v1
// By Boylett - Boylett.com
//Скачано с русского портала о скриптинге в pawno   WWW.PAWNO.RU
//------------------------------------------------------------------------------

#if defined _xicons_included
	#endinput
#endif
#define _xicons_included
#pragma library xicons

#include <a_samp>

//------------------------------------------------------------------------------
// Forwards

forward xIcons_Timer();

//------------------------------------------------------------------------------
// Macros

#if !defined MAX_ICONS
#define MAX_ICONS 32
#endif

#if !defined MAP_RADIUS 
#define MAP_RADIUS 160.0
#endif

#if !defined ICON_TIMER
#define ICON_TIMER 212
#endif

//------------------------------------------------------------------------------
// Variables

enum e_xIcons_player
{
	Float:e_xIcons_x,
	Float:e_xIcons_y,
	Float:e_xIcons_z,
	e_xIcons_type,
	e_xIcons_colour,
	bool:e_xIcons_used
}

new
	g_xIcons_player[MAX_PLAYERS][MAX_ICONS][e_xIcons_player];

//------------------------------------------------------------------------------
// Functions

/*
native SetPlayerMapIconStay(playerid,iconid,Float:x,Float:y,Float:z,markertype,colour);
native RemovePlayerMapIconStay(playerid,iconid);
*/

/*xIcons_OnGameModeInit()
{
	SetTimer("xIcons_Timer",ICON_TIMER,1);
}

xIcons_OnPlayerConnect(playerid)
{
	for(new i = 0; i < MAX_ICONS; i++)
	{
	    g_xIcons_player[playerid][i][e_xIcons_used] = false;
	}
}*/

SetPlayerMapIconStay(playerid,iconid,Float:x,Float:y,Float:z,markertype,colour)
{
    g_xIcons_player[playerid][iconid][e_xIcons_used] = true;
    g_xIcons_player[playerid][iconid][e_xIcons_x] = x;
    g_xIcons_player[playerid][iconid][e_xIcons_y] = y;
    g_xIcons_player[playerid][iconid][e_xIcons_z] = z;
    g_xIcons_player[playerid][iconid][e_xIcons_type] = markertype;
    g_xIcons_player[playerid][iconid][e_xIcons_colour] = colour;
    GetPlayerPos(playerid,x,y,z);
    xIcons_SetIconPos(playerid,iconid,x,y);
}

/*RemovePlayerMapIconStay(playerid,iconid)
{
    g_xIcons_player[playerid][iconid][e_xIcons_used] = false;
    RemovePlayerMapIcon(playerid,iconid);
}*/

public xIcons_Timer()
{
	for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
	{
	    if(IsPlayerConnected(playerid))
	    {
		    new
		        Float:x,
		        Float:y,
		        Float:z;
			GetPlayerPos(playerid,x,y,z);
			for(new i = 0; i < MAX_ICONS; i++)
			{
			    if(g_xIcons_player[playerid][i][e_xIcons_used])
			    {
			        xIcons_SetIconPos(playerid,i,x,y);
			    }
			}
			#pragma unused z
		}
	}
}

xIcons_SetIconPos(playerid,iconid,Float:x,Float:y)
{
	new
		Float:magnitude = floatsqroot(floatpower(x - g_xIcons_player[playerid][iconid][e_xIcons_x],2) + floatpower(y - g_xIcons_player[playerid][iconid][e_xIcons_y],2)),
		Float:xmove = (1 / magnitude) * (g_xIcons_player[playerid][iconid][e_xIcons_x] - x) * MAP_RADIUS,
		Float:ymove = (1 / magnitude) * (g_xIcons_player[playerid][iconid][e_xIcons_y] - y) * MAP_RADIUS,
		Float:xdist = g_xIcons_player[playerid][iconid][e_xIcons_x] - x,
		Float:ydist = g_xIcons_player[playerid][iconid][e_xIcons_y] - y;

	if(xdist < 0) xdist = -xdist;
	if(ydist < 0) ydist = -ydist;

	if(xmove < 0)
	{
	    if((-xmove) > xdist) xmove = -xdist;
	}
	else
	{
	    if(xmove > xdist) xmove = xdist;
	}

	if(ymove < 0)
	{
	    if((-ymove) > ydist) ymove = -ydist;
	}
	else
	{
	    if(ymove > ydist) ymove = ydist;
	}

    x += xmove;
    y += ymove;

    SetPlayerMapIcon(
		playerid,
		iconid,
		x,
		y,
		g_xIcons_player[playerid][iconid][e_xIcons_z],
		g_xIcons_player[playerid][iconid][e_xIcons_type],
		g_xIcons_player[playerid][iconid][e_xIcons_colour]
	);
}
