Unit randomly dies when casting a spell

REOspeedwagon

New Member
Reaction score
0
So I am creating a game called "Demonic Defense", and if you've been on battle.net lately; you've probably seen it hosted. I am having one problem with one of the defenders. Whenever the Shadow Beetle (a unit in Demonic defense) casts one of his abilities (A transform ability made via triggers, based off of channel) he randomly dies.

The unit has 2 spells; one to transform him into a unit, and one to transform him back to his original form. Below is the trigger for which transforms him back into his regular form.
Code:
Rise of Ragthark Inverse
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Rise of Ragthark From Ragthark
    Actions
        Set tempPoint = (Position of (Triggering unit))
        Special Effect - Create a special effect at tempPoint using Abilities\Spells\Other\Volcano\VolcanoDeath.mdl
        Special Effect - Destroy (Last created special effect)
        Set tempint = (Integer((Percentage life of (Triggering unit))))
        Set tempInt2 = (Integer((Mana of (Triggering unit))))
        Unit - Remove (Triggering unit) from the game
        Unit - Create 1 Shadow Beetle for (Owner of (Triggering unit)) at tempPoint facing (Facing of (Triggering unit)) degrees
        Unit - Set mana of (Last created unit) to ((Real(tempInt2)) - 15.00)
        Unit - Set life of (Last created unit) to (Real(tempint))%
        Custom script:   call RemoveLocation( udg_tempPoint )
Some reason, (I think after upgrading something that both the "Ragthark" and "Shadow Beetle" uses, it does this) after using this ability to revert him into his normal form; he randomly dies. Also I have tried the Action "Replace Unit", but ended up changing the trigger to this, as I thought it was that causing the death. Note: Both the abilities in which transforms into Ragthark, and from are based off of channel, but have different base order IDs.
 

vypur85

Hibernate
Reaction score
803
So far I can't see any problem with the trigger which you posted that could cause random death.

> ...after upgrading something
Does the upgrade involves max life gain? If it does, then that could be the problem.

There are too many possibilities for this to occur.
You may need to troubleshoot yourself.
It could be other triggers that mess up with your current trigger.

Remember that once you remove a unit, all the reference to that particular unit is gone forever. So if you have another trigger which uses a saved variable of this unit, then shit happens.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
There are a few things wrong with this trigger:
Code:
Set tempint = (Integer((Percentage life of (Triggering unit))))
Why do you use Integers here if the data is a Real? This *could* potentially kill the unit if it had 0.999 hitpoints when casting the ability.

Code:
Unit - Remove (Triggering unit) from the game
You should not remove the unit until the end of the trigger. If you remove the unit the reference will be lost, especially "(Owner of (Triggering Unit))" and "(Facing of (Triggering unit))" will be hard to get when the unit in question does not exist anymore.

And last but not least, why do you trigger it in the first place? Why not use Metamorphosis or something like that? This seems highly redundant.
 

vypur85

Hibernate
Reaction score
803
> *could*
Highly unlikely...

> You should not remove...
Surprisingly it works. I tested it myself. Could have sworn it didn't worked the last time I dealt with this.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
> *could*
Highly unlikely...
Its not unlikely at all.
When converting the real to an integer all values after the decimal point are gone.
A unit with 0.9999 hitpoints will have 1 hitpoint displayed when selected. But when using this skill the unit will be dead. This is a bug. And there is absolutely NO reason why an integer should be used here instead of a real.


> You should not remove...
Surprisingly it works. I tested it myself. Could have sworn it didn't worked the last time I dealt with this.
I am absolutely sure this was the case last time I tried too. Its just not a good idea to do it.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
What? This is not a question about probability. This is a question about right or wrong in terms of mathematical accuracy.
How could you possibly say, that this is not a bug?
 

Solu9

You can change this now in User CP.
Reaction score
216
I must agree with Accname.
When storing a real it should be stored in a real variable. Everything else will just cause problems.

About removing the unit.
While it might work I would rather replace it myself.

Another way could be. Hiding the unit, move it to an unreachable location and give it to a non used player for the time being.
The same for the seconds form. Just switch the two units when either of the abilities are used.

However, overall Metamorphosis or Bearform seems to be a better option in my opinion.
 

REOspeedwagon

New Member
Reaction score
0
I apologize, I forgot to mention the bear form based spell also killed the unit. I can fix the real variable, and will.

So far I can't see any problem with the trigger which you posted that could cause random death.

> ...after upgrading something
Does the upgrade involves max life gain? If it does, then that could be the problem.

There are too many possibilities for this to occur.
You may need to troubleshoot yourself.
It could be other triggers that mess up with your current trigger.

Remember that once you remove a unit, all the reference to that particular unit is gone forever. So if you have another trigger which uses a saved variable of this unit, then shit happens.


Also, the unit does have a health upgrade; multiple ones to be exact, only differing in the 100-200 range.

EDIT: After much testing, I can see now it is most likely the health upgrades, is there a fix to this?
 

vypur85

Hibernate
Reaction score
803
> Hiding the unit, move it to an unreachable
Usually I'd kill it and hide it. No one will notice anyway. It's better than removing.

> ...could you possibly say...
Fuck off, bitch... Lol.

> is there a fix..
I'm not sure myself. I'm not too experienced in upgrades. Then again, it also depends on how you create the upgrade ability.

Max life and mana abilities (not sure about upgrades) are bugged. If you set these abilities into several levels and add them to units and level them up, their max life/mana values get messed up. For positive values of life/mana increment, when you add and level and then remove (in this case, when you morph the unit, it's considered 'removed'), the life/mana becomes negative instead.

Here's an example:
You unit max life is 500hp.
You add Max life ability to your unit and set it to level 2 which gives extra 750 hp.
You remove the ability (or demorph the unit).
Your unit now has -250 max life.
Since it's a negative value, it just dies.

An easy way to confirm this is to create a game text periodically and show the max life of your bugged unit.

If this is the case, then how to fix?

Use alternatives.

What?

Up to you.
 

REOspeedwagon

New Member
Reaction score
0
I fixed the issue by creating a unit at map ini for those of whom which select this shadow beetle. Ragthark stays hidden for the entire game, until the transformation is done, and it switches the two out. Thanks for the help.
 

afisakov

You can change this now in User CP.
Reaction score
37
When converting the real to an integer all values after the decimal point are gone.
A unit with 0.9999 hitpoints will have 1 hitpoint displayed when selected. But when using this skill the unit will be dead. This is a bug. And there is absolutely NO reason why an integer should be used here instead of a real.
FYI, his trigger used percent health, not absolute. Thus th unit did not have to be at one health to truncate to 0, it would be enough to be below 1%. Still rare I agree, but quiet possible with poison or disease cloud- which would drop hp to 1 and keep it there.
e.g. 1000 max hp, with current hp=7 has 0.7% hp. covert to integer=0, convert back into real=0 and unit dead.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top