How do I turn value into % ?

Get help using Construct 2

Post » Sat Jan 14, 2017 6:08 pm

Greetings there! ^_^
So i am designing an armor system as a string value. When being hit, i want to reduce the dmg by the value of the armor in %
- Let's say damge is 50 and armor is 20, i want the damage to be reduced by armor in % and not flat out 20.

Is there some way to do this?
Player in collission with Bullet, substract from player health 20-Player.armor (this will be flat out 20, but i want the 20 to be %, how to do this?)

Thanks in advance!
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sat Jan 14, 2017 6:29 pm

[armor] - [dmg] * multiplier

Set the multiplier to 0.2 to only use 20% of the damage.
Use 0.5 to use 50%.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Jan 14, 2017 6:50 pm

randomly wrote:[armor] - [dmg] * multiplier

Set the multiplier to 0.2 to only use 20% of the damage.
Use 0.5 to use 50%.


Im sorry what? That does not make any sense to me, sorry.
Basically when Player is in colission with bullet -
Subsctract Damage - Armor from Health

If armor is the value of 20, i wanna turn it into 20%
So if Damage is 100, it should be 100-20% = 80 dmg from health
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sat Jan 14, 2017 7:11 pm

round(value / value) * 100

round(55 / 80) * 100 = 69%

edit: if you want the value from the percentage:

(percentage / 100) * value

round(69 / 100) * 80 = 55
Image
B
30
S
9
G
3
Posts: 171
Reputation: 3,334

Post » Sat Jan 14, 2017 7:27 pm

gameglaux wrote:round(value / value) * 100

round(55 / 80) * 100 = 69%


Im sorry what? That explains nothing... Like seriously i know u guys trying to help but ur not making sense at all.

My Code is, ''Substract From ''Health''; Damage - armor''
Health = 150
Damage = 60
Armor = 20

I want the code above to deal 60 dmg - 20% (armor.)
I cant make it a constant 20% since armor will vary..
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sat Jan 14, 2017 8:12 pm

Divide by 100 to get percent. (20/100 = 0.2 AKA 20%)
multiply result to get percentage (0.2 * 60 = 12 AKA 20% of 60)
subtract percentage from self (60-12 = 48 AKA 60 dmg - 20% (armor))
subtract result from health (150 - 48 = 102)

Health - (Damage - Damage * Armor/100)

150 - (60 - 60 * 20/100) = 102
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Sat Jan 14, 2017 8:15 pm

Ninja'd, but anyway:

To get 20% of something, you multiply it by 0.2 (that is 20/100).

So assuming I understand, if damage is 60, but you want to reduce it by 20%, 60 * 0.2 = 12, so 60 - 12 = 48 (adjusted damage). What was being pointed out above, is that you can do it simpler by multiplying by 100%-20% = 80%. So 60 * 0.8 = 48.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Sat Jan 14, 2017 8:35 pm

blackhornet wrote:Ninja'd, but anyway:

To get 20% of something, you multiply it by 0.2 (that is 20/100).

So assuming I understand, if damage is 60, but you want to reduce it by 20%, 60 * 0.2 = 12, so 60 - 12 = 48 (adjusted damage). What was being pointed out above, is that you can do it simpler by multiplying by 100%-20% = 80%. So 60 * 0.8 = 48.


Hey i dont understand what he is trying to say honestly, maybe u can help? ^_^
I know the counting but i cant use the above to get the code.
Health = 150
Damage = 60
Armor = 20

So the code is, when hit, *Substract from Health* = ?? what? How to do it using variables of the above?
Becuase if armor was 0.2 instead of 20, then using = Damage * Armor - Damage will become a negative number.
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sat Jan 14, 2017 8:37 pm

spacedoubt wrote:Divide by 100 to get percent. (20/100 = 0.2 AKA 20%)
multiply result to get percentage (0.2 * 60 = 12 AKA 20% of 60)
subtract percentage from self (60-12 = 48 AKA 60 dmg - 20% (armor))
subtract result from health (150 - 48 = 102)

Health - (Damage - Damage * Armor/100)

150 - (60 - 60 * 20/100) = 102


Yeah that does not work because we cant willy nilly pick any number, the armors are fixed Variables. Try to do it with these variables instead -

Health = 150
Damage = 60
Armor = 20

Now go. When hit, *Substract from Health* = ???
Your part above, go show me :) - The armor on each target vill vary and not be the same, so we cant use random numbers in the code, must be Damage and Armor and Health.
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sat Jan 14, 2017 8:47 pm

spacedoubt wrote:Health - (Damage - Damage * Armor/100)


Greaver wrote:must be Damage and Armor and Health.
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests