Sacco Posted November 3, 2023 Share Posted November 3, 2023 as you can see here i am trying to add some sort of mightiness loss on hit for Wolfgang. The problem is, as i made the code every time i get damaged from cold and heat i lose like 100 mightiness in 1 second or so. Is there something to fix this problem? I know i can just remove the -4 and almost negate all of the downside from getting damaged by heat,cold or hunger, but i want to keep the -4. I have almost 0 knowledge in coding stuff, so every type of help is appreciated! Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 3, 2023 Share Posted November 3, 2023 This looks like a math problem more than a code problem. You're dividing the amount by 5, then substracting it by 4. So, what ends up happening is that the smaller the damage amount is, the higher the mightiness loss is going to be proportionally. Freezing damage happens every frame (from what I can tell), so the actual damage amount is pretty miniscule for a single instance, but the -4 makes it incredibly noticeable. Let's have 2 extreme examples: The amount is -0.1, it gets divided by 5, so it's -0.02, then substracted by 4, so now it's -4.02 The amount is -100, it gets divided by 5, so it's -20, then substracted by 4, it's -24 4.02 is ~40 times as much as 0.1, but 100 is only ~4 times as much as 24. The simplest solution would be to avoid addition and subtraction, either multiply or divide the amount so it's proportional. If let's say you want 2 Mightiness lost for every point of Health lost, then multiply by 2. Vice versa (1 Mightiness for every 2 Health) divide by 2 and so on. If the simple solution isn't satisfactory, what were you trying to accomplish? I might be able to help with the math there. 1 Link to comment Share on other sites More sharing options...
Sacco Posted November 4, 2023 Author Share Posted November 4, 2023 9 hours ago, ariadnesGambit said: This looks like a math problem more than a code problem. You're dividing the amount by 5, then substracting it by 4. So, what ends up happening is that the smaller the damage amount is, the higher the mightiness loss is going to be proportionally. Freezing damage happens every frame (from what I can tell), so the actual damage amount is pretty miniscule for a single instance, but the -4 makes it incredibly noticeable. Let's have 2 extreme examples: The amount is -0.1, it gets divided by 5, so it's -0.02, then substracted by 4, so now it's -4.02 The amount is -100, it gets divided by 5, so it's -20, then substracted by 4, it's -24 4.02 is ~40 times as much as 0.1, but 100 is only ~4 times as much as 24. The simplest solution would be to avoid addition and subtraction, either multiply or divide the amount so it's proportional. If let's say you want 2 Mightiness lost for every point of Health lost, then multiply by 2. Vice versa (1 Mightiness for every 2 Health) divide by 2 and so on. If the simple solution isn't satisfactory, what were you trying to accomplish? I might be able to help with the math there 'Id like to keep the subtraction. I did it this way because i don't know how to set the mightiness loss like it was in the beta, just by getting attacked and lose mightiness based on the enemy's default damage. If you know how to set it can you tell me how to do this? thanks! Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 4, 2023 Share Posted November 4, 2023 (edited) 40 minutes ago, Sacco said: I did it this way because i don't know how to set the mightiness loss like it was in the beta, just by getting attacked and lose mightiness based on the enemy's default damage. If you want to only lose Mightiness from getting hit in combat, then you could listen to the "attacked" event. Something like this might work, haven't tested it though: local function OnAttacked(inst, data) if data.attacker ~= nil and data.attacker.components.combat ~= nil then local damage = data.attacker.components.combat.defaultdamage if damage ~= nil and damage > 0 then inst.components.mightiness:DoDelta(-damage) -- Add some math here end end end And replace the event too: inst:ListenForEvent("attacked", OnAttacked) Edited November 4, 2023 by ariadnesGambit 1 Link to comment Share on other sites More sharing options...
Sacco Posted November 4, 2023 Author Share Posted November 4, 2023 2 hours ago, ariadnesGambit said: If you want to only lose Mightiness from getting hit in combat, then you could listen to the "attacked" event. Something like this might work, haven't tested it though: local function OnAttacked(inst, data) if data.attacker ~= nil and data.attacker.components.combat ~= nil then local damage = data.attacker.components.combat.defaultdamage if damage ~= nil and damage > 0 then inst.components.mightiness:DoDelta(-damage) -- Add some math here end end end And replace the event too: inst:ListenForEvent("attacked", OnAttacked) oh wow, it actually worked! thanks a lot! 1 Link to comment Share on other sites More sharing options...
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