SA-MP Forums Archive
[Tutorial] GetPlayerFPS example - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] GetPlayerFPS example (/showthread.php?tid=172085)

Pages: 1 2


GetPlayerFPS example - JernejL - 28.08.2010

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.


Re: GetPlayerFPS example - [03]Garsino - 28.08.2010

Good tutorial! But next time use PVars? :P


Re: GetPlayerFPS example - Brian_Furious - 28.08.2010

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

P.S it works only for 0.3b?


Re: GetPlayerFPS example - Kitten - 28.08.2010

Nice ill test it soon !


Re: GetPlayerFPS example - JernejL - 28.08.2010

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.


Re: GetPlayerFPS example - [03]Garsino - 28.08.2010

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


Re: GetPlayerFPS example - Gamer_Z - 29.08.2010

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


Re: GetPlayerFPS example - Brian_Furious - 29.08.2010

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


Re: GetPlayerFPS example - [L3th4l] - 29.08.2010

Looks good


Re: GetPlayerFPS example - Flake. - 29.08.2010

thanks for this you finally showed everyone


Re: GetPlayerFPS example - nemesis- - 29.08.2010

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 .


Re: GetPlayerFPS example - JernejL - 29.08.2010

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)


Re: GetPlayerFPS example - Hiddos - 29.08.2010

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


Re: GetPlayerFPS example - Calgon - 29.08.2010

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.


Re: GetPlayerFPS example - Cank - 29.08.2010

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


Re: GetPlayerFPS example - MrDeath537 - 29.08.2010

OMFG, amazing. Using it!. Thanks you.


Re: GetPlayerFPS example - [XST]O_x - 29.08.2010

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


Re: GetPlayerFPS example - JernejL - 29.08.2010

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.


Re: GetPlayerFPS example - MrDeath537 - 29.08.2010

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


Re: GetPlayerFPS example - Flake. - 30.08.2010

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