I don’t want to write code like this
if damage > 30 and damage < 40 then bloodamount = 2
elseif damage > 40 and damage < 63 then bloodamount = 4
(and so on...)
I want to make a goood and efficient calculation method, how would I do this?
I don’t want to write code like this
if damage > 30 and damage < 40 then bloodamount = 2
elseif damage > 40 and damage < 63 then bloodamount = 4
(and so on...)
I want to make a goood and efficient calculation method, how would I do this?
Use a function. Input one number value get another number value returned.
You can use a linear function y =MX + b and math.round the final value to get the blood amount.
You can also use a number sequence and map out the range of values from a damage range to another blood amount range.
I honestly have no clue about scripting, but imma just say maybe make a system where there’s around 5-10 blood splatters if shot past 100 hp
each blood splatter will be a representation of how much hp was lost, so if you lose 10hp for example, a medium-big sized splatter wil appear, and if you lose 2 hp, a small one will appear, and the blood splatters can merge with the more hp you lose
sorry if it makes no sense, but it’s just an idea.
Found the solution myself!
--example
local last_health = 100;
local current_health = 50;
local difference = math.abs(last_health-current_health);
local blood_amount = math.clamp(difference*.3, 0, 13);