[Help] TextDraw Don't Update
#1

Hello i made a TextDraw known as Premium Points . but it don't update when i give or take premium points from someone . Following is the codes.

PHP код:
stock load_pp(playerid)
{
    
Textdraw1 CreatePlayerTextDraw(playerid,501.000000100.000000"Premium Points: 69");
    
PlayerTextDrawBackgroundColor(playerid,Textdraw1, -1);
    
PlayerTextDrawFont(playerid,Textdraw11);
    
PlayerTextDrawLetterSize(playerid,Textdraw10.3200000.799999);
    
PlayerTextDrawColor(playerid,Textdraw165535);
    
PlayerTextDrawSetOutline(playerid,Textdraw11);
    
PlayerTextDrawSetProportional(playerid,Textdraw11);
    
PlayerTextDrawUseBox(playerid,Textdraw11);
    
PlayerTextDrawBoxColor(playerid,Textdraw10x00000044);
    
PlayerTextDrawTextSize(playerid,Textdraw1606.0000000.000000);
    
PlayerTextDrawSetSelectable(playerid,Textdraw10);
    return 
1;

I added the following command in OnPlayerSpawn()
PHP код:
PlayerTextDrawShow(playeridTextdraw1); 
At OnPlayerDisconnet()
PHP код:
    PlayerTextDrawHide(playeridTextdraw1); 
Public UpdatePlayer() is following ( i also did the forward for UpdatePlayer)
PHP код:
public UpdatePlayer()
{
    new 
string[256];
    foreach(new 
Player)
    {
        
format(string128"Premium Points: %d"User[i][accountPP]);
        
PlayerTextDrawSetString(iTextdraw1string);
    }
    return 
1;

OnPlayerConnect()
PHP код:
    load_pp(playerid); 
And the following in OnPlayerDisconnect()
PHP код:
    PlayerTextDrawHide(playeridTextdraw1);
unloadpp(playerid); 
Following is the commands of giving and taking premium points.

Taking Premium points:
PHP код:
CMD:takepp(playeridparams[])
{
    
LoginCheck(playerid);
    if(
User[playerid][accountAdmin] >= 3)
    {
        new 
string[150], idamount;
        if(
sscanf(params"ui"idamount)) return SendClientMessage(playeridCOLOR_RED"USAGE: /givepp [playerid] [amount]");
        if(
id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1"» "red"Player not connected.");
        if(
User[id][accountLogged] == false) return SendClientMessage(playerid, -1"» "red"Player not logged in.");
        if(
User[id][accountPP] < amount) return SendClientMessage(playerid0xFF0000FF"This Player Dont Have That Much Points!");
        
format(string150"[PREMIUM POINTS] "red"%s has taken %s [%d] Premium Points."GetName(playerid), GetName(id), amount);
        
SendAMessage(-1string);
        
format(string150""green"[PREMIUM POINTS] "white"You have received "grey"%d "white"premium points from an "red"admin"white"."amountUser[id][accountPP]-amount);
        
SendClientMessage(id, -1string);
        
format(string150"» You have lost{%06x}%s "white"premium points of "grey"%d"white"."GetPlayerColor(id) >>> 8GetName(id), amount);
        
SendClientMessage(playerid, -1string);
        
format(string128"%s take %d Premium Point(s) from %s."GetName(playerid), amountGetName(id));
        
Log("premium.txt"string);
        
User[id][accountPP] -= amount;
    }
    else
    {
        
SendClientMessage(playerid, -1"» "red"You are not authorized to use this command.");
    }
    return 
1;

(I know there is some mistakes in Takepp of format .)

Giving Premium point:
PHP код:
CMD:givepp(playeridparams[])
{
    
LoginCheck(playerid);
    if(
User[playerid][accountAdmin] >= 3)
    {
        new 
string[150], idamount;
    
        if(
sscanf(params"ui"idamount)) return SendClientMessage(playeridCOLOR_RED"USAGE: /givepp [playerid] [amount]");
        if(
id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1"» "red"Player not connected.");
        if(
User[id][accountLogged] == false) return SendClientMessage(playerid, -1"» "red"Player not logged in.");
        
format(string150"[PREMIUM POINTS] "red"%s has given %s [%d] Premium Points."GetName(playerid), GetName(id), amount);
        
SendAMessage(-1string);
        
format(string150""green"[PREMIUM POINTS] "white"You have received "grey"%d "white"premium points from an "red"admin"white"."amountUser[id][accountPP]+amount);
        
SendClientMessage(id, -1string);
        
format(string150"» You have given {%06x}%s "white"premium points of "grey"%d"white"."GetPlayerColor(id) >>> 8GetName(id), amount);
        
SendClientMessage(playerid, -1string);
        
format(string128"%s received %d Premium Points from %s."GetName(id), amountGetName(playerid));
        
Log("premium.txt"string);
        
User[id][accountPP] += amount;
    }
    else
    {
        
SendClientMessage(playerid, -1"» "red"You are not authorized to use this command.");
    }
    return 
1;

Setting Premium points :

PHP код:
CMD:setpremium(playeridparams[])
{
    new
        
string[200],
        
id,
        
amount
    
;
    
LoginCheck(playerid);
    if(
User[playerid][accountAdmin] >= 5)
    {
        if(
sscanf(params"ui"idamount)) return SendClientMessage(playeridCOLOR_RED"USAGE: /setpremium [playerid] [points]");
        if(
id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1"» "red"Player not connected.");
        if(
User[id][accountLogged] == false) return SendClientMessage(playerid, -1"» "red"Player not logged in.");
        
format(string128"[SET] "white"%s's Premium Point has been set to %d by %s."GetName(id), amountGetName(playerid));
        
SendAMessage(COLOR_REDstring);
        
format(string128"[SET] "white"An admin has set your premium points to %d."amount);
        
SendClientMessage(idCOLOR_YELLOWstring);
        
format(string128"%s has been premium points set to %d by %s."GetName(id), amountGetName(playerid));
        
Log("admin.txt"string);
        
User[id][accountPP] = amount;
    }
    else
    {
        
SendClientMessage(playerid, -1"» "red"You are not authorized to use this command.");
    }
    return 
1;

Reply
#2

callbacks will never be called except if there's a function to call them, Use a timer
pawn Код:
new pTimer[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
     pTimer[playerid] = SetTimerEx("UpdatePlayer", 1000, true, "i", playerid); // each second the textdraw will be updated
     return 1;
}
we made a timer variable , and a timer with params. Recommending you to edit your callback:
pawn Код:
public UpdatePlayer(playerid)
{
    new string[128];
    format(string, 128, "Premium Points: %d", User[playerid][accountPP]);
    PlayerTextDrawSetString(playerid, Textdraw0, string);
    return 1;
}
Set your string size to 128, you formatted it 128 and set as 256, that's a waste of memory and useless.


now:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
      KillTimer(pTimer[playerid]);
      return 1;
}
Killing player's timer when he disconnects
Reply
#3

pawn Код:
OnGameModeInit() {
 SetTimer("UpdatePlayer", 500, true);
return 1;
}
Reply
#4

@bgedition , i forgot to mention it . I already wrote that command of SetTimer.
@Sawalha thanks , +rep you and you too bgedition.
Reply
#5

EDIT: Removed, incorrect post.
Reply
#6

@Sawalhan , will you tell me the code please of How to give Premium points to an offline player?
Reply
#7

which saving method do you use?
Reply
#8

MySql
Reply
#9

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Read this:
https://sampwiki.blast.hk/wiki/TextDrawSetString

I just added a note that reads:

Quote:

The text within the TextDraw will not be updated until TextDrawShowForPlayer or TextDrawShowForAll has been used.

This is NOT true and similar messages have been removed from that page several times earlier! For every other functions this holds true, EXCEPT for this one.
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
This is NOT true and similar messages have been removed from that page several times earlier! For every other functions this holds true, EXCEPT for this one.
Yeah, I had a feeling. My bad. I'll test it next time I jump to conclusions, I don't work with TextDraws very often.

EDIT: And I just realised that I have done this exact same thing in October 2014... I must be losing my mind...
Reply


Forum Jump:


Users browsing this thread: