[FilterScript] Animated TextDraw(s)
#1

LiveText


Author: Bombo
Version: 1.1.2


Start in OnPlayerConnect()
Finish in OnPlayerSpawn()


Code:
// LiveText v1.1.2 by Bombo

#include <a_samp>

#include "../include/gl_common.inc"

#define LIVE_TEXT_LEN 15 //you MUST set the text length

//the text
new LiveTextString[] = "forum.sa-mp.com";

//position (posx, posy) and interval between chars (width)
//are set in CreateLiveText()
new Float:posx, Float:posy, Float:width;

new PlayerText:start_b[MAX_PLAYERS*LIVE_TEXT_LEN];
new Float:site_size[MAX_PLAYERS*LIVE_TEXT_LEN];
new Float:add[MAX_PLAYERS*LIVE_TEXT_LEN];
new bool:IsPlayerSpawned[MAX_PLAYERS];
new TimerMove;
new Float:size_add;

forward TimerMoveText();

public OnFilterScriptInit()
{
    new i;

    print("\n--------------------------------------");
    print(" LiveText v1.1.2 by Bombo");
    print("--------------------------------------\n");

	for(i = 0; i < MAX_PLAYERS; ++i)
      IsPlayerSpawned[i] = false;

    for(i = 0; i < MAX_PLAYERS; ++i)
    {
      if(IsPlayerConnected(i) && !IsPlayerSpawned[i])
      {
        CreateLiveText(i);
        ShowLiveText(i);
      }
    }

    TimerMove = SetTimer("TimerMoveText", 50, true);
       
    return 1;
}

public OnFilterScriptExit()
{
    new i;

    for(i = 0; i < MAX_PLAYERS; ++i)
    {
        if(IsPlayerConnected(i))
         DestroyLiveText(i);
    }

    KillTimer(TimerMove);
    
    return 1;
}

CreateLiveText(i) //Is called in OnFilterScriptInit()
{
  new j, k;
  new str[2];

  width = 16.0;
  posx = 400.0;
  posy = 420.0;
  size_add = 0.2;
  
  str[1] = '\0';

  for(j = 0; j < LIVE_TEXT_LEN; ++j)
  {
    format(str, 2, "%c", LiveTextString[j]);
    start_b[i*LIVE_TEXT_LEN+j] = CreatePlayerTextDraw(i,posx+width*j,posy,str);
  }

  //start position calculation
  for(j = 0; j < LIVE_TEXT_LEN; ++j)
  {
    add[i*LIVE_TEXT_LEN+j] = size_add;
    site_size[i*LIVE_TEXT_LEN+j] = 1 + size_add + j%2;
    
    for(k = 0; k < j; ++k)
    {
      if(site_size[i*LIVE_TEXT_LEN+j] > 4 || site_size[i*LIVE_TEXT_LEN+j] < 0.01)
      {
        if(site_size[i*LIVE_TEXT_LEN+j] > 4)
          site_size[i*LIVE_TEXT_LEN+j] = 4;
        else
          site_size[i*LIVE_TEXT_LEN+j] = 0.01;

        if(add[i*LIVE_TEXT_LEN+j] == size_add)
          add[i*LIVE_TEXT_LEN+j] = -size_add;
        else
          add[i*LIVE_TEXT_LEN+j] = size_add;
      }
      site_size[i*LIVE_TEXT_LEN+j] = site_size[i*LIVE_TEXT_LEN+j] + add[i*LIVE_TEXT_LEN+j];
    }
  }

  for(j = 0; j < LIVE_TEXT_LEN; ++j)
  {
    PlayerTextDrawAlignment(i, start_b[i*LIVE_TEXT_LEN+j],0);
    PlayerTextDrawBackgroundColor(i, start_b[i*LIVE_TEXT_LEN+j],0x00705F2F);
    PlayerTextDrawFont(i, start_b[i*LIVE_TEXT_LEN+j],2);
    PlayerTextDrawLetterSize(i, start_b[i*LIVE_TEXT_LEN+j],0.5,1.0);
    PlayerTextDrawColor(i, start_b[i*LIVE_TEXT_LEN+j],0xFFFF00FF);
    PlayerTextDrawSetOutline(i, start_b[i*LIVE_TEXT_LEN+j],1);
    PlayerTextDrawSetProportional(i, start_b[i*LIVE_TEXT_LEN+j],1);
    PlayerTextDrawSetShadow(i, start_b[i*LIVE_TEXT_LEN+j],3);
  }
}

MoveLiveText(i) //Is called in TimerMoveText()
{
  new j;
  new str[2];

  str[1] = '\0';

  HideLiveText(i);
  DestroyLiveText(i);
  
  for(j = 0; j < LIVE_TEXT_LEN; ++j)
  {
    format(str, 2, "%c", LiveTextString[j]);
    start_b[i*LIVE_TEXT_LEN+j] = CreatePlayerTextDraw(i,posx+width*j,posy+site_size[i*LIVE_TEXT_LEN+j]*site_size[i*LIVE_TEXT_LEN+j]+1,str);
  }

  for(j = 0; j < LIVE_TEXT_LEN; ++j)
  {
    //next coordinates colculation
    site_size[i*LIVE_TEXT_LEN+j] = site_size[i*LIVE_TEXT_LEN+j] + add[i*LIVE_TEXT_LEN+j];
    if(site_size[i*LIVE_TEXT_LEN+j] > 4 || site_size[i*LIVE_TEXT_LEN+j] < 0.01)
    {
      if(site_size[i*LIVE_TEXT_LEN+j] > 4)
        site_size[i*LIVE_TEXT_LEN+j] = 4;
      else
        site_size[i*LIVE_TEXT_LEN+j] = 0.01;

      if(add[i*LIVE_TEXT_LEN+j] == size_add)
          add[i*LIVE_TEXT_LEN+j] = -size_add;
      else
        add[i*LIVE_TEXT_LEN+j] = size_add;
    }

    PlayerTextDrawAlignment(i, start_b[i*LIVE_TEXT_LEN+j],0);
    PlayerTextDrawBackgroundColor(i, start_b[i*LIVE_TEXT_LEN+j],0x00705F2F);
    PlayerTextDrawFont(i, start_b[i*LIVE_TEXT_LEN+j],2);
//    PlayerTextDrawLetterSize(i, start_b[i*LIVE_TEXT_LEN+j],0.5,1.0+site_size[i*LIVE_TEXT_LEN+j]);
    PlayerTextDrawColor(i, start_b[i*LIVE_TEXT_LEN+j],0xFFFF00FF);
    PlayerTextDrawSetOutline(i, start_b[i*LIVE_TEXT_LEN+j],1);
    PlayerTextDrawSetProportional(i, start_b[i*LIVE_TEXT_LEN+j],1);
    PlayerTextDrawSetShadow(i, start_b[i*LIVE_TEXT_LEN+j],3);
  }
  
  ShowLiveText(i);
}

ShowLiveText(i)
{
  new j;

  for(j = 0; j < LIVE_TEXT_LEN; ++j)
    PlayerTextDrawShow(i, start_b[i*LIVE_TEXT_LEN+j]);
}

HideLiveText(i)
{
  new j;

  for(j = 0; j < LIVE_TEXT_LEN; ++j)
    PlayerTextDrawHide(i, start_b[i*LIVE_TEXT_LEN+j]);
}

DestroyLiveText(i) //Вызов в OnFilterScriptExit()
{
  new j;

  for(j = 0; j < LIVE_TEXT_LEN; ++j)
    PlayerTextDrawDestroy(i,start_b[i*LIVE_TEXT_LEN+j]);
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    CreateLiveText(playerid);
    ShowLiveText(playerid);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    IsPlayerSpawned[playerid] = true;
    DestroyLiveText(playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    IsPlayerSpawned[playerid] = false;
    DestroyLiveText(playerid);
    return 1;
}

public TimerMoveText()
{
  new i;

  for(i = 0; i < MAX_PLAYERS; ++i)
  {
    if(IsPlayerConnected(i) && !IsPlayerSpawned[i])
    {
      MoveLiveText(i);
    }
  }
}
The result:
Tested: 25.11.2013
Reply
#2

Awesome +REP
Reply
#3

Well done. Looks neat.
Reply
#4

have bugs, not appear when you enter the server.
Reply
#5

Keep it up
Reply
#6

Nice.
Reply
#7

That's pretty bad ass!
Reply
#8

Quote:
Originally Posted by xBaDaSSx
View Post
have bugs, not appear when you enter the server.
Always or sometimes? Does anybody have the same bug?
Reply
#9

It probably happened when he loaded the FS in his server. So it should be like this:
pawn Code:
public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" LiveText v1.1 by Bombo");
    print("--------------------------------------\n");

    for(new i = 0; i < MAX_PLAYERS; ++i)
    {
        if(IsPlayerConnected(i))
        {
            CreateLiveText(i);
            ShowLiveText(i);
        }
    }

    TimerMove = SetTimer("TimerMoveText", 50, true);
    return 1;
}
Just tested it and it works pretty good and smooth
Reply
#10

Ah, unique idea. Good work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)