FPS Textdraw Problem + rep But FAST!!!
#6

It explains how you can get FPS using a little trick with drunk level. Your working code should probably be like this when you read & understand the tutorial:

pawn Код:
new
    Text:FPS[MAX_PLAYERS],
    pDrunkLevelLast[MAX_PLAYERS],
    pFPS[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    FPS[playerid] = TextDrawCreate(240.0, 580.0, "Your FPS: Loading");

    TextDrawShowForPlayer(playerid, FPS[playerid]);
    return 1;
}

public OnPlayerUpdate(playerid)
{
    // Getting FPS as explained in the tutorial and storing it in pFPS[] variable
    new drunknew;
    drunknew = GetPlayerDrunkLevel(playerid);

    if (drunknew < 100) { // go back up, keep cycling.
        SetPlayerDrunkLevel(playerid, 2000);
    } else {

        if (pDrunkLevelLast[playerid] != drunknew) {

            new wfps = pDrunkLevelLast[playerid] - drunknew;

            if ((wfps > 0) && (wfps < 200))
                pFPS[playerid] = wfps;

            pDrunkLevelLast[playerid] = drunknew;
        }

    }
    // Done with fps!
    // Update FPS textdraws
    new string[128]
    format(string, sizeof(string), "Your FPS: %d", pFPS[playerid]);
    TextDrawSetString(FPS[playerid], string);
    return 1;
}
However, and to be honest with you, your code is inefficient in many ways.

1# Why global-textdraws when player-textdraws could simply fit? I mean, yeah it's just a way around the limit, but you can save a slot for a textdraw that really needs to be 'global'.
2# Updating the textdraw over OnPlayerUpdate is honestly not necessary and not efficient at all. Do you realize that [url=https://sampwiki.blast.hk/wiki/OnPlayerUpdate] is called VERY frequently per second? Does your textdraw update need to be that much frequent? If you ask me, no, I'd just make an one-second timer to handle update.
3#
pawn Код:
new string[128]
format(string, sizeof(string), "Your FPS: %d", GetPlayerFPS(playerid));
I bet you weren't sober when you picked a size for this string. 128? Why? "Your FPS: 200" - the longest this string can get - is 13 characters length, and if you add the NULL character to those, you get 14. Hence, a memory friendly code should probably look like this:

pawn Код:
new string[14]
format(string, sizeof(string), "Your FPS: %d", pFPS[playerid]);
Reply


Messages In This Thread
FPS Textdraw Problem + rep But FAST!!! - by Toxik - 10.05.2015, 01:38
Re: FPS Textdraw Problem + rep But FAST!!! - by Deathlane - 10.05.2015, 01:48
Re: FPS Textdraw Problem + rep But FAST!!! - by [KHK]Khalid - 10.05.2015, 01:51
Re: FPS Textdraw Problem + rep But FAST!!! - by Toxik - 10.05.2015, 02:11
Re: FPS Textdraw Problem + rep But FAST!!! - by X337 - 10.05.2015, 06:56
Re: FPS Textdraw Problem + rep But FAST!!! - by [KHK]Khalid - 10.05.2015, 08:06

Forum Jump:


Users browsing this thread: 2 Guest(s)