Jump to content

Simplify function


ds1-e

Recommended Posts

  • Scripting Moderators

Hey, any idea how to make this simpler?

math.floor(math.round(player_blood/90/(90000/90/90), 2)).."L" -- this thing

--

function math.round(number, decimals, method)
	decimals = decimals or 0
	local factor = 10 ^ decimals
	if (method == "ceil" or method == "floor") then 
		return math[method](number * factor)/factor
	else 
		return tonumber(("%."..decimals.."f"):format(number))
	end
end

 

Edited by majqq
Link to comment
  • Scripting Moderators
11 hours ago, salh said:

in 1

what the player_blood

Integer.

7 hours ago, DNL291 said:

It would be useful if you explain what this code is supposed to do. What do you want to do besides simplify the calculation?

Convert integer. For example:

12000 > 12

11000 > 11

5000 > 5

1000 > 1

less or equal to 999 > 0

Link to comment
  • Scripting Moderators
3 minutes ago, savour said:

are you talking about the amount of code or the process itself?

 

I would like to make it simpler, instead of using math.floor + math.round, if possible. I use this with onClientRender.

Link to comment
1 hour ago, majqq said:

Convert integer. For example:

12000 > 12

 11000 > 11

5000 > 5

 1000 > 1

 less or equal to 999 > 0

well, from what i see here you don't really need the round method

math.floor(12345/1000) = 12

math.floor(19999/1000) = 19

math.floor(999/1000) = 0

also for more optimization, avoid using the OOP on render events, since it uses double the resources (from my experience) also you can make some value setters outside the render events (that changes the value after something is happened) and use the final results only on rendering

  • Like 1
Link to comment
  • Scripting Moderators
43 minutes ago, savour said:

well, from what i see here you don't really need the round method

math.floor(12345/1000) = 12

math.floor(19999/1000) = 19

math.floor(999/1000) = 0

also for more optimization, avoid using the OOP on render events, since it uses double the resources (from my experience) also you can make some value setters outside the render events (that changes the value after something is happened) and use the final results only on rendering

Thank you :P

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