developa Posted September 23, 2017 Share Posted September 23, 2017 (edited) How to optimize this code? local imagePosX,imagePosY,imagePosZ = -21.38184, 5.24524, 3.10965 addEventHandler("onClientPreRender", root, function() local position = {getScreenFromWorldPosition(imagePosX, imagePosY, imagePosZ)} if position[1] and position[2] then local ceiling = math.ceil local distance = (Vector3(localPlayer.position)-Vector3(imagePosX, imagePosY, imagePosZ)).length dxDrawRectangle((position[1]+10/2)-5, position[2]+10/2, dxGetTextWidth(ceiling(distance), 0.6, "default-bold")+10, 20, tocolor(255, 0, 0), false) dxDrawText(ceiling(distance), position[1]+10/2, position[2]+10/2, 10, 10, tocolor(0, 255, 0), 1, "default-bold") end end) Edited September 23, 2017 by developa Link to comment
Moderators IIYAMA Posted September 24, 2017 Moderators Share Posted September 24, 2017 It looks fine to me as it is. If you want super - super optimization. You could pre-define the colors on top of the function. Not using a table on line 3, but 2 separated variables. (indexing tables cost time) Put this on top of the function: local ceiling = math.ceil Even though I do not recommend you to optimize it that far, except if you execute 100+ dx functions per frame. Scripts should stay readable. And you can also compile it to improve the performance. 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