Baseplate Posted July 29, 2013 Posted July 29, 2013 Hello everyone, well I tried to make an FPS Calculator and tried to tweak This resource with dxDrawText but it doesn't create any text. Code --Client-side 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 dxDrawText(""..counter.."", 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false) counter = 0 starttick = false end end )
Wei Posted July 29, 2013 Posted July 29, 2013 local root = getRootElement() 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 dxDrawText(""..counter.."", 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false) end ) This should work
Baseplate Posted July 29, 2013 Author Posted July 29, 2013 Thanks, but it wasn't working fine so I found another way and it works fine now.
Vector Posted July 29, 2013 Posted July 29, 2013 this is better.. local fps; local updateTick; addEventHandler ("onClientPreRender", getRootElement (), function (dt) if (not updateTick) or ((getTickCount () - updateTick)>1000) then fps = math.floor ( 1000 / dt ); updateTick = getTickCount (); end; end); addEventHandler ("onClientRender", getRootElement (), function () dxDrawText ("FPS: " .. tostring(fps) , 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false); end);
Moderators IIYAMA Posted July 29, 2013 Moderators Posted July 29, 2013 this is better.. It isn't, more handlers give more lagg. onClientRender is just fine, you don't need to calculate so much, for so little improvements with the correct timing. But it is nice that there is another way of doing.
Vector Posted July 29, 2013 Posted July 29, 2013 ok. I don´t know that. i said it´s best because its a more clear solution.
Baseplate Posted July 29, 2013 Author Posted July 29, 2013 I did use that resource, started it, then all I had to do was getting the localPlayer's element data with onClientRender then it draws the text.
Moderators IIYAMA Posted July 29, 2013 Moderators Posted July 29, 2013 ok. I don´t know that.i said it´s best because its a more clear solution. Not really precisely, cause you only check the amount of fps from one pre-frame, not from a second. But the good thing about it, that it shows us direct big fps drops, I tried that part of you. It jumps from 66 t/m 56, my fps is stable and it makes changes with 10 fps. but it detect big fps drops directly:(I tried this) local updateTick,lastFPSUpdate = 0,0 addEventHandler ("onClientPreRender", root, function (dt) local fps = math.floor ( 1000 / dt ) if lastFPSUpdate-fps > 30 and (not updateTick or getTickCount () - updateTick > 500) then updateTick = getTickCount () outputChatBox("big fps drop") end lastFPSUpdate = fps end) @abxf, local counter = 0 local starttick local fps =0 addEventHandler("onClientRender",root, function() if not starttick then starttick = getTickCount() end counter = counter+1 if getTickCount() - starttick >= 1000 then fps = counter starttick,counter = false,0 end dxDrawText(""..fps.."", 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false) end )
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