24.11.2013, 17:21
(
Last edited by Bombo; 25/11/2013 at 05:23 PM.
Reason: bugfix
)
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); } } }
Tested: 25.11.2013