[Tutorial] GetPlayerFPS example
#1

So I see noone made any examples from my suggestion how to build a fps counter using drunklevel, so here is a basic copy-pastable code i wrote for my needs that you can use:

pawn Код:
new pDrunkLevelLast[MAX_PLAYERS];
new pFPS[MAX_PLAYERS];
 
public OnPlayerConnect(playerid) {
    pDrunkLevelLast[playerid]   = 0;
    pFPS[PlayerID]          = 0;
}
 
public OnPlayerUpdate(playerid) {
   
    // handle fps counters.
   
    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;
        }
       
    }
   
}
The first person to make a Filterscript out of this with a on-screen FPS textdraw gets eternal gratitude from the turtle!

Remember, this will only work correctly with 0.3b, also you can still set drunk level to >2000 and it will work properly, the trick does not interfere / break any existing script functionality.
Reply
#2

Good tutorial! But next time use PVars? :P
Reply
#3

NIce, i'll test it tomrrow..but it looks nice

P.S it works only for 0.3b?
Reply
#4

Nice ill test it soon !
Reply
#5

It only works for 0.3b yes, i obviously stated that in my post.

Also, i don't use pvars because the script i am working with needs THE ULTIMATE PERFORMANCE at runtime, last time i checked arrays were still faster than pvars.
Reply
#6

Well with PVars you can share the FPS through other scripts. But I guess there are other workarounds
Reply
#7

here you go:
pawn Код:
#include <a_samp>

new pDrunkLevelLast[MAX_PLAYERS];
new pFPS[MAX_PLAYERS];

public OnFilterScriptInit(){
    SetTimer("DisplayFPS",1000,1);
    return 1;
}

public OnPlayerConnect(playerid) {
    pDrunkLevelLast[playerid]   = 0;
    pFPS[playerid]          = 0;
}

public OnPlayerUpdate(playerid) {

    // handle fps counters.

    new 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;
        }

    }

}

forward DisplayFPS();
public DisplayFPS(){
    new FPSmsg[20];
    for(new i; i < MAX_PLAYERS; i++)if(IsPlayerConnected(i)){
        format(FPSmsg,20,"Your FPS is: %d",pFPS[i]);
        //Show it here on-screen and set PVar
    }
}
rest you can do yourself
Reply
#8

Quote:
Originally Posted by gamer_Z
Посмотреть сообщение
here you go:
pawn Код:
#include <a_samp>

new pDrunkLevelLast[MAX_PLAYERS];
new pFPS[MAX_PLAYERS];

public OnFilterScriptInit(){
    SetTimer("DisplayFPS",1000,1);
    return 1;
}

public OnPlayerConnect(playerid) {
    pDrunkLevelLast[playerid]   = 0;
    pFPS[playerid]          = 0;
}

public OnPlayerUpdate(playerid) {

    // handle fps counters.

    new 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;
        }

    }

}


damn, it's easy, useful and works

forward DisplayFPS();
public DisplayFPS(){
    new FPSmsg[20];
    for(new i; i < MAX_PLAYERS; i++)if(IsPlayerConnected(i)){
        format(FPSmsg,20,"Your FPS is: %d",pFPS[i]);
        //Show it here on-screen and set PVar
    }
}
rest you can do yourself
it's easy, useful and works
Reply
#9

Looks good
Reply
#10

thanks for this you finally showed everyone
Reply
#11

Quote:
Originally Posted by JernejL
Посмотреть сообщение
So I see noone made anx examples from my suggestion how to build a fps counter using drunklevel, so here is a basic copy-pastable code i wrote for my needs that you can use:

The first person to make a Filterscript out of this with a on-screen FPS textdraw gets eternal gratitude from the turtle!

Remember, this will only work correctly with 0.3b, also you can still set drunk level to >2000 and it will work properly, the trick does not interfere / break any existing script functionality.
I had a working /fps command the very same day you posted your whitepaper on it. The logic was simple enough to follow to work out the math. Mine is different though: my /fps brings up a dialog which shows the FPS of every player on the server with an 'update' button to refresh it all. I also do not have the range check that you do since I have other functions that can break the FPS function on a specific player if they start playing with functions that drastically alter their drunk level (i.e. /mdrunk, /wine, /beer, etc). That, or you can just direct it to a player (i.e. /fps <player name>). Come by my server some time and do /fps .
Reply
#12

Quote:
Originally Posted by nemesis-
Посмотреть сообщение
I had a working /fps command the very same day you posted your whitepaper on it. The logic was simple enough to follow to work out the math. Mine is different though: my /fps brings up a dialog which shows the FPS of every player on the server with an 'update' button to refresh it all. I also do not have the range check that you do since I have other functions that can break the FPS function on a specific player if they start playing with functions that drastically alter their drunk level (i.e. /mdrunk, /wine, /beer, etc). That, or you can just direct it to a player (i.e. /fps <player name>). Come by my server some time and do /fps .
We had this for months as admin-only-manual-drunk-fps-checker in 0.3a on partyserver, and with 0.3b it's public functions: see /fps /goodfps & /laggers, uses dialogs too.

My implementation will not break if you set drunk level (and highier than 2000 drunk level on partyserver is set if you driveby too much)
Reply
#13

I'm wondering where all this FPS crap came from so suddenly... because it was stated in the 0.3b topic that /fpslimit saves?

Looks good, even though I'm wondering why somebody would want to get somebody else's FPS :S
Reply
#14

Quote:
Originally Posted by Hiddos
Посмотреть сообщение
I'm wondering where all this FPS crap came from so suddenly... because it was stated in the 0.3b topic that /fpslimit saves?

Looks good, even though I'm wondering why somebody would want to get somebody else's FPS :S
It can be useful to detect if someone's lagging or HP hacking. Seeing as you could get their FPS rate, ping & other dependencies.
Reply
#15

nice, but how does it work?
what does the drinlevel have to do with fps?
Reply
#16

OMFG, amazing. Using it!. Thanks you.
Reply
#17

Dude you rock,thanks!
Made an FS(with your credits OFC.)
http://forum.sa-mp.com/showthread.ph...112#post815112
Reply
#18

Quote:
Originally Posted by Cank
Посмотреть сообщение
nice, but how does it work?
what does the drinlevel have to do with fps?
It has to do with how drinklevel is synced and decremented, drunk level decrements FPS amout each second, which is synced in that interval.

Hiddos: 0.3b adds some new trick to help getting player fps in more precise manner.
Reply
#19

Seriously, you're a genious...
I'm using it, thanks for tutorial.
Reply
#20

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
Dude you rock,thanks!
Made an FS(with your credits OFC.)
http://forum.sa-mp.com/showthread.ph...112#post815112
haha nice i just made smth like this about a hour ago then look a look at the forums and saw this FS
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)