..:D&G:.. Posted August 4, 2015 Posted August 4, 2015 Hello guys, I am making a scoreboard and I would like to add the player's FPS to it, but I can't find any function to get a certain player's FPS... So, is there any way I can do that? Thanks.
Buffalo Posted August 4, 2015 Posted August 4, 2015 local player = getLocalPlayer() local counter = 0 local starttick local currenttick addEventHandler("onClientRender",root, function() if not starttick then starttick = getTickCount() end counter = counter + 1 currenttick = getTickCount() if currenttick - starttick >= 1000 then setElementData(player,"FPS",counter) counter = 0 starttick = false end end )
MTA Team botder Posted August 4, 2015 MTA Team Posted August 4, 2015 onClientPreRender Notice (not quite sure about this): This number might be inaccurate, because pre-rendered frames might be dropped, which will show higher FPS (prerendered) than the actual FPS (rendered). local framesPerSecond = 0 local framesDeltaTime = 0 addEventHandler("onClientPreRender", root, function (deltaTime) framesDeltaTime = framesDeltaTime + deltaTime framesPerSecond = framesPerSecond + 1 if framesDeltaTime >= 1000 then setElementData(localPlayer, "fps", framesPerSecond) framesDeltaTime = framesDeltaTime - 1000 framesPerSecond = 0 end end ) onClientRender local framesPerSecond = 0 local framesDeltaTime = 0 local lastRenderTick = false addEventHandler("onClientRender", root, function () local currentTick = getTickCount() lastRenderTick = lastRenderTick or currentTick framesDeltaTime = framesDeltaTime + (currentTick - lastRenderTick) lastRenderTick = currentTick framesPerSecond = framesPerSecond + 1 if framesDeltaTime >= 1000 then setElementData(localPlayer, "fps", framesPerSecond) framesDeltaTime = framesDeltaTime - 1000 framesPerSecond = 0 end end ) @ getCurrentFPS This example is even more inaccurate than onClientPreRender because it may jump randomly between 0-FPSLIMIT, depending on CPU usage. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now