15.03.2018, 12:35
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:
And add this to whereever you declare gDrunkLevelLast:
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.
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; }
Код:
new gDrunkLevelTimeStamp[MAX_PLAYRES];
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.