Jump to content

(JavaScript) FPS Script


Recommended Posts

Hello, I thought It would be a good idea if I shared the FPS script that I'm using on my RageMP Server. Everything is going to be client-side only.

First of all, we'll need to import our fps.js file into our index.js file, like so:


Client-Side Logic:

let fpsBrowser = null;
let frameCount = 0;
let lastTickTime = Date.now();

// This function should be called every time the game renders a frame.
function onFrameRendered() {

// This function calculates the FPS and should be called at a regular interval.
function calculateFPS() {
  const currentTickTime = Date.now();
  const timePassed = currentTickTime - lastTickTime;
  const fps = (frameCount / timePassed) * 1000;

  // Send FPS to CEF browser
  if (fpsBrowser) {

  // Reset the counter and timestamp after calculating FPS
  frameCount = 0;
  lastTickTime = currentTickTime;

// Setup the FPS browser and start calculating FPS
mp.events.add("render", onFrameRendered);
setInterval(calculateFPS, 1000); // Update the FPS every second

// Function to create and show the FPS browser
function showFPSBrowser() {
  if (fpsBrowser == null) {
    fpsBrowser = mp.browsers.new("package://CEF/fps/fps.html");

// Function to close and destroy the FPS browser
function closeFPSBrowser() {
  if (fpsBrowser !== null) {
    fpsBrowser = null;

// Keybind to toggle FPS display
mp.keys.bind(0x78, false, () => {
  // F9 key
  if (fpsBrowser == null) {
  } else {

CEF Browser Logic:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <title>FPS Display</title>
      #fpsCounter {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 10;
        color: #ffffff;
        font-family: Arial, sans-serif;
        font-size: 12px;
        line-height: 14px;
        font-weight: bold;
        padding: 5px 10px;
        user-select: none;
        background-color: rgba(0, 0, 0, 0.5);
    <div id="fpsCounter">FPS: 0</div>
      // This function will be called from the client-side script
      function updateFPS(fps) {
        document.getElementById("fpsCounter").textContent = `FPS: ${fps}`;


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...