SA-MP Forums Archive
>>>> Urgent help [Textdrawpros] <<<< - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: >>>> Urgent help [Textdrawpros] <<<< (/showthread.php?tid=524288)



>>>> Urgent help [Textdrawpros] <<<< - SPA - 06.07.2014

Hello,
I'm using Textdraw to show players stats above the health, here is the code:
Код:
new Text:LoggedInAs[MAX_PLAYERS];

//Call functions
public OnPlayerDeath(playerid,killerid,reason)
{
	pInfo[playerid][Deaths]++;
	CheckLoggedInAs(playerid);
	if(killerid != INVALID_PLAYER_ID)
	{
	    CheckLoggedInAs(killerid);
	    pInfo[killerid][Kills]++;
	}
	return 1;
}

//Onplayerconnect
public OnPlayerConnect(playerid)
{
    LoggedInAs[playerid] = TextDrawCreate(300.5,6, " ");
    TextDrawBackgroundColor(LoggedInAs[playerid], 255);
    TextDrawFont(LoggedInAs[playerid], 3);
    TextDrawLetterSize(LoggedInAs[playerid], 0.350000, 1.000000);
    TextDrawColor(LoggedInAs[playerid], -5046017);
    TextDrawSetOutline(LoggedInAs[playerid], 0);
    TextDrawSetProportional(LoggedInAs[playerid], 1);
    TextDrawSetShadow(LoggedInAs[playerid], 1);
    TextDrawSetSelectable(LoggedInAs[playerid], 0);

    
    //+ some other crap for the textdraw. (Proportional etc.)
    CheckLoggedInAs(playerid);
   return 1;
}
//OnPlayerDisconnect
public OnPlayerDisconnect(playerid, reason)
{
    TextDrawDestroy(LoggedInAs[playerid]);
    return 1;
}
//OnPlayerSpawn
public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer(playerid,LoggedInAs[playerid]);
    CheckLoggedInAs(playerid);
    return 1;
}

//Call function
stock CheckLoggedInAs(playerid)
{
	new string[450];
	format(string, sizeof(string), "~g~Kills: %d ~W~- ~r~Deaths: %d ~W~- ~y~DM Score: %d ~P~Rank: %d",pInfo[playerid][Kills],pInfo[playerid][Deaths],GetPlayerScore(playerid),Rank[playerid]);
 	TextDrawSetString(Text:LoggedInAs[playerid], string);
	if(pInfo[playerid][Kills] >= 1000) Rank[ playerid ] = 6;
	else if(pInfo[playerid][Kills] >= 700) Rank[ playerid ] = 5;
	else if(pInfo[playerid][Kills] >= 500) Rank[ playerid ] = 4;
	else if(pInfo[playerid][Kills] >= 200) Rank[ playerid ] = 3;
	else if(pInfo[playerid][Kills] >= 100) Rank[ playerid ] = 2;
	else if(pInfo[playerid][Kills] >= 10) Rank[ playerid ] = 1;
	else if(pInfo[playerid][Kills] >= 0) Rank[ playerid ] = 0;
	return 1;
}
So after 2 days this textdraw disappearing, so i need to restart the server , anyone know the reason? thanks !
EDIT:
I heared that i must put textdraws under onfilterscriptinit, not onplayerconnect, cuz of refresh is that right?
Код:
public OnPlayerConnect(playerid)
{
    LoggedInAs[playerid] = TextDrawCreate(300.5,6, " ");
    TextDrawBackgroundColor(LoggedInAs[playerid], 255);
    TextDrawFont(LoggedInAs[playerid], 3);
    TextDrawLetterSize(LoggedInAs[playerid], 0.350000, 1.000000);
    TextDrawColor(LoggedInAs[playerid], -5046017);
    TextDrawSetOutline(LoggedInAs[playerid], 0);
    TextDrawSetProportional(LoggedInAs[playerid], 1);
    TextDrawSetShadow(LoggedInAs[playerid], 1);
    TextDrawSetSelectable(LoggedInAs[playerid], 0);

    
    //+ some other crap for the textdraw. (Proportional etc.)
    CheckLoggedInAs(playerid);
   return 1;
}



Re: >>>> Urgent help [Textdrawpros] <<<< - BroZeus - 06.07.2014

TextDrawSetString(Text:LoggedInAs[playerid], string);
there is no need of bold part in the above text
use it as
TextDrawSetString(LoggedInAs[playerid], string);

and also in stock CheckLoggedInAs
why are you setting player's rank after setting the text draw string
first set rank then set string

Well this is not the solution to your problem these are just small mistakes i found

Possible cazes of textdraw disappear are--
-If you choose values for y that are less than 1, the first text row will be invisible and only the shadow is visible.

- If the last character in the text is a space (" "), the text will all be blank.

- If part of the text is off-screen, the color of the text will not show, only the shadow (if enabled) will.


Re: >>>> Urgent help [Textdrawpros] <<<< - SPA - 06.07.2014

These mistakes will not solve the problem ,thanks brozeus , anyone can help please?


Re: >>>> Urgent help [Textdrawpros] <<<< - SPA - 06.07.2014

EDITED!


Re: >>>> Urgent help [Textdrawpros] <<<< - LivingLikeYouDo - 06.07.2014

You must put them under OnGameModeInit/OnFilterScriptInit, as I never experienced problems with that.


Re: >>>> Urgent help [Textdrawpros] <<<< - SPA - 06.07.2014

Can you give me example?


Re: >>>> Urgent help [Textdrawpros] <<<< - SPA - 06.07.2014

Well , i can not put the textdraws under onfilterscriptinit or ongamemodeinit because it's need (playerid).


Re: >>>> Urgent help [Textdrawpros] <<<< - ikkentim - 06.07.2014

you are creating textdraws that you do not destroy when not being used anymore. therefore you exceed the textdraw limit. i suggest using per-player textdraws for textdraws unique to every play such as this. AFAIK per-player textdraws are automatically destroyed when the player disconnects.


Re: >>>> Urgent help [Textdrawpros] <<<< - SPA - 06.07.2014

I'm destrying it :
public OnPlayerDisconnect(playerid, reason)
{
TextDrawDestroy(LoggedInAs[playerid]);
return 1;
}
And how to use per-player TextDraw? give me an example please.


Re: >>>> Urgent help [Textdrawpros] <<<< - SPA - 06.07.2014

Bump!