Šta (ne) treba raditi sa PlayerTDovima (PlayerText)

Započeo PabloK, Maj 12, 2020, 09:06:47 PRE PODNE

prethodna tema - sledeća tema

0 članova i 1 gost pregledaju ovu temu.

Player Textdraws


Šta su player textdraw-ovi?
Postoje dve vrste textdrawova, Global Textdraw-ovi koji bi trebali da budu isti za svakog igrača (neretko vidim bad practice pa se spama format pre svakog prikazivanja umesto da se fino kreira PlayerTextdraw) za razliku od PlayerTextDraw-ova koji su "unikatni" za svakog igrača (bilo da je tekst, pozicija ili bilo šta od elemenata drugačije).


Šta (ne) treba raditi sa nijma?
Primetio sam da mnogi ovde rade ovo:
[pawn]new PlayerText: someTextDraw[MAX_PLAYERS][100] = {INVALID_PLAYER_TEXT_DRAW, ...};

createSomeTextDraw(playerid)
{
   // someTextDraw[playerid] = CreatePlayerTextDraw(playerid, Float:x, Float:y, text[])
}

public OnPlayerConnect(playerid)
{
   // I ako preprucujem da se ovakve stvari kreiraju,
   // iskljucivo kada su potrebne tj kada su uslovi ispunjeni
   createSomeTextDraw(playerid);

   return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
   for(new i = 0; i < 100; i++)
      PlayerTextDrawDestroy(playerid, someTextDraw[playerid]), someTextDraw[playerid] = INVALID_PLAYER_TEXT_DRAW;

   return 1;
}[/pawn]
Ovde je callback OnPlayerDisconnect u potpunosti beskoristan - razlog?
Player TextDraw-ovi se automatski destroyaju kada igrač izađe sa servera, znači bespotrebno je da imate po desetine ovakvih loopova jer će TextDraw svakako biti uništen.



Baj d vej
Ne znam koliko znate, ali postoji YSF koji ima bogami fin TextDraw managment jer u sebi sazdrži funkcije kao što su:
[pawn]// Textdraw - Global
native IsValidTextDraw(Text:textdrawid);
native IsTextDrawVisibleForPlayer(playerid, Text:textdrawid);
native TextDrawGetString(Text:textdrawid, text[], len = sizeof(text));
native TextDrawSetPos(Text:textdrawid, Float:fX, Float:fY); // You can change textdraw pos with it, but you need to use TextDrawShowForPlayer() after that
native TextDrawGetLetterSize(Text:textdrawid, &Float:fX, &Float:fY = 0.0);
native TextDrawGetTextSize(Text:textdrawid, &Float:fX, &Float:fY = 0.0);
native TextDrawGetPos(Text:textdrawid, &Float:fX, &Float:fY = 0.0);
native TextDrawGetColor(Text:textdrawid);
native TextDrawGetBoxColor(Text:textdrawid);
native TextDrawGetBackgroundColor(Text:textdrawid);
native TextDrawGetShadow(Text:textdrawid);
native TextDrawGetOutline(Text:textdrawid);
native TextDrawGetFont(Text:textdrawid);
native TextDrawIsBox(Text:textdrawid);
native TextDrawIsProportional(Text:textdrawid);
native TextDrawIsSelectable(Text:textdrawid);
native TextDrawGetAlignment(Text:textdrawid);
native TextDrawGetPreviewModel(Text:textdrawid);
native TextDrawGetPreviewRot(Text:textdrawid, &Float:fRotX, &Float:fRotY = 0.0, &Float:fRotZ = 0.0, &Float:fZoom = 0.0);
native TextDrawGetPreviewVehCol(Text:textdrawid, &color1, &color2 = 0);
native TextDrawSetStringForPlayer(Text:textdrawid, playerid, const string[], {Float,_}:...);

// Textdraw - Player
native IsValidPlayerTextDraw(playerid, PlayerText:textdrawid);
native IsPlayerTextDrawVisible(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetString(playerid, PlayerText:textdrawid, text[], len = sizeof(text));
native PlayerTextDrawSetPos(playerid, PlayerText:textdrawid, Float:fX, Float:fY);
native PlayerTextDrawGetLetterSize(playerid, PlayerText:textdrawid, &Float:fX, &Float:fY = 0.0);
native PlayerTextDrawGetTextSize(playerid, PlayerText:textdrawid, &Float:fX, &Float:fY = 0.0);
native PlayerTextDrawGetPos(playerid, PlayerText:textdrawid, &Float:fX, &Float:fY = 0.0);
native PlayerTextDrawGetColor(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetBoxColor(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetBackgroundCol(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetShadow(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetOutline(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetFont(playerid, PlayerText:textdrawid);
native PlayerTextDrawIsBox(playerid, PlayerText:textdrawid);
native PlayerTextDrawIsProportional(playerid, PlayerText:textdrawid);
native PlayerTextDrawIsSelectable(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetAlignment(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetPreviewModel(playerid, PlayerText:textdrawid);
native PlayerTextDrawGetPreviewRot(playerid, PlayerText:textdrawid, &Float:fRotX, &Float:fRotY = 0.0, &Float:fRotZ = 0.0, &Float:fZoom = 0.0);
native PlayerTextDrawGetPreviewVehCol(playerid, PlayerText:textdrawid, &color1, &color2 = 0);[/pawn]
Dok ne prestanete da gledate front i zapravo malo pogledate svoj back-end od vas skriptera nikada neće biti niti bilo čega drugoga.