SA-MP Forums Archive
How to update textdraw information ? - 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: How to update textdraw information ? (/showthread.php?tid=530661)



How to update textdraw information ? - SandKing94 - 08.08.2014

So i have this
PHP код:
public OnPlayerUpdate(playerid)
{
      new 
string[50];
    
format(stringsizeof(string), "Score:%d"GetPlayerScore(playerid));
    
TextDrawSetString(ScoreTextstring);
    return 
1;

PHP код:
public OnPlayerSpawn(playerid)
{
new 
str[100];
format(strsizeof(str), "Score:%d"GetPlayerScore(playerid));
ScoreText TextDrawCreate(503.500000108.062500"Score:");
TextDrawSetString(ScoreTextstr);
TextDrawLetterSize(ScoreText0.3000001.399999);
TextDrawAlignment(ScoreText1);
TextDrawColor(ScoreText, -1);
TextDrawSetShadow(ScoreText0);
TextDrawSetOutline(ScoreText1);
TextDrawBackgroundColor(ScoreText51);
TextDrawFont(ScoreText2);
TextDrawSetProportional(ScoreText1);
return 
1;

But the score is still the same i have to reconnect to see my real score.


Re: How to update textdraw information ? - [XST]O_x - 08.08.2014

pawn Код:
new updateTimer[ MAX_PLAYERS ] ;

forward UpdatePlayer(playerid);

public OnPlayerConnect(playerid)
{
    updateTimer[playerid] = SetTimerEx("UpdatePlayer", 1000, true, "i", playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    KillTimer(updateTimer[playerid]);
    return 1;
}

public UpdatePlayer(playerid)
{
    new string[24];
    format(string, sizeof string, "Score: %d", GetPlayerScore(playerid));
    TextDrawSetString(ScoreText[playerid], string);
    return 1;
}



Re: How to update textdraw information ? - arakuta - 08.08.2014

You can create a function that gives score and automatically update the textdraw.

pawn Код:
GivePlayerScore(playerid,scr)
{
    SetPlayerScore(playerid,GetPlayerScore(playerid) + score);
    PlayerTextDrawSetString(playerid,text[playerid],"String");
}



Re: How to update textdraw information ? - SandKing94 - 08.08.2014

But when player kill player he gets score


Re: How to update textdraw information ? - Vince - 08.08.2014

And? You can update the textdraw in OnPlayerDeath. Using a timer to listen for an event that is initiated by the scripter (giving score) is frankly pretty dumb.


Re: How to update textdraw information ? - [XST]O_x - 08.08.2014

Quote:
Originally Posted by arakuta
Посмотреть сообщение
You can create a function that gives score and automatically update the textdraw.

pawn Код:
GivePlayerScore(playerid,scr)
{
    SetPlayerScore(playerid,GetPlayerScore(playerid) + score);
    PlayerTextDrawSetString(playerid,text[playerid],"String");
}
That is actually genuis. Can save a timer usage.


Re: How to update textdraw information ? - SandKing94 - 08.08.2014

What if i want to make the same with kills and deaths textdraw ?


Re: How to update textdraw information ? - SandKing94 - 08.08.2014

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
pawn Код:
new updateTimer[ MAX_PLAYERS ] ;

forward UpdatePlayer(playerid);

public OnPlayerConnect(playerid)
{
    updateTimer[playerid] = SetTimerEx("UpdatePlayer", 1000, true, "i", playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    KillTimer(updateTimer[playerid]);
    return 1;
}

public UpdatePlayer(playerid)
{
    new string[24];
    format(string, sizeof string, "Score: %d", GetPlayerScore(playerid));
    TextDrawSetString(ScoreText[playerid], string);
    return 1;
}
Dont works


Re: How to update textdraw information ? - caoraivoso3 - 08.08.2014

You need https://sampwiki.blast.hk/wiki/TextDrawShowForPlayer


Re: How to update textdraw information ? - SandKing94 - 08.08.2014

bump