Help with this TextDraw.
#1

Well I made a textdraw that displays your fps and it only show it for a quick second then it goes back to 0 and it keeps doing that. I don't know whats wrong.

Код:
new Text:FPS;

FPS = TextDrawCreate(497.000000, 163.000000, "FPS:");
TextDrawBackgroundColor(FPS, 255);
TextDrawFont(FPS, 3);
TextDrawLetterSize(FPS, 0.500000, 1.000000);
TextDrawColor(FPS, -65281);
TextDrawSetOutline(FPS, 0);
TextDrawSetProportional(FPS, 1);
TextDrawSetShadow(FPS, 1);

public OnPlayerUpdate(playerid)
{
   new string[128];
   new fps;
   fps = GetPlayerFPS(playerid);
   format(string, sizeof string, "FPS: %d", fps);
   TextDrawSetString(FPS, string);
   return 1;
}
Reply
#2

Show the function that's getting the players FPS - and also... Don't use OnPlayerUpdate for anything really, unless absolutely necessary.
Reply
#3

Quote:
Originally Posted by Mike Garber
Посмотреть сообщение
Show the function that's getting the players FPS - and also... Don't use OnPlayerUpdate for anything really, unless absolutely necessary.
Код:
stock GetPlayerFPS(playerid)
{
    SetPVarInt(playerid, "DrunkL", GetPlayerDrunkLevel(playerid));
    if(GetPVarInt(playerid, "DrunkL") < 100) SetPlayerDrunkLevel(playerid, 2000);
        else{
            if(GetPVarInt(playerid, "LDrunkL") != GetPVarInt(playerid, "DrunkL"))
            {
                SetPVarInt(playerid, "FPS", (GetPVarInt(playerid, "LDrunkL") - GetPVarInt(playerid, "DrunkL")));
                SetPVarInt(playerid, "LDrunkL", GetPVarInt(playerid, "DrunkL"));
                if((GetPVarInt(playerid, "FPS") > 0) && (GetPVarInt(playerid, "FPS") < 256))
                {
                    return GetPVarInt(playerid, "FPS") - 1;
                }
            }
        }
    return 0;
}
What do i use instead of onplayerupdate?
Reply
#4

The guy who wrote that rly likes pvar

pawn Код:
stock GetPlayerFPS(playerid)
{
    new
        drunk = GetPlayerDrunkLevel(playerid),
        fps = (GetPVarInt(playerid, "DrunkLevel") - drunk);
    if(drunk < 100) {
        SetPlayerDrunkLevel(playerid, 2000);
        SetPVarInt(playerid, "DrunkLevel", 2000);
    } else {
        SetPVarInt(playerid, "DrunkLevel", drunk);
    }
    return fps;
}
Reply
#5

Also make a textdraw for every player.
pawn Код:
new Text:FPS[MAX_PLAYERS];
pawn Код:
FPS[playerid] = TextDrawCreate(497.000000, 163.000000, "FPS:");
Reply
#6

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
The guy who wrote that rly likes pvar

pawn Код:
stock GetPlayerFPS(playerid)
{
    new
        drunk = GetPlayerDrunkLevel(playerid),
        fps = (GetPVarInt(playerid, "DrunkLevel") - drunk);
    if(drunk < 100) {
        SetPlayerDrunkLevel(playerid, 2000);
        SetPVarInt(playerid, "DrunkLevel", 2000);
    } else {
        SetPVarInt(playerid, "DrunkLevel", drunk);
    }
    return fps;
}
I tried this and it shows the FPS 2000 and it keeps changing to 0 every second like before. Do I have to use something else instead of OnPlayerUpdate?
Reply
#7

Quote:
Originally Posted by TheYoungCapone
Посмотреть сообщение
I tried this and it shows the FPS 2000 and it keeps changing to 0 every second like before. Do I have to use something else instead of OnPlayerUpdate?
Yeah I forgot something important

pawn Код:
stock GetPlayerFPS(playerid)
{ // forum.sa-mp.com/showpost.php?p=1167812&postcount=7
    new
        drunk = GetPlayerDrunkLevel(playerid);
    if(GetPVarInt(playerid, "DrunkLevel") != drunk) {
        SetPVarInt(playerid, "FPS", (GetPVarInt(playerid, "DrunkLevel") - drunk));
    }
    if(drunk < 100) {
        SetPlayerDrunkLevel(playerid, 2000);
        SetPVarInt(playerid, "DrunkLevel", 2000);
    } else {
        SetPVarInt(playerid, "DrunkLevel", drunk);
    }
    return GetPVarInt(playerid, "FPS");
}
Reply
#8

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Yeah I forgot something important

pawn Код:
stock GetPlayerFPS(playerid)
{
    new
        drunk = GetPlayerDrunkLevel(playerid);
    if(GetPVarInt(playerid, "DrunkLevel") != drunk) {
        SetPVarInt(playerid, "FPS", (GetPVarInt(playerid, "DrunkLevel") - drunk));
    }
    if(drunk < 100) {
        SetPlayerDrunkLevel(playerid, 2000);
        SetPVarInt(playerid, "DrunkLevel", 2000);
    } else {
        SetPVarInt(playerid, "DrunkLevel", drunk);
    }
    return GetPVarInt(playerid, "FPS");
}
Well it kind of works it shows FPS for a second then it shows 2000 and it goes back and forth any more ideas?And also someone said not to use OnPlayerUpdate do i change it? and if so to what.
Reply
#9

Quote:
Originally Posted by TheYoungCapone
Посмотреть сообщение
Well it kind of works it shows FPS for a second then it shows 2000 and it goes back and forth any more ideas?And also someone said not to use OnPlayerUpdate do i change it? and if so to what.
So, this will fix it, the only problem is that we cant get the fps while reseting the drunk level
Means that there is one call once a minute which only shows the last fps but its not realy noticeable

pawn Код:
stock GetPlayerFPS(playerid) //no one time usage (needs to be in a timer)
{ //forum.sa-mp.com/showpost.php?p=1167870&postcount=9
    new
        drunk = GetPlayerDrunkLevel(playerid);
    if(GetPVarInt(playerid, "DrunkLevel") != drunk) {
        if(GetPVarInt(playerid, "DrunkLevel") == 2000) {
            if(drunk > 100) {
                SetPVarInt(playerid, "DrunkLevel", drunk);
            }
            return GetPVarInt(playerid, "FPS");
        } else {
            SetPVarInt(playerid, "FPS", (GetPVarInt(playerid, "DrunkLevel") - drunk));
        }
    }
    if(drunk < 100) {
        SetPlayerDrunkLevel(playerid, 2000);
        SetPVarInt(playerid, "DrunkLevel", 2000);
    } else {
        SetPVarInt(playerid, "DrunkLevel", drunk);
    }
    return GetPVarInt(playerid, "FPS");
}
Yes you should avoid OnPlayerUpdate because it gets called very often per second per player!
Example: 5 calls per second * 10 player = 50 calls per second (far to much)

Just use a timer (SetTimer) and a loop

pawn Код:
//To start the timer
SetTimer("MyTimer", 1000, true);
pawn Код:
forward MyTimer();
public MyTimer()
{
    for(new i; i != MAX_PLAYERS; ++i)
    {  //foreach if possible
        if(IsPlayerConnected(i))
        {
            //your code
        }
    }
}
And another important thing (if you missed the post)

Quote:
Originally Posted by Stigg
Посмотреть сообщение
Also make a textdraw for every player.
pawn Код:
new Text:FPS[MAX_PLAYERS];
pawn Код:
FPS[playerid] = TextDrawCreate(497.000000, 163.000000, "FPS:");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)