>>>> Urgent help [Textdrawpros] <<<<
#1

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;
}
Reply
#2

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.
Reply
#3

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

EDITED!
Reply
#5

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

Can you give me example?
Reply
#7

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

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.
Reply
#9

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.
Reply
#10

Bump!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)