Gastonito Posted November 7, 2016 Share Posted November 7, 2016 Hello guys, i have this Scoreboard-Fps script : ( It isnt mine ) local ping = getPlayerPing(getLocalPlayer()) local x, y = guiGetScreenSize ( ) r,g,b=0,0,0 alpha=150 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 end ) function drawStates () addEventHandler ( "onClientRender", root, pingState ) addEventHandler ( "onClientRender", root, fpsState ) end addEventHandler ( "onClientResourceStart", resourceRoot, drawStates ) function pingState() posx= x-30 posy= 20 dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r, g, b, alpha ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r, g, b, alpha ) ) dxDrawRectangle ( posx+10, posy-8, 4,12, tocolor ( r, g, b, alpha ) ) dxDrawRectangle ( posx+15, posy-12, 4,16, tocolor ( r, g, b, alpha ) ) dxDrawRectangle ( posx+20, posy-16, 4,20, tocolor ( r, g, b, alpha ) ) r2,g2,b2=255,0,0 alpha2=255 if ping <= 100 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+10, posy-8, 4,12, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+15, posy-12, 4,16, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+20, posy-16, 4,20, tocolor ( r2, g2, b2, alpha2 ) ) elseif ping >=101 and ping <= 200 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+10, posy-8, 4,12, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+15, posy-12, 4,16, tocolor ( r2, g2, b2, alpha2 ) ) elseif ping >=201 and ping <= 300 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+10, posy-8, 4,12, tocolor ( r2, g2, b2, alpha2 ) ) elseif ping >=301 and ping <= 400 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r2, g2, b2, alpha2 ) ) elseif ping >=401 and ping <= 500 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) end end function fpsState() posx2= x-55 posy2= 13 dxDrawText ( getElementData(getLocalPlayer(),"FPS"), posx2-12, posy2-6, x, y, tocolor ( 255, 255, 255, 255 ), 1.4, "default-bold" ) dxDrawText ( "FPS", posx2-13, posy2+10, x, y, tocolor ( 255, 255, 255, 255 ), 1.0, "default-bold" ) dxDrawText ( "PING", posx2+23, posy2+10, x, y, tocolor ( 255, 255, 255, 255 ), 1.0, "default-bold" ) end And i got this error : 2016-11-07 17:27:15] WARNING: SAEGsco-fps\client.lua:87: Bad argument @ 'dxDrawText' [Expected string at argument 1, got boolean] So can anyone help me ? Link to comment
LoPollo Posted November 7, 2016 Share Posted November 7, 2016 (edited) getElementData(getLocalPlayer(),"FPS") will return false if the data does not exists. --line 20 of the code if currenttick - starttick >= 1000 then setElementData(player,"FPS",counter) counter = 0 starttick = false end The data doesn't exist for the first second since no measurement has been made. There are 2 solutions: 1. at line 87 check if the data exist before calling dxDrawText; 2. replace the code i copied above with this to create dummy data and avoid the error: --line 20 of the code if currenttick - starttick >= 1000 then setElementData(player,"FPS",counter) counter = 0 starttick = false else setElementData(player,"FPS","N/A") end I did not test anything, let me know if this help Edited November 7, 2016 by LoPollo bad english Link to comment
Gastonito Posted November 10, 2016 Author Share Posted November 10, 2016 On 7/11/2016 at 10:48 PM, LoPollo said: getElementData(getLocalPlayer(),"FPS") will return false if the data does not exists. --line 20 of the code if currenttick - starttick >= 1000 then setElementData(player,"FPS",counter) counter = 0 starttick = false end The data doesn't exist for the first second since no measurement has been made. There are 2 solutions: 1. at line 87 check if the data exist before calling dxDrawText; 2. replace the code i copied above with this to create dummy data and avoid the error: --line 20 of the code if currenttick - starttick >= 1000 then setElementData(player,"FPS",counter) counter = 0 starttick = false else setElementData(player,"FPS","N/A") end I did not test anything, let me know if this help The erros stopped, but the FPS show N/A Link to comment
LoPollo Posted November 10, 2016 Share Posted November 10, 2016 (edited) It should show N/A only the first time , when there's no data. After the handler function at line 14 updates the data (when currenttick - starttick >= 1000) getElementData at line 87 should return the value of the measurement and then draw the value on the screen is there any error threw clientside? If an error happened it shouldn't draw anything at all... still have you checked the clientscript.log? I don't know where to see cause the script seems ok Do you know what? i'm an idiot You must have used the code i gave you, where i added an "else" setting the "N/A". so the N/A is displayed for every frame which is not the first after every second. Thus to correct the problem delete the else and cut the line with setElementData(player,"FPS","N/A") pasting it in a function, called when the resource starts (preferred), or simply outside any function at the start of the script after declaring variables (i.e. between line 12 and 13 of the code) Otherwise you can replace line 87 with this: dxDrawText ( getElementData(getLocalPlayer(),"FPS") or "N/A", posx2-12, posy2-6, x, y, tocolor ( 255, 255, 255, 255 ), 1.4, "default-bold" ) Edited November 10, 2016 by LoPollo Link to comment
Gastonito Posted November 11, 2016 Author Share Posted November 11, 2016 21 hours ago, LoPollo said: It should show N/A only the first time , when there's no data. After the handler function at line 14 updates the data (when currenttick - starttick >= 1000) getElementData at line 87 should return the value of the measurement and then draw the value on the screen is there any error threw clientside? If an error happened it shouldn't draw anything at all... still have you checked the clientscript.log? I don't know where to see cause the script seems ok Do you know what? i'm an idiot You must have used the code i gave you, where i added an "else" setting the "N/A". so the N/A is displayed for every frame which is not the first after every second. Thus to correct the problem delete the else and cut the line with setElementData(player,"FPS","N/A") pasting it in a function, called when the resource starts (preferred), or simply outside any function at the start of the script after declaring variables (i.e. between line 12 and 13 of the code) Otherwise you can replace line 87 with this: dxDrawText ( getElementData(getLocalPlayer(),"FPS") or "N/A", posx2-12, posy2-6, x, y, tocolor ( 255, 255, 255, 255 ), 1.4, "default-bold" ) i didnt get it could u just fix the code and resent it please Link to comment
LoPollo Posted November 11, 2016 Share Posted November 11, 2016 Sure Spoiler local ping = getPlayerPing(getLocalPlayer()) local x, y = guiGetScreenSize ( ) r,g,b=0,0,0 alpha=150 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 end ) function drawStates () addEventHandler ( "onClientRender", root, pingState ) addEventHandler ( "onClientRender", root, fpsState ) end addEventHandler ( "onClientResourceStart", resourceRoot, drawStates ) function pingState() posx= x-30 posy= 20 dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r, g, b, alpha ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r, g, b, alpha ) ) dxDrawRectangle ( posx+10, posy-8, 4,12, tocolor ( r, g, b, alpha ) ) dxDrawRectangle ( posx+15, posy-12, 4,16, tocolor ( r, g, b, alpha ) ) dxDrawRectangle ( posx+20, posy-16, 4,20, tocolor ( r, g, b, alpha ) ) r2,g2,b2=255,0,0 alpha2=255 if ping <= 100 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+10, posy-8, 4,12, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+15, posy-12, 4,16, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+20, posy-16, 4,20, tocolor ( r2, g2, b2, alpha2 ) ) elseif ping >=101 and ping <= 200 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+10, posy-8, 4,12, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+15, posy-12, 4,16, tocolor ( r2, g2, b2, alpha2 ) ) elseif ping >=201 and ping <= 300 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+10, posy-8, 4,12, tocolor ( r2, g2, b2, alpha2 ) ) elseif ping >=301 and ping <= 400 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) dxDrawRectangle ( posx+5, posy-4, 4,8, tocolor ( r2, g2, b2, alpha2 ) ) elseif ping >=401 and ping <= 500 then dxDrawRectangle ( posx, posy, 4, 4, tocolor ( r2, g2, b2, alpha2 ) ) end end function fpsState() posx2= x-55 posy2= 13 dxDrawText ( getElementData(getLocalPlayer(),"FPS") or "N/A", posx2-12, posy2-6, x, y, tocolor ( 255, 255, 255, 255 ), 1.4, "default-bold" ) dxDrawText ( "FPS", posx2-13, posy2+10, x, y, tocolor ( 255, 255, 255, 255 ), 1.0, "default-bold" ) dxDrawText ( "PING", posx2+23, posy2+10, x, y, tocolor ( 255, 255, 255, 255 ), 1.0, "default-bold" ) end If i didn't forgot anything it should work Link to comment
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