My FPS command.
#1

The command seems to work out good in some way, but it takes a while to generate the player's FPS and it shows few random numbers along the way, Not sure if it suppose to work like that..

e.g

I do /fpslimit 51 (which will generate it to 56-57)

I do /fps 0 (my id)

It shows this:

first time use of the command

117,

second time

118

third

102

4th 56

It shows my fps not correctly only after a few times of performing the command (I guess I have to wait till it generates it perfectly.)

PHP код:
CMD:fps(playeridparams[])
{
   new
        
fps,
        
target,
        
str[64],
        
PlayerName[MAX_PLAYER_NAME];
   
GetPlayerName(playeridPlayerNamesizeof(PlayerName));
   
   
fps GetPlayerDrunkLevel(target);
   if(
fps 100) {
      
SetPlayerDrunkLevel(target2000);
   } else {
        if (
gDrunkLevelLast[target] != fps) {
            new 
gfps gDrunkLevelLast[playerid] - fps;
            if ((
gfps 0) && (gfps 200))
                   
gFPS[playerid] = gfps;
               
gDrunkLevelLast[playerid] = fps;
      }
   }
   if (
   
sscanf (
   
params,
   
"u"target)) target playerid;
   
format(str,sizeof(str), "SERVER: %s's fps is %d"PlayerNamegFPS[target]);
   
   
SendClientMessage(playerid, -1str);
   return 
true;

Reply
#2

bump
Reply
#3

You're setting your FPS instead of the targets.

Quote:

gFPS[playerid] = gfps;

Reply
#4

Yeah, thanks I didn't notice, anyway same issue.

It starts like this

it shows 0 few times when i perform the command, then it shows my correct fps, and then it shows something like 160 or something
Reply
#5

The Drunk Level drops by the amount of your FPS per SECOND.

That means using that command 2 times in 3 seconds will show the number of frames for the past 3 seconds in total.

You must calculate the time between 2 checks (eg. GetTickCount) and calculate the fps like this (using float the precision will be higher):

Код:
new Float:fps = float(drunklvl_difference) / (float(timepassed_in_ms) / 1000.0);
That will give the correct average FPS (frames/second) for a certain time interval.
Reply
#6

It didn't work, I got few errors.

Код:
CMD:fps(playerid, params[])
{
   new
	    Float:fps = float(drunklvl_difference) / (float(timepassed_in_ms) / 1000.0),
		target,
		str[64],
		PlayerName[MAX_PLAYER_NAME];

   GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
   
   fps = GetPlayerDrunkLevel(target);

   if(fps < 100) {
	  SetPlayerDrunkLevel(target, 2000);
   } else {

		if (gDrunkLevelLast[target] != fps) {

			new gfps = gDrunkLevelLast[playerid] - fps;

			if ((gfps > 0) && (gfps < 200))
				   gFPS[target] = gfps;


	   	    gDrunkLevelLast[playerid] = fps;

	  }
   }
   if (
   sscanf (
   params,
   "u", target)) target = playerid;

   format(str,sizeof(str), "SERVER: %s's fps is %d", PlayerName, gFPS[target]);
   
   SendClientMessage(playerid, -1, str);

   return true;
}
Код:
C:\Users\yan\Desktop\Battlegrounds\gamemodes\bg.pwn(401) : error 017: undefined symbol "drunklvl_difference"
C:\Users\yan\Desktop\Battlegrounds\gamemodes\bg.pwn(416) : warning 213: tag mismatch
C:\Users\yan\Desktop\Battlegrounds\gamemodes\bg.pwn(422) : warning 213: tag mismatch
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
401:
Код:
Float:fps = float(drunklvl_difference) / (float(timepassed_in_ms) / 1000.0),
416:
Код:
new gfps = gDrunkLevelLast[playerid] - fps;
422:
Код:
gDrunkLevelLast[playerid] = fps;
If i remove your code it complies perfect.
Reply
#7

The variable names were just examples. Obviously you cannot just copy-paste that into your code.

In your code "gfps" is the variable which holds the difference between the last check and now (basically frames since last check, not per second).

But there are some more problems in your code.

You mix up playerid with the target id several times. Furthermore you get the target id from the input AFTER actually using it. That will lead to ID 0 always being the target...

This is what it could look like:

Код:
CMD:fps(playerid, params[])
{
   new
      target,
      str[64],
      PlayerName[MAX_PLAYER_NAME];

   if (sscanf(params, "u", target)) target = playerid; // Put this check here otherwise "target" will be zero in the code below

   GetPlayerName(target, PlayerName, sizeof(PlayerName));

   new curlevel = GetPlayerDrunkLevel(target);

   if(curlevel > 100 && gDrunkLevelLast[target] != curlevel)
   {
      new gfps = gDrunkLevelLast[target] - curlevel, // This is NOT the actual FPS yet, it's only the number of frames since the last check!
         ms = GetTickCount() - gDrunkLevelTimeStamp[target], // Time between last check and now
         Float:fps = float(gfps) / (float(ms) / 1000.0); // Actual FPS

      if ((fps > 0.0) && (fps < 200.0)) gFPS[target] = floatround(fps);
      else gFPS[target] = 0;
   }
   else gFPS[target] = 0;

   SetPlayerDrunkLevel(target, 2000);
   gDrunkLevelTimeStamp[target] = GetTickCount();
   gDrunkLevelLast[target] = 2000;

   if(gFPS[target] == 0)
   {
      format(str,sizeof(str), "SERVER: Started measuring FPS for %s.", PlayerName);

      SendClientMessage(playerid, -1, str);
   }
   else
   {
      format(str,sizeof(str), "SERVER: %s's fps is %d", PlayerName, gFPS[target]);

      SendClientMessage(playerid, -1, str);
   }

   return true;
}
And add this to whereever you declare gDrunkLevelLast:

Код:
new gDrunkLevelTimeStamp[MAX_PLAYRES];
The main problem however is, that the FPS will start measuring only if you type the command.

Only when typing it a second time it will show the actual FPS since the first time you entered it.
I also suggest resetting gDrunkLevelLast to 0 when a player connects or disconnects.

I added that it will show a message that the FPS measuring hast started when you first type it.
If you want the FPS to be measured at all times, you'll need to execute this code (the middle part of it) in a timer.

Sorry for the indentation, can't really use TAB in Firefox.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)