# [Trigger]Spell trigger problem

#### 1337D00D

Level 4
This spell is meant to switch location and hp percent with another unit. It also has a casting time. However, nothing is really working. The opposite unit gets my current life, but nothing happens to mine. Positions don't even switch, and I think its because Target Unit of ability being cast didnt keep its value. I tried assigning them to a variable but then absolutely nothing happened.

Code:
``````SoulSwap
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Soul Swap
Actions
Set anyPos2 = (Position of (Target unit of ability being cast))
Set anyPos = (Position of (Triggering unit))
Set anyInt2 = (Integer((Percentage life of (Target unit of ability being cast))))
Set anyInt = (Integer((Percentage life of (Triggering unit))))
Unit - Set life of (Triggering unit) to (Real(anyInt2))%
Unit - Set life of (Target unit of ability being cast) to (Real(anyInt))%
Unit - Move (Target unit of ability being cast) instantly to anyPos
Unit - Move (Triggering unit) instantly to anyPos2``````

yes i know it leaks, but i will fix those later

#### daggoth

Level 2
If you experience problems with the positions swap you can use dummies. So your trigger suould look that way. And Why you are usig life percentage? This is different for hero that has 1200 hp and a one with 750. Anyway:

Events:
-A unit starts the effect of an ability
Conditions:
-[ability being cast] = blaa blaa you know
Events:
-Set SufferingUnitPosition
-Set CastingUnitPosition
-Set SufferingUnit=you know
-Set CastingUnit=you know
-Set LifeOfSufferingUnit
-Set LifeOfCastingUnit
-Create 1 dummy caster(SU) at the Suffering unit position bla bla
-Create 1 dummy caster(CU) at the Casting Unit position bla bla
-Set life of SufferingUnit to life of CastingUnit
-Set life of CastingUnit to life of SufferingUnit
-Move instantly SufferingUnit to Position of dummy caster(CU)
-Move instantly CastingUnit to position fo dummy caster(SU)
-Remove dummy caster(SU)
-Remove dummy caster(CU)

From my experience of position swithing spells I have found that you almost allways must use a dummie. Most of the spell that are made in your way not allways work (don't know why). Badly but creating stuff a some position causes a leak, but if you know jass you can fix it. I don't so I can't help you anymore.
And I think your problem is the following:
-everything works fine but when one of the units 'ports to the other the rest of the trigger is still active and the second unit tries to 'port to the first but nothing happens because they are near each other anyway. Sounds kinda messy (Sorry).

Last edited:

#### Hemlock

Level 13
Not sure what you did wrong but I always asign my units, and its better to refer your unit to the casting unit instead of the triggering unit, since triggering unit sometimes act akwards.

take a peak at the map I attached here, thats a working version.

#### Attachments

• swap.w3x
16.7 KB · Views: 48

#### DoOs_101

Level 12
Well logically, I learned this from my Computer Science class of making a swap class. Basically you need this method.

Code:
``````int swap = hp[Player number of owner of casting hero];
(The above is to make sure you do not overide the other hp value)
hp[Player number of owner of casting hero] = hp[Player number of owner of unit of ability being cast];
hp[Player number of owner of unit of ability being cast] = swap;
end function``````

Your mistake is you overide the value of the other hp, since before you've set that hp to the casting unit's hp therefore the next time you reverse the assignment you get the other hp the same as the other one...

Code:
``````SoulSwap
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Soul Swap
Actions
Set anyPos2 = (Position of (Target unit of ability being cast))
Set anyPos = (Position of (Triggering unit))
Set anyInt2 = curent life of (Target unit of ability being cast)
Set anyInt = curent life of (Triggering unit)
Unit - Set life of (Triggering unit) to anyInt2
Unit - Set life of (Target unit of ability being cast) to anyInt
Unit - Move (Target unit of ability being cast) instantly to anyPos
Unit - Move (Triggering unit) instantly to anyPos2``````

Last edited:

Level 11
Few ideas:
-Store the units into variables
-Store the % lifes into REAL variables, and forget that conversion thing
-Set the units' pathing to false for a moment and then swap them

But anyway, i don't think TargetUnitOfA.B.C. loses the value at any situation, so doesn't Triggering Unit... And also your trigger isn't that complicated to cause any value-loss...

#### 1337D00D

Level 4
Problem solved.

BTW Warnico, your version uses "Begins casting an ability". You should rather use "Starts the effect of an ability", because a player can cancel casting the spell and not lose any mana, but will proc the trigger.

And Why you are usig life percentage?
If you have 500/1000 hp, you have 50%. Then, you switch with a hero with 200/200 hp, which is 100%. The target would then have 100/200 and you would have 1000/1000. It's sorta to keep it "fair".

Last edited:

Level 11
Problem solved.
At least tell us what the problem was!! I'm interested...

Replies
2
Views
167
Replies
15
Views
810
Replies
4
Views
888
Replies
4
Views
701
Replies
6
Views
515