SA-MP Forums Archive
Stats TextDraw Bug - 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: Stats TextDraw Bug (/showthread.php?tid=521997)



Stats TextDraw Bug [+REP's!] - SPA - 25.06.2014

Hello, I'v added to my server stats such as kills deaths,score, i'v added it under onplayerupdate or even set a timer, its working for few mins , then when i get more players and relog , the stats is disappearing, is that a bug or there are wrong something ?


Re: Stats TextDraw Bug - RenovanZ - 25.06.2014

May I see your code ?


Re: Stats TextDraw Bug - SPA - 25.06.2014

Код:
/*
	**************************
	Filtsript version v3.3  **
	**************************
*/


#include <a_samp>


enum PlayerDB
{
	Kills,
	Deaths,
	bool:Box,
}
new PlayerData[MAX_PLAYERS][PlayerDB];
forward StatsInfromation();


new Text: PlayerStats[MAX_PLAYERS];
new Text: Textdraw1;



public OnFilterScriptInit()
{
	
	SetTimer("StatsInfromation",1000 , 1);
 	for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
 	{
	    PlayerStats[playerid] = TextDrawCreate(231.000000,405.000000,"-");
	    Textdraw1 = TextDrawCreate(260.000000,391.000000,"STATS");
	    TextDrawUseBox(PlayerStats[playerid],1);
	    TextDrawBoxColor(PlayerStats[playerid],0xffffff33);
	    TextDrawTextSize(PlayerStats[playerid],389.000000,119.000000);
	    TextDrawAlignment(PlayerStats[playerid],0);
	    TextDrawAlignment(Textdraw1,0);
	    TextDrawBackgroundColor(PlayerStats[playerid],0x000000ff);
	    TextDrawBackgroundColor(Textdraw1,0xff000033);
	    TextDrawFont(PlayerStats[playerid],2);
	    TextDrawLetterSize(PlayerStats[playerid],0.399999,1.200000);
	    TextDrawFont(Textdraw1,2);
	    TextDrawLetterSize(Textdraw1,0.799999,1.300000);
	    TextDrawColor(PlayerStats[playerid],0xffffffff);
	    TextDrawColor(Textdraw1,0xffffffff);
	    TextDrawSetOutline(PlayerStats[playerid],1);
	    TextDrawSetOutline(Textdraw1,1);
	    TextDrawSetProportional(PlayerStats[playerid],1);
	    TextDrawSetProportional(Textdraw1,1);
	    TextDrawSetShadow(PlayerStats[playerid],1);
	    TextDrawSetShadow(Textdraw1,1);

	}
	return 1;
}

//______________________________________________________________________________
public OnFilterScriptExit()
{
    for(new i = 0;i < MAX_PLAYERS; i++)
    {
        TextDrawDestroy(PlayerStats[i]);
    }
    TextDrawDestroy(Textdraw1);
	return 1;
}
//______________________________________________________________________________
public OnPlayerConnect(playerid)
{


	TextDrawShowForPlayer(playerid, PlayerStats[playerid]);
	TextDrawShowForPlayer(playerid, Textdraw1);

	return 1;
}
//______________________________________________________________________________



//______________________________________________________________________________
public StatsInfromation()
{
    new str[128];
	for(new i=0;i<MAX_PLAYERS;i++)
	{
		if (IsPlayerConnected(i))
	    {
	        format(str, sizeof(str), "Kills: %d - Deaths: %d" , PlayerData[i][Kills], PlayerData[i][Deaths]);
	        TextDrawSetString(PlayerStats[i],str);
    	}
	}
	return 1;
}
//______________________________________________________________________________
//                            2009/2010 ©



Re: Stats TextDraw Bug - RenovanZ - 25.06.2014

Which textdraw is disappearing ? Both of them ?


Respuesta: Stats TextDraw Bug - SickAttack - 25.06.2014

Create per-player textdraws instead of what your doing and you don't even need to use a timer, just update the textdraw every time the stat changes.

Example:
pawn Код:
new PlayerText:Time[MAX_PLAYERS];

Time[playerid] = CreatePlayerTextDraw(playerid, 554.000000, 205.000000, "~g~05:00");
PlayerTextDrawAlignment(playerid, Time[playerid], 2);
PlayerTextDrawBackgroundColor(playerid, Time[playerid], 22);
PlayerTextDrawFont(playerid, Time[playerid], 2);
PlayerTextDrawLetterSize(playerid, Time[playerid], 0.560000, 6.100000);
PlayerTextDrawColor(playerid, Time[playerid], -1);
PlayerTextDrawSetOutline(playerid, Time[playerid], 1);
PlayerTextDrawSetProportional(playerid, Time[playerid], 1);
PlayerTextDrawSetSelectable(playerid, Time[playerid], 0);

// To update the textdraw
new string[128];
format(string, sizeof (string), "~g~%02d:%02d", minutes, seconds);
PlayerTextDrawSetString(playerid, Time[playerid], string);



Re: Stats TextDraw Bug - SPA - 25.06.2014

Quote:
Originally Posted by RenovanZ
Посмотреть сообщение
Which textdraw is disappearing ? Both of them ?
Both of them, i must restart server to back it.


Re: Respuesta: Stats TextDraw Bug - SPA - 25.06.2014

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Create per-player textdraws instead of what your doing and you don't even need to use a timer, just update the textdraw every time the stat changes.

Example:
pawn Код:
new PlayerText:Time[MAX_PLAYERS];

Time[playerid] = CreatePlayerTextDraw(playerid, 554.000000, 205.000000, "~g~05:00");
PlayerTextDrawAlignment(playerid, Time[playerid], 2);
PlayerTextDrawBackgroundColor(playerid, Time[playerid], 22);
PlayerTextDrawFont(playerid, Time[playerid], 2);
PlayerTextDrawLetterSize(playerid, Time[playerid], 0.560000, 6.100000);
PlayerTextDrawColor(playerid, Time[playerid], -1);
PlayerTextDrawSetOutline(playerid, Time[playerid], 1);
PlayerTextDrawSetProportional(playerid, Time[playerid], 1);
PlayerTextDrawSetSelectable(playerid, Time[playerid], 0);

// To update the textdraw
new string[128];
format(string, sizeof (string), "~g~%02d:%02d", minutes, seconds);
PlayerTextDrawSetString(playerid, Time[playerid], string);
Thanks + rep , but where to add both of functions? onplayerupdate?


Re: Respuesta: Stats TextDraw Bug - RenovanZ - 25.06.2014

Quote:
Originally Posted by SPA
Посмотреть сообщение
Thanks + rep , but where to add both of functions? onplayerupdate?
You should place the first function to OnPlayerConnect (dont forget to show it).
Also, you shouldn't place the second function to OnPlayerUpdate, just place it OnPlayerDeath, because Death and Kills only updated at the OnPlayerDeath, right ?