SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 28/08/2010, 10:33 PM   #1
JernejL
Beta Tester
 
JernejL's Avatar
 
Join Date: Jan 2006
Location: Slovenia
Posts: 564
Reputation: 358
Default GetPlayerFPS example

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 Code:
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.
__________________


8.2.121.99:7777 - Partyserver - TurtleServer (now with extra turtles)!

SA-MP map editor: Not a in-game script but a proper windows application!
http://forum.sa-mp.com/showthread.php?t=282801

Last edited by JernejL; 28/07/2011 at 07:28 AM.
JernejL is offline   Reply With Quote
Old 28/08/2010, 10:37 PM   #2
[03]Garsino
Guest
 
Posts: n/a
Default Re: GetPlayerFPS example

Good tutorial! But next time use PVars? :P
  Reply With Quote
Old 28/08/2010, 10:46 PM   #3
Brian_Furious
Gangsta
 
Brian_Furious's Avatar
 
Join Date: May 2009
Location: C:\Windows\System32\brian_furious.dll
Posts: 748
Reputation: 40
Default Re: GetPlayerFPS example

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

P.S it works only for 0.3b?
__________________
I currently working on a NEW LA:RP (Los Angeles RolePlay) 3.0 R2
Brian_Furious is offline   Reply With Quote
Old 28/08/2010, 10:47 PM   #4
Kitten
High-roller
 
Kitten's Avatar
 
Join Date: Jul 2010
Location: Canada
Posts: 2,314
Reputation: 236
Default Re: GetPlayerFPS example

Nice ill test it soon !
__________________
Kitten is offline   Reply With Quote
Old 28/08/2010, 11:15 PM   #5
JernejL
Beta Tester
 
JernejL's Avatar
 
Join Date: Jan 2006
Location: Slovenia
Posts: 564
Reputation: 358
Default Re: GetPlayerFPS example

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.
__________________


8.2.121.99:7777 - Partyserver - TurtleServer (now with extra turtles)!

SA-MP map editor: Not a in-game script but a proper windows application!
http://forum.sa-mp.com/showthread.php?t=282801
JernejL is offline   Reply With Quote
Old 28/08/2010, 11:50 PM   #6
[03]Garsino
Guest
 
Posts: n/a
Default Re: GetPlayerFPS example

Well with PVars you can share the FPS through other scripts. But I guess there are other workarounds
  Reply With Quote
Old 29/08/2010, 12:06 AM   #7
Gamer_Z
High-roller
 
Gamer_Z's Avatar
 
Join Date: Jun 2009
Location: Fontys University of Applied Sciences
Posts: 2,595
Reputation: 785
Default Re: GetPlayerFPS example

here you go:
pawn Code:
#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
Gamer_Z is offline   Reply With Quote
Old 29/08/2010, 12:13 AM   #8
Brian_Furious
Gangsta
 
Brian_Furious's Avatar
 
Join Date: May 2009
Location: C:\Windows\System32\brian_furious.dll
Posts: 748
Reputation: 40
Default Re: GetPlayerFPS example

Quote:
Originally Posted by gamer_Z View Post
here you go:
pawn Code:
#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
__________________
I currently working on a NEW LA:RP (Los Angeles RolePlay) 3.0 R2
Brian_Furious is offline   Reply With Quote
Old 29/08/2010, 12:20 AM   #9
[L3th4l]
Guest
 
Posts: n/a
Default Re: GetPlayerFPS example

Looks good
  Reply With Quote
Old 29/08/2010, 12:37 AM   #10
Gamer_Z
High-roller
 
Gamer_Z's Avatar
 
Join Date: Jun 2009
Location: Fontys University of Applied Sciences
Posts: 2,595
Reputation: 785
Default Re: GetPlayerFPS example

AND no lagg ;d

Do you have more scripts where you want to add some ideas to it or realise? xD
Gamer_Z is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 03:04 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.