xTravax Posted October 17, 2014 Share Posted October 17, 2014 -- 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
ZL|LuCaS Posted October 17, 2014 Share Posted October 17, 2014 -- 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
xTravax Posted October 17, 2014 Author Share Posted October 17, 2014 so basically i have to cancel my whole hud project just because mta function uses much cpu? mta has dissapointed me once again Link to comment
ZL|LuCaS Posted October 17, 2014 Share Posted October 17, 2014 so basically i have to cancel my whole hud project just because mta function uses much cpu?mta has dissapointed me once again you it can use dxDrawImage with a loop, is more efficient, I do not use dxDrawLine. Link to comment
DNL291 Posted October 17, 2014 Share Posted October 17, 2014 That's because dxDrawLine function is used several times. You have other alternatives to create that circle. Link to comment
RenanPG Posted October 17, 2014 Share Posted October 17, 2014 That's because dxDrawLine function is used several times.You have other alternatives to create that circle. Try using images. Link to comment
ZL|LuCaS Posted October 17, 2014 Share Posted October 17, 2014 (edited) That's because dxDrawLine function is used several times.You have other alternatives to create that circle. not because dxDrawCircle will only work with Rendering Edited October 17, 2014 by Guest Link to comment
RenanPG Posted October 17, 2014 Share Posted October 17, 2014 That's because dxDrawLine function is used several times.You have other alternatives to create that circle. not because dxDrawCircle will only work with Rendering dxDrawCircle make a loop with lines every frame rendering, DNL291 are right and that's why lag. Link to comment
ZL|LuCaS Posted October 17, 2014 Share Posted October 17, 2014 loops? will do with that dxDraw Cycle disappear,we're talking about rendering. Link to comment
#RooTs Posted October 17, 2014 Share Posted October 17, 2014 you can use dxDrawRectangle dxDrawRectangle ( x*500, y*500, x*200, y*002, tocolor ( 0, 0, 0, 150 ) ) instead of dxDrawLine just arrange his height to 1% or 2% (1 pixels ) OBS: is just an idea Link to comment
RenanPG Posted October 17, 2014 Share Posted October 17, 2014 loops? will do with that dxDraw Cycle disappear,we're talking about rendering. Read the code again. Link to comment
DNL291 Posted October 17, 2014 Share Posted October 17, 2014 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
Saml1er Posted October 17, 2014 Share Posted October 17, 2014 If u still plan on using this then just make variables and functions local, this will at least speed up accessing variables which make the code to work faster. Link to comment
xTravax Posted October 17, 2014 Author Share Posted October 17, 2014 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
ZL|LuCaS Posted October 17, 2014 Share Posted October 17, 2014 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) download img 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