Jump to content

HELP FPS


K4stic

Recommended Posts

Problem then i type /myfps it show then i again type /myfps it's hide it but if i again type /myfps then is not show it me again

No Error's in Debugscript

local FPSLimit = 100 
local FPSMax = 1 
  
function onClientResourceStart ( resource ) 
    if ( guiFPSLabel == nil ) then 
        FPSLimit = 255 / FPSLimit 
        guiFPSLabel = guiCreateLabel ( 0.03, 0.97, 0.1, 0.1, "FPS: 0", true ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
        addEventHandler ( "onClientRender", root, onClientRender ) 
    else 
        guiSetText ( guiFPSLabel, nil ) 
    end 
end 
addCommandHandler("myfps", onClientResourceStart) 
  
function onClientRender ( ) 
    if ( getTickCount() < FPSTime ) then 
        FPSCalc = FPSCalc + 1 
    else 
        if ( FPSCalc > FPSMax ) then FPSLimit = 255 / FPSCalc FPSMax = FPSCalc end 
        guiSetText ( guiFPSLabel, "FPS: "..FPSCalc.." Max: "..FPSMax ) 
        guiLabelSetColor ( guiFPSLabel, 255 - math.ceil ( FPSCalc * FPSLimit ), math.ceil ( FPSCalc * FPSLimit ), 0 ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
    end 
end 
  

Link to comment
  • Moderators
function onClientResourceStart ( resource ) 
    if ( guiFPSLabel == nil ) then 
        FPSLimit = 255 / FPSLimit 
        guiFPSLabel = guiCreateLabel ( 0.03, 0.97, 0.1, 0.1, "FPS: 0", true ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
        addEventHandler ( "onClientRender", root, onClientRender )  
    else 
        guiSetText ( guiFPSLabel, nil ) 
        destroyElement(guiFPSLabel) 
        guiFPSLabel = nil --? 
        removeEventHandler ( "onClientRender", root, onClientRender ) -- you have to remove it before you can handle it again. 
    end 
end 
addCommandHandler("myfps", onClientResourceStart) 

Edited by Guest
Link to comment
  • Moderators

1: login as admin

2: /debugscript 3

local A = 1 
  
if A == 1 then 
  outputDebugString ("A is 1") 
else 
  outputDebugString ("A isn't 1") 
end 
  

This kind of string has been designed to output information, so your chat won't be spammed with debug information.

This is how I check my scripts when they don't work and I can't find the problem.

A == 1000 
  
if A > 10 then 
   outputDebugString ("A is higher then 10") 
   if A > 100 then 
      outputDebugString ("A is higher then 100") 
       if A > 300 then 
          outputDebugString ("A is higher then 300") 
          if A > 1000 then 
          outputDebugString ("A is higher then 1000") 
          end 
       end 
    end    
end 
outputDebugString ("A is this value:" .. A ) -- check how big a value is. 

Link to comment

ok now work but it's output me to debugscript that

line 14:RemoveEventHandler(a nil value)

local FPSLimit = 100 
local FPSMax = 1 
  
function onClientResourceStart ( resource ) 
    if ( guiFPSLabel == nil ) then 
        FPSLimit = 255 / FPSLimit 
        guiFPSLabel = guiCreateLabel ( 0.03, 0.97, 0.1, 0.1, "FPS: 0", true ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
        addEventHandler ( "onClientRender", root, onClientRender ) 
    else 
        guiSetText ( guiFPSLabel, "" ) 
        destroyElement(guiFPSLabel) 
        RemoveEventHandler ( "onClientRender", root, onClientRender ) 
    end 
end 
addCommandHandler("myfps", onClientResourceStart) 
  
function onClientRender ( ) 
    if ( getTickCount() < FPSTime ) then 
        FPSCalc = FPSCalc + 1 
    else 
        if ( FPSCalc > FPSMax ) then FPSLimit = 255 / FPSCalc FPSMax = FPSCalc end 
        guiSetText ( guiFPSLabel, "FPS: "..FPSCalc.." Max: "..FPSMax ) 
        guiLabelSetColor ( guiFPSLabel, 255 - math.ceil ( FPSCalc * FPSLimit ), math.ceil ( FPSCalc * FPSLimit ), 0 ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
    end 
end 
  

Link to comment
  • Moderators

as I said I don't know what is wrong with it, I can't test it at the moment...

Tell me what the string out puts by the 3e time.

local FPSLimit = 100 
local FPSMax = 1 
  
addCommandHandler("myfps", 
function (  ) 
    if not guiFPSLabel  then 
        FPSLimit = 255 / FPSLimit 
        guiFPSLabel = guiCreateLabel ( 0.03, 0.97, 0.1, 0.1, "FPS: 0", true ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
        addEventHandler ( "onClientRender", root, onClientRender ) 
        outputDebugString ("label created") 
    else 
        guiSetText ( guiFPSLabel, "" ) 
        destroyElement(guiFPSLabel) 
        guiFPSLabel = nil 
        removeEventHandler ( "onClientRender", root, onClientRender ) 
       outputDebugString ("label destroyed")  
    end 
end) 
  
  
function onClientRender ( ) 
    if ( getTickCount() < FPSTime ) then 
        FPSCalc = FPSCalc + 1 
    else 
        if ( FPSCalc > FPSMax ) then FPSLimit = 255 / FPSCalc FPSMax = FPSCalc end 
        guiSetText ( guiFPSLabel, "FPS: "..FPSCalc.." Max: "..FPSMax ) 
        guiLabelSetColor ( guiFPSLabel, 255 - math.ceil ( FPSCalc * FPSLimit ), math.ceil ( FPSCalc * FPSLimit ), 0 ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
    end 
end 

Updated at 14:25. (germany/Netherlands timezone)

Link to comment

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...