Problem with text draw timer
#1

Hello all,

I have tried to create a text draw stats bar that sits at the bottom of the screen and updates as your stats update,
The text draw works fine, and will display, it's just as soon as the timer updates for the first time, the bar dissapears.

pawn Код:
public UpdateStats(playerid)
{
    for(new i; i < MAX_PLAYERS; i++)// this is to find the playerid
    {
        if(IsPlayerConnected(i))
        {
            i = playerid;
        }
    }
    new
        str[128],
        Float:ratio,
        k,d;
    if((PlayerInfo[playerid][Kills] != 0) && PlayerInfo[playerid][Deaths] == 0)//just a script to work out a kill death ratio
    {
        ratio = 100.00;
    }
    else
    {
        ratio = floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths]);
    }
    k = PlayerInfo[playerid][Kills];
    d = PlayerInfo[playerid][Deaths];


    format(str,sizeof(str),"~r~K: ~w~%d | ~r~D: ~w~%d | ~r~K/D: ~w~%.2f ",k,d,ratio);
    TextDrawSetString(TotalStats[playerid],str);
    SendClientMessage(playerid,WHITE,str);
    return 1;
}
the reason I put the loop in there to find the playerid is because I want to put the timer under OnGameModeInit, that way there is 1 continuous timer, instead of a seperate timer for each individual player.

I get the text: "~r~K: ~w~%d | ~r~D: ~w~%d | ~r~K/D: ~w~%.2f " sent to me through SendClientMessage, it just won't work through textdraw.

This has been bugging me for quite some time,
any help will be greatly appreciated.
Reply
#2

pawn Код:
public UpdateStats(playerid)
{
    for(new i; i < MAX_PLAYERS; i++)// this is to find the playerid
    {
        if(IsPlayerConnected(i))
        {
            i = playerid;
        }
    }
    new
        str[128],
        Float:ratio,
        k,d;
    if((PlayerInfo[playerid][Kills] != 0) && PlayerInfo[playerid][Deaths] == 0)//just a script to work out a kill death ratio
    {
        ratio = 100.00;
    }
    else
    {
        ratio = floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths]);
    }
    k = PlayerInfo[playerid][Kills];
    d = PlayerInfo[playerid][Deaths];


    format(str,sizeof(str),"~r~K: ~w~%d | ~r~D: ~w~%d | ~r~K/D: ~w~%.2f ",k,d,ratio);
    TextDrawSetString(TotalStats[playerid],str);
    SendClientMessage(playerid,WHITE,str);
    TextDrawShowForPlayer(playerid, str); //Add this
    return 1;
}
Try this.
Reply
#3

Simply does not work, unfortunately,
That is a 3 second timer, so repeatedly showing the textdraw is inefficient,
I already have TextDrawShowForPlayer Under OnPlayerSpawn
Reply
#4

Try updating the textdraw onplayerdeath..can't post code on phone sorry
Reply
#5

That would work, but I'm trying to get a timer working, so that way, in the future I can add lines to the stats bar, like, minutes online, hours online, current level etc.

Also, I have been messing around with this small piece of script for that long, I won't get my satisfaction until I learn exactly how to fix this problem.
Reply
#6

Sorry that I can't help ya ..But I like to hear the "I'll keep trying" spirit!
Reply
#7

The codes in your first post seems quite fine for me except one thing *. Do you mind if I ask you to you show the whole declaration of the textdraw and also the way you're calling the UpdateStats func?

* Why not OnPlayerConnect instead of OnGameModeInit? Well I don't get it why would you use it under ongamemode. I mean when a player connects SetTimerEx, store the player id then use it in your timer function UpdateStats without any loops. More efficient ha?
Reply
#8

Thanks,

I have solved the problem, but not in the way i had hoped, I have put the timer under OnPlayerConnect, so now a timer gets created everytime someone connects, it seems to be working alright, but I don't know how this will effect me performance wise.

My goal is to have 1 global timer that updates every persons stats at the same time.

EDIT: Hellsphynx, I have just resorted to that, I will post my script now

OnPlayerconnect:

pawn Код:
public  OnPlayerConnect(playerid)
{
    TotalStats[playerid] = TextDrawCreate(10.000000,432.000000," Loading stats.... ");
    TextDrawColor(TotalStats[playerid],0xFFFFFFFF); //color of the words
    TextDrawUseBox(TotalStats[playerid],true);
    TextDrawBoxColor(TotalStats[playerid],0x000000AA);
    TextDrawFont(TotalStats[playerid],1);
    TextDrawSetOutline(TotalStats[playerid],true);
    TextDrawBackgroundColor(TotalStats[playerid],255); //color of the shadow
    TextDrawTextSize(TotalStats[playerid],640.0,480.0);
    TextDrawLetterSize(TotalStats[playerid],0.4,1.2);
then under OnGameModeInit I just have a simple SetTimer("UpdateStats",3000,1)

Under OnPlayerSpawn I show the Textdraw TextDrawShowForPlayer(playerid,TotalStats[playerid]);
Reply
#9

Quote:
Originally Posted by mrcoolballs
Посмотреть сообщение
My goal is to have 1 global timer that updates every persons stats at the same time.
Well, I understand you now. So, how about this code?
pawn Код:
forward UpdateStats();

public UpdateStats()
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        new
            str[128],
            Float:ratio,
            k,d;
        if((PlayerInfo[i][Kills] != 0) && PlayerInfo[i][Deaths] == 0) //just a script to work out a kill death ratio
        {
            ratio = 100.00;
        }
        else
        {
            ratio = floatdiv(PlayerInfo[i][Kills], PlayerInfo[i][Deaths]);
        }
        k = PlayerInfo[i][Kills];
        d = PlayerInfo[i][Deaths];
        format(str,sizeof(str),"~r~K: ~w~%d | ~r~D: ~w~%d | ~r~K/D: ~w~%.2f ",k,d,ratio);
        TextDrawSetString(TotalStats[i],str);
        SendClientMessage(i,WHITE,str);
    }
    return 1;
}


public OnGameModeInit()
{
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        TotalStats[i] = TextDrawCreate(10.000000,432.000000," Loading stats.... ");
        TextDrawColor(TotalStats[i],0xFFFFFFFF); //color of the words
        TextDrawUseBox(TotalStats[i],true);
        TextDrawBoxColor(TotalStats[i],0x000000AA);
        TextDrawFont(TotalStats[i],1);
        TextDrawSetOutline(TotalStats[i],true);
        TextDrawBackgroundColor(TotalStats[i],255); //color of the shadow
        TextDrawTextSize(TotalStats[i],640.0,480.0);
        TextDrawLetterSize(TotalStats[i],0.4,1.2);
    }
    SetTimer("UpdateStats", 600, true);
    return 1;
}

public OnPlayerConnect(playerid)
{
    TextDrawShowForPlayer(playerid, TotalStats[playerid]);
    return 1;
}
Let me know if it works.
Reply
#10

Sorry, still doesn't seem to be working,
the SendClientMessage delivers the correct text, just the textdraw doesn't
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)