#include <a_samp>
#include <a_actor>
#include <streamer>

forward SetActorParams(actorid, virt, interior, color, bool:invulnerable, Float:actorHealth, name[], info[], namevisibility);
forward SpawnActor(actorid, Float:x, Float:y, Float:z, Float:angle, virt);
forward SetActorChatBubble(actorid, text[], color, Float:drawdistance);
forward LocalActorMessage(Float:dist, actorid, color, message[]);
forward DestroyActorParams(actorid);


enum aInfo
{
	Text3D:a3DChat,
	Text3D:a3DAction,
	Text3D:a3DName,
	Text3D:a3DInfo,
	Float:aSpawnX,
	Float:aSpawnY,
	Float:aSpawnZ,
	Float:aSpawnA,
	Float:aHealth,
	aColor,
	aMapIcon,
	aVirt,
	aInt,
	aSkin,
	bool:aInvulnerable,
 	aName[64],
 	aText[128],
 	aNameVisibility
}
new ActorInfo[MAX_ACTORS][aInfo];

public SetActorParams(actorid, virt, interior, color, bool:invulnerable, Float:actorHealth, name[],info[], namevisibility)
{
	new Float:x, Float:y, Float:z;
	GetActorPos(actorid, x, y, z);
	new Float:angle;
	GetActorFacingAngle(actorid, angle);
	ActorInfo[actorid][aSpawnX] = x;
	ActorInfo[actorid][aSpawnY] = y;
	ActorInfo[actorid][aSpawnZ] = z;
	ActorInfo[actorid][aSpawnA] = angle;
	ActorInfo[actorid][aColor] = color;
	ActorInfo[actorid][aVirt] = virt;
	ActorInfo[actorid][aInt] = interior;
	ActorInfo[actorid][aInvulnerable] = invulnerable;
	ActorInfo[actorid][aHealth] = actorHealth;
	ActorInfo[actorid][aNameVisibility] = namevisibility;
	SetActorVirtualWorld(actorid, virt);
	SetActorInvulnerable(actorid, invulnerable);
	SetActorHealth(actorid, actorHealth);
	format(ActorInfo[actorid][aName], 64, "%s", name);
	format(ActorInfo[actorid][aText], 128, "%s", info);
	ClearActorAnimations(actorid);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DName]);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DInfo]);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DChat]);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DAction]);
	DestroyDynamicMapIcon(ActorInfo[actorid][aMapIcon]);
	ActorInfo[actorid][a3DName] = CreateDynamic3DTextLabel(name,0xFFFFFFFF,x, y, z+1.2,40.0,INVALID_PLAYER_ID,INVALID_PLAYER_ID,namevisibility,virt,interior,-1,40.0);
	ActorInfo[actorid][a3DInfo] = CreateDynamic3DTextLabel(info,0xFFFFFFFF,x, y, z,40.0,INVALID_PLAYER_ID,INVALID_PLAYER_ID,namevisibility,virt,interior,-1,40.0);
	if(virt == 0) { ActorInfo[actorid][aMapIcon] = CreateDynamicMapIcon(x, y, z, 0, color, virt, interior, -1, 40.0); }
	return 1;
}

public DestroyActorParams(actorid)
{
	ActorInfo[actorid][aSpawnX] = 0;
	ActorInfo[actorid][aSpawnY] = 0;
	ActorInfo[actorid][aSpawnZ] = 0;
	ActorInfo[actorid][aSpawnA] = 0;
	ActorInfo[actorid][aColor] = 0;
	ActorInfo[actorid][aVirt] = 25;
	ActorInfo[actorid][aInt] = 0;
	ActorInfo[actorid][aInvulnerable] = false;
	ActorInfo[actorid][aHealth] = 1;
	ActorInfo[actorid][aNameVisibility] = 1;
	SetActorVirtualWorld(actorid, 25);
	SetActorInvulnerable(actorid, 0);
	SetActorHealth(actorid, 1);
	format(ActorInfo[actorid][aName], 64, "");
	format(ActorInfo[actorid][aText], 128, "");
	ClearActorAnimations(actorid);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DChat]);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DAction]);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DName]);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DInfo]);
	DestroyDynamicMapIcon(ActorInfo[actorid][aMapIcon]);
	return 1;
}
public SpawnActor(actorid, Float:x, Float:y, Float:z, Float:angle, virt)
{
	//new name_string[64],info_string[128];
    SetActorPos(actorid,x, y, z);
    SetActorVirtualWorld(actorid, virt);
    SetActorFacingAngle(actorid, angle);
	/*format(name_string, sizeof(name_string), "%s", ActorInfo[actorid][aName]);
	format(info_string, sizeof(info_string), "%s", ActorInfo[actorid][aText]);
    SetActorParams(actorid, virt, ActorInfo[actorid][aInt], ActorInfo[actorid][aColor],ActorInfo[actorid][aInvulnerable], ActorInfo[actorid][aHealth], name_string, info_string, ActorInfo[actorid][aNameVisibility]);*/
    return 1;
}
public LocalActorMessage(Float:dist, actorid, color, message[])
{
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DChat]);
	if(!IsValidActor(actorid)) return print("Этого актёра не существует!");
    new virt = GetActorVirtualWorld(actorid);
	new Float:x, Float:y, Float:z;
	GetActorPos(actorid, x, y, z);
	new name_string[256];
	for(new i = 0, j = MAX_PLAYERS; i < j; i++)
	{
	    if(IsPlayerConnected(i))
		{
			if(IsActorStreamedIn(actorid, i))
			{
				format(name_string, sizeof(name_string), "%s - (%s) [%d]",message,ActorInfo[actorid][aName],actorid);
				SendClientMessage(i, color, name_string);
			}
		}
	}
	ApplyActorAnimation(actorid, "PED","IDLE_CHAT",4.1,1,1,1,1,1);
	ActorInfo[actorid][a3DChat] = CreateDynamic3DTextLabel(name_string, color, x, y, z+1.1, dist,INVALID_PLAYER_ID,INVALID_PLAYER_ID,1,virt,-1,-1,dist);
	SetTimerEx("DestroyActorMessage",3000,false,"d",actorid);
	return 1;
}
public SetActorChatBubble(actorid, text[], color, Float:drawdistance)
{
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DAction]);
	if(!IsValidActor(actorid)) return print("Этого актёра не существует!");
    new virt = GetActorVirtualWorld(actorid);
	new Float:x, Float:y, Float:z;
	GetActorPos(actorid, x, y, z);
	new name_string[256];
	for(new i = 0, j = MAX_PLAYERS; i < j; i++)
	{
	    if(IsPlayerConnected(i))
		{
			if(IsActorStreamedIn(actorid, i))
			{
				format(name_string, sizeof(name_string), "%s[%d]: %s", ActorInfo[actorid][aName],actorid,text);
				SendClientMessage(i, color, name_string);
			}
		}
	}
	ActorInfo[actorid][a3DAction] = CreateDynamic3DTextLabel(name_string, color, x, y, z+0.5, drawdistance,INVALID_PLAYER_ID,INVALID_PLAYER_ID,1,virt,-1,-1,drawdistance);
	SetTimerEx("DestroyActorChatBubble",3000,false,"d",actorid);
	return 1;
}
stock SetActorColor(actorid, color)
{
	if(!IsValidActor(actorid)) return print("Этого актёра не существует!");
	//--------------- Old data -----------
	new name_string[64],info_string[128];
    new virt = GetActorVirtualWorld(actorid);
    new skin = ActorInfo[actorid][aSkin];
    new interior = ActorInfo[actorid][aInt];
	new Float:x, Float:y, Float:z;
	GetActorPos(actorid, x, y, z);
	new Float:angle;
	GetActorFacingAngle(actorid, angle);
	new Float:actorHealth;
    GetActorHealth(actorid, actorHealth);
	new bool:invulnerable = false;
    if(IsActorInvulnerable(actorid) == 1) { invulnerable = true; }
    if(IsActorInvulnerable(actorid) == 0) { invulnerable = false; }
    DestroyActor(actorid);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DName]);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DInfo]);
	DestroyDynamicMapIcon(ActorInfo[actorid][aMapIcon]);
	format(name_string, sizeof(name_string), "%s", ActorInfo[actorid][aName]);
	format(info_string, sizeof(info_string), "%s", ActorInfo[actorid][aText]);
	//--------------- New data -----------
	actorid = CreateActor(skin, x, y, z, angle);
	SetActorParams(actorid, virt, interior, color, invulnerable, actorHealth, name_string, info_string, ActorInfo[actorid][aNameVisibility]);
	return 1;
}
stock SetActorSkin(actorid,skin)
{
	if(!IsValidActor(actorid)) return print("Этого актёра не существует!");
	//--------------- Old data -----------
	new name_string[64],info_string[128];
	new Float:x, Float:y, Float:z;
	GetActorPos(actorid, x, y, z);
	new Float:angle;
	GetActorFacingAngle(actorid, angle);
    new virt = GetActorVirtualWorld(actorid);
    new member = ActorInfo[actorid][aMember];
    new interior = ActorInfo[actorid][aInt];
	new Float:actorHealth;
    GetActorHealth(actorid, actorHealth);
	new bool:invulnerable = false;
    if(IsActorInvulnerable(actorid) == 1) {invulnerable = true;}
    if(IsActorInvulnerable(actorid) == 0) {invulnerable = false;}
    DestroyActor(actorid);
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DName]);
	DestroyDynamicMapIcon(ActorInfo[actorid][aMapIcon]);
	format(name_string, sizeof(name_string), "%s", ActorInfo[actorid][aName]);
	format(info_string, sizeof(info_string), "%s", ActorInfo[actorid][aText]);
	//--------------- New data -----------
	actorid = CreateActor(skin, x, y, z, angle);
	SetActorParams(actorid, virt, interior, member, invulnerable, actorHealth, name_string, info_string, ActorInfo[actorid][aNameVisibility]);
	return 1;
}
forward DestroyActorMessage(actorid);
public DestroyActorMessage(actorid)
{
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DChat]);
	ClearActorAnimations(actorid);
	return 1;
}
forward DestroyActorChatBubble(actorid);
public DestroyActorChatBubble(actorid)
{
	DestroyDynamic3DTextLabel(ActorInfo[actorid][a3DAction]);
	ClearActorAnimations(actorid);
	return 1;
}