I am trying to make a vespene refinery that harvests at a rate that is proportional to a percent of its current health. So if the refinery is at full health (100%) then it will extract every 2.1 seconds like it does normally, But if it is at 50% health then it should harvest lets say every 4.2 seconds.
Does anyone have any insight on how to do this? I have tried looking at the individual fields but it looks like they only accept a concrete numerical value.
It is possible, but my first idea of a solution may have side effects. What you could do is have a behavior applied to it that changes the refinery timescale and slow it down by whatever percentage. The problem is that I do not know if this affects repair times, or other times.
You could treat each refinery as a separate instance which you update every game frame (16 times a game second) and decrement a counter to know when to give resources. Other approach is to make each refinery give you in come every second or two but scale the income based on the health and use a fixed (real) accumulator for fractional parts.
I tried making a trigger that updates on unit heatlh but I used the action for changing duration rather than the period. I can't seem to find the action to alter the period of a behavior, just duration. Otherwise i guess i could detect whenever the behavior is applied then change the remaining duration to a value related to the % health and have the behavior apply it self when it ends.
how about a buff that fires every 0.0625 seconds with a dummy effect. you'll register a dummy effect as event in triggers counting up a custom value on the raffinery. now some math, if it gives income every 2.1 seconds, your custom value need to reach 33 ticks to give income. if the raffinery is damaged you just increase the amount of ticks needed. this also solves an issue where your building is damaged during the process. you could also do that in triggers only but please dont do:
Yep, it seems a non-periodic behavior that applies it self when it ends (and sets its duration) could work. But you still need triggers to change the duration, don't you? I couldn't think of a data-only approach so I thought a trigger-only approach was preferable.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hello,
I am trying to make a vespene refinery that harvests at a rate that is proportional to a percent of its current health. So if the refinery is at full health (100%) then it will extract every 2.1 seconds like it does normally, But if it is at 50% health then it should harvest lets say every 4.2 seconds.
Does anyone have any insight on how to do this? I have tried looking at the individual fields but it looks like they only accept a concrete numerical value.
It is possible, but my first idea of a solution may have side effects. What you could do is have a behavior applied to it that changes the refinery timescale and slow it down by whatever percentage. The problem is that I do not know if this affects repair times, or other times.
@ArcaneDurandel: Go
Could you provide a little more specific information please, like how do i relate the timescale to the percentage of unit health?
You could treat each refinery as a separate instance which you update every game frame (16 times a game second) and decrement a counter to know when to give resources. Other approach is to make each refinery give you in come every second or two but scale the income based on the health and use a fixed (real) accumulator for fractional parts.
I can see how you could do with a function. Here is an example in pseudo code that you would call only once, when the unit is created:
This way, the time you wait between two harvests is updated at every harvest. I don't think you need to update faster than that.
Depending on when you create the refinery, you will wrap the function in different ways. One way is with a trigger like:
Of course, you can collapse 4 lines in one:
Its just harder to read.
@Usernameisntworkingright: Go
I tried making a trigger that updates on unit heatlh but I used the action for changing duration rather than the period. I can't seem to find the action to alter the period of a behavior, just duration. Otherwise i guess i could detect whenever the behavior is applied then change the remaining duration to a value related to the % health and have the behavior apply it self when it ends.
how about a buff that fires every 0.0625 seconds with a dummy effect. you'll register a dummy effect as event in triggers counting up a custom value on the raffinery. now some math, if it gives income every 2.1 seconds, your custom value need to reach 33 ticks to give income. if the raffinery is damaged you just increase the amount of ticks needed. this also solves an issue where your building is damaged during the process. you could also do that in triggers only but please dont do:
rather use a
i consider reapeat forever as a no go in programming, there is something wrong in the design of your programm if you need it.
@FunkyUserName: Go
Agreed: "while(unit is alive)" is better code design. The rest of the function works.
@Usernameisntworkingright: Go
Yep, it seems a non-periodic behavior that applies it self when it ends (and sets its duration) could work. But you still need triggers to change the duration, don't you? I couldn't think of a data-only approach so I thought a trigger-only approach was preferable.