Poison: html5 timer on several objects.

Hello.
I’d like to add a poison effect on each object (enemies) who are in collision with another (traps).
I already did searches on the forum with no luck. :neutral_face:
Can semeone suggest some way to do that please ?

Details:
Both enemies and traps, are spawned objects.
The game is native and html5.
I can add more details if necessary.

What i want:
I already have a trap who do instant damage,
ideally, i’d change it’s event " - 10 HP " to " wait 1 sec → - 3 HP → wait 1 sec → - 3 HP → wait 1 sec → - 3 HP "
but i can’t find a “wait” fonction in html5. :cry:

I just can’t find a good solution.

What I could do:
At worst, I could add a variable “poisoned_for” and “poison_damage” to each enemies and do:

(constantly reduce “poisoned_for”)
always do" - 1*TimeDelta()" to variable " poisoned_for "
(If collision AND not already under poison → start poison)
enemies collide with trap AND “poisoned_for” < 10 → add 3 to “poisoned_for”
(reduce HP after 1,2 and 3 seconds poisoned)
if “poisoned_for” < 2, do once remove “poison_damage” to HP
if “poisoned_for” < 1, do once remove “poison_damage” to HP
if “poisoned_for” < 0, do once remove “poison_damage” to HP

But that means for each poison that can be added on the first one (example: 2 different poison),
I have to add even more variables.

Thank for your time. :slight_smile:

You could try to create a custom chronometer with timedelta() function for each object. There are a lot of post about this, it works exactly like chronometers, but with better performance. I’m not sure it exist in html5, but i suppose yes.

Thanks,

Sadly, as I stated under “What I could do:” That would mean, I must add another timer, for each different poisons.
I’m afraid for the performances with several dozens of enemies poisoned by a dozen of traps by 2 or 3 different poison.
That’s why i hoped for a substitue of a “wait” command. things would be much simpler.

I’d like the poisons to be additive. Optionally, have some additive and some other overwriting each other.

Howewer, i just tought, something could probably work with Random named variable…
I’m gonna explore the matter, but i still need help. I’ll post if I find something working.

I use the method i described for a burning effect… on dozen and dozen of objects, taking X damage every X milliseconds. As i noticed a small performance drop, the incrementation of the timer works only when object are the screen +500px (this act like a “pause”, and i also use few variable to pause eefect when needed). This is the first options i tried. The max performance i can handle this way (native platform) is about 250 objects on screen (heavy sprites, lot of image + 2/3 particule emitter per object). I guess it’s not possible on HTML platform nowaday(if the aim is android/ios publication).

The second option is simpliest, but not the best for game interactivity : use one timer (vanilla chronometer from Gdevelop) per poison for exemple, then use a variable on each object like a “step” : poinson1 => 0.25s ; poison2 0.10s etc.
In this second case, according poison1 to make 2 damage and poison2 4 damage, then with few condition, when objects are poisoned, they will lost 2HP each 0.25s with poison1 and 4HP every 0.10s with poison2.
The second option might have really little impact on performance, it just can become a problem in case you want visual effect on damage, because all related object will trigger the effect/damage at the same time.

There are other solutions, but far more complex and long to do (and explain !), i hope this will help you.

(Skip the firsts 2 parts for a summary and misc.)

So first, about my random named variable, it seems simply impossible! :unamused:

For your first method, It seems like you only have one source of burning,
I want different poisons to deal damage independently (or additively).
And all my objects are on the screen… but that may change,
howewer the enemies must be able to die even far away from the screen.

The second option still limit me to 1 poison active per poison type,

Also, another “minor” problem, while visual effect on damage isn’t a necessity (passive visual while poisoned), i’m still woried about the timer.
my timer should be 1 second. To have equivalent damage to your poison 1 exemple, that would mean 8 damage.

Exemple: i have 2 enemies with 7 hp.
the 1st one walk over trap at time T +0s,
the poison timer take a step at T +0.1s and enemie 1 die,
the 2nd enemie walk over another trap at T +0.2s,
the poison timer take a step at T+1.1s and enemie 2 die.

While it’s not a big deal, it means that the gameplay is slightly affected by random.
Up to now, I tried my best to avoid such stuff.

Correct me if i’m wrong, but neither suggestion seems viable for what i have in mind. :neutral_face:
I will probably use suggestion 2, because i might aswell go with the simpler way.

I was thinking about stacks of poisons.
each enemies would have a variable per 0.5 sec up to 6 sec.
each 0.5 sec, a timer move whatever damage is in the variable in the lower one (10 damage in 1 sec go to 0.5 sec),
and when the damage go to 0 sec, the damage applies.
When an enemie walk over a trap, he get 8 damage in both 0.5 sec, 1 sec, and 1.5 sec.
more damage can accumulate.
The problem is, 12 variables are needed per enemies for a poison of 6 seconds. I fear for performance.

I still welcome any idea.

by the way, do you think i should “up” this topic :question: Timed events in HTML5
I’d really want to finish this trap but… I could drop the poison type traps for the moment and come back later.

Hum, i’ve quickly reat your post (i’ll spent more time on it after and edit this post), but basically there are no limitation in different and cumulative poison source. I use variable object, each object have as many variable you want.

Another idea might be to just increment a “damage per second” variable on each object affected by poison, with only one chronometer. the difficulty will remain on trigger/stop poison if poison is supposed to have limited in time effect. in this case you have a variable on “Object” called for example “dps”, and each second with only one chromometer you remove Object.Variable(dps) to Object.Variable(Hp). the best might be an example.

Check the example, it’s the last i described.

EDIT : in this case it’s really basic, but at last in “what you have in mind”, you’ll need a poison duration timer… You’ll need at last another variable for poison duration, or even more as you expected. But it’s possible with only one chronometer, but if you have 8 type of poison, it means 8 variables to handle duration and 8 variables for “dps” by poison type.

Lot of variables should not be a problem with “run once” condition, but lot of chronometers will affect performance for sure.
example.zip (11.7 KB)

<<[ …]if you have 8 type of poison, it means 8 variables to handle duration and 8 variables for “dps” by poison type. >>
That’s about what i feared.

In my game, at worst but unusual, I can have up to 25 traps divided in 4 poison type and a hundred of enemies affected by poisons at once.
(highest trap is 8 sec poison for 12 damage)
If i’m not wrong: mixing 25 traps in 4 type of poison with 50 enemies → a potential of 4 (1 per traps) different timers_variable for 400 (poisons * enemies) dps_variable at once.
I may have confused myself in this calcul.

Yeah… I should probably wait for the “wait event” to be implemented to do: repeat 3 time → wait 3sec then damage.
Seems easier.
I’ll wait till tommorow just in case new opinions come, then i’ll Up the post I linked too earlier.

You spoked of other solutions, if you have some more spare time, i’d really like to know more about them.

By the way, thanks a lot Kink. :slight_smile:

You’re welcome :slight_smile:

I encourage you test at least (first because we can’t be sure of when the pause event will available), i can’t promise miracle on HTml5 (especially if you export to ios/android), but in native platform, i’m sure Gdevelop can handle that amount of variable easily. The point is to optimize : use “run once” condition whenever you can, limit loop or call to unexisting object/variable.

To be precise on what i’ve made on Gdevelop on native platform : 200 sprites object with 20+ variables each, and each a proper timer (made with timedelta()) + lot of particule effect (each object have 2 to 10 particule emitter) with variable related to parent object timer) + physics/platform/ligh extension with variable… still 60 fps, no drop since i tracked every “bad” coding, using debugger and performance monitor. The basics system and art took me about 5h, maybe less, optimizing took me about 12-15h. Now, no matter if i only display maximum 5 objects on scene, i know i can go crazy on final stage with 200 mobs :smiley: