Jump to content

script using too much cpu


xTravax

Recommended Posts

-- custom functions 
function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) 
    if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then 
        return false 
    end 
  
    local function clamp( val, lower, upper ) 
        if ( lower > upper ) then lower, upper = upper, lower end 
        return math.max( lower, math.min( upper, val ) ) 
    end 
  
    radius = type( radius ) == "number" and radius or 50 
    width = type( width ) == "number" and width or 5 
    angleAmount = type( angleAmount ) == "number" and angleAmount or 1 
    startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) 
    stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) 
    color = color or tocolor( 255, 255, 255, 200 ) 
    postGUI = type( postGUI ) == "boolean" and postGUI or false 
  
    if ( stopAngle < startAngle ) then 
        local tempAngle = stopAngle 
        stopAngle = startAngle 
        startAngle = tempAngle 
    end 
  
    for i = startAngle, stopAngle, angleAmount do 
        local startX = math.cos( math.rad( i ) ) * ( radius - width ) 
        local startY = math.sin( math.rad( i ) ) * ( radius - width ) 
        local endX = math.cos( math.rad( i ) ) * ( radius + width ) 
        local endY = math.sin( math.rad( i ) ) * ( radius + width ) 
  
        dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) 
    end 
  
    return true 
end 
  
  
  
--using custom functions partial circle 
pHealth = 100 
  
 setTimer(function() 
 pHealth = getElementHealth(localPlayer) 
 outputChatBox(pHealth) 
 end,50,1) 
  
 function onDamage() 
pHealth = getElementHealth(source) 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(),onDamage) 
  
    function healthHud( ) 
    if getElementData(localPlayer,"UI") == "hidden" then return end 
    --local circle = getElementHealth(localPlayer) 
  
  
  
         
  
        dxDrawCircle( 200, 200, 52, 5, 1, 0, pHealth*3.6,tocolor(0,0,0,255) ) 
        dxDrawCircle( 200, 200, 44, 1, 1, 0, pHealth*3.6,tocolor(0,0,0,255) ) 
        dxDrawCircle( 200, 200, 50, 5, 1, 0, pHealth*3.6,tocolor(255,0,0,255) ) 
  
    end 
addEventHandler( "onClientRender", root,healthHud) 
  
  
function onDeath() 
pHealth = 0 
removeEventHandler("onClientRender",root,healthHud) 
end 
addEventHandler("onClientPlayerWasted",getLocalPlayer(),onDeath) 
  
function onSpawn() 
addEventHandler("onClientRender",root,healthHud) 
pHealth = getElementHealth(source) 
end 
addEventHandler("onClientPlayerSpawn",getLocalPlayer(),onSpawn) 

so its just a basic simple health circled hud and perfomancebrowser is reporting that this script is using 20-30% of client(me) cpu and when looking at server

i have no idea why, no debugscript 3 errors.

is it problem in me or i have to optimize the script somehow?

Link to comment
-- custom functions 
function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) 
    if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then 
        return false 
    end 
  
    local function clamp( val, lower, upper ) 
        if ( lower > upper ) then lower, upper = upper, lower end 
        return math.max( lower, math.min( upper, val ) ) 
    end 
  
    radius = type( radius ) == "number" and radius or 50 
    width = type( width ) == "number" and width or 5 
    angleAmount = type( angleAmount ) == "number" and angleAmount or 1 
    startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) 
    stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) 
    color = color or tocolor( 255, 255, 255, 200 ) 
    postGUI = type( postGUI ) == "boolean" and postGUI or false 
  
    if ( stopAngle < startAngle ) then 
        local tempAngle = stopAngle 
        stopAngle = startAngle 
        startAngle = tempAngle 
    end 
  
    for i = startAngle, stopAngle, angleAmount do 
        local startX = math.cos( math.rad( i ) ) * ( radius - width ) 
        local startY = math.sin( math.rad( i ) ) * ( radius - width ) 
        local endX = math.cos( math.rad( i ) ) * ( radius + width ) 
        local endY = math.sin( math.rad( i ) ) * ( radius + width ) 
  
        dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) 
    end 
  
    return true 
end 
  
  
  
--using custom functions partial circle 
pHealth = 100 
  
 setTimer(function() 
 pHealth = getElementHealth(localPlayer) 
 outputChatBox(pHealth) 
 end,50,1) 
  
 function onDamage() 
pHealth = getElementHealth(source) 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(),onDamage) 
  
    function healthHud( ) 
    if getElementData(localPlayer,"UI") == "hidden" then return end 
    --local circle = getElementHealth(localPlayer) 
  
  
  
         
  
        dxDrawCircle( 200, 200, 52, 5, 1, 0, pHealth*3.6,tocolor(0,0,0,255) ) 
        dxDrawCircle( 200, 200, 44, 1, 1, 0, pHealth*3.6,tocolor(0,0,0,255) ) 
        dxDrawCircle( 200, 200, 50, 5, 1, 0, pHealth*3.6,tocolor(255,0,0,255) ) 
  
    end 
addEventHandler( "onClientRender", root,healthHud) 
  
  
function onDeath() 
pHealth = 0 
removeEventHandler("onClientRender",root,healthHud) 
end 
addEventHandler("onClientPlayerWasted",getLocalPlayer(),onDeath) 
  
function onSpawn() 
addEventHandler("onClientRender",root,healthHud) 
pHealth = getElementHealth(source) 
end 
addEventHandler("onClientPlayerSpawn",getLocalPlayer(),onSpawn) 

so its just a basic simple health circled hud and perfomancebrowser is reporting that this script is using 20-30% of client(me) cpu and when looking at server

i have no idea why, no debugscript 3 errors.

is it problem in me or i have to optimize the script somehow?

I have not found errors but dxDrawLine uses much cpu.

Link to comment
loops? will do with that dxDraw Cycle disappear,we're talking about rendering.

That will draw many dx-lines on every render, is that what should be causing the problem with the performance.

You can edit that code and see by yourself how many dx-lines are being drawn on every render.

Link to comment

if i use images, it would be hard to make it(smooth) and also it wouldn't be smooth as i have no idea how would i do that unfortunately.

drawing rectangles.. not sure how would i do that

and saml1er,code can work faster but cpu usage wont change a bit(tested)

how does race gamemode draw its blue speedometer bar though?(i know, by images yes but i meant how does it draw images next to each other so perfectly..)

race gamemode itself doesn't consume much cpu and it does same thing im doing except its not in a circle

Link to comment
if i use images, it would be hard to make it(smooth) and also it wouldn't be smooth as i have no idea how would i do that unfortunately.

drawing rectangles.. not sure how would i do that

and saml1er,code can work faster but cpu usage wont change a bit(tested)

how does race gamemode draw its blue speedometer bar though?(i know, by images yes but i meant how does it draw images next to each other so perfectly..)

race gamemode itself doesn't consume much cpu and it does same thing im doing except its not in a circle

local loop,pHealth,screeW,screeY = 100,0,guiGetScreenSize() local dxDrawHealth = function() 
 pHealth = getElementHealth(localPlayer) 
 if getElementHealth(localPlayer) > 0 then 
  for count = 1, loop do 
  if count < pHealth then color = tocolor(255, 0, 0, 255) else color = tocolor(0, 0, 0, 255) end 
    dxDrawImage(screeW / 2 - 200, screeY * 0.200 - 64, 80, 80, "PJYtOH.png", 360 / loop * (count - 1), 0, 0, color) 
  end 
  for count = pHealth - 3, pHealth do 
    if count > 0 then 
    color = tocolor(255, 0, 0, 255) 
      dxDrawImage(screeW / 2 - 200, screeY * 0.200 - 64, 80, 80, "PJYtOH.png", 360 / loop * count, 0, 0, color) 
    end 
   end 
  end 
end 
addEventHandler("onClientRender",root, dxDrawHealth) 

PJYtOH.png download img

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