• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Spirit link but with mana cost (share mana costs) - Get mana cost

Status
Not open for further replies.
Level 21
Joined
Apr 8, 2017
Messages
1,530
As tittle said.
26803635_1556270544465981_2110252826_n.jpg


I want to add this spells to me custom High elf race.

Description:
-Pick X number of unit and distribute their mana costs between them like main spell but with mana.

There isnt problem if spell isnt a spells a chain, if you want u can add this effect with units with X buff.
-Cast spell -> Spell cost is now distributed between affected units.

>>>>>>>>
Spell cost = 100
Affected units = 5
-Result
Waste 20 on each unit
>>>>>>>>
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
This is a really tedious spell. As of right now, there's no way to get the mana cost of an ability, so what you will need to do is map the mana cost of every single spell that can be casted in your project (preferably hashtables, but you can use arrays).

Whenever an ability is casted, check if that unit has the "chain link" debuff. If they do, find out which ability was casted, find it's mana cost with however you stored it, then divide that mana cost by the number of units it's linked with, and subtract accordingly. Another thing you will need to watch out for is to give the caster the mana you subtracted from the other units. If not, the caster will loose all the mana it costed for the spell in addition to the other linked units losing their portion of mana.
 
Level 11
Joined
Jun 2, 2004
Messages
849
For triggering the mana sharing, I'd probably have a periodic trigger normalize their mana every 0.05 seconds or so. Spell costs/etc would be normal. It'd take a bit of math actually do the normalization (especially if you're considering units with different sized mana pools) but shouldn't be too hard. The hard part is maintaining the unit group for which units are linked.
 
Level 13
Joined
Oct 18, 2013
Messages
690
If you use Draco's Memory library, this function will be useful to you:
Code:
function GetAbilityManaCost takes integer abil, integer level returns integer

If you want, I can code this spell for you.
 
Level 11
Joined
Jun 2, 2004
Messages
849
Don't need to even have an event for spell casts. Just normalize it all the time.

Crap method that won't work with different sized mana pools, just an example:

- Add up mana available to all units (not max; their current mana)
- Divide by number of units in unit group
- Set all member's mana to that value

When a unit casts an ability, their mana pool will be depleted as normal. Within a short amount of time, the periodic trigger will tick and the cost will be distributed to the other members.
 
One can use a 0s timer after the "starts effect" event to gain the mana spent on this spell (works in almost any case, except if mana drain magic is involved).
If one mimicis Spiritlink from Blizzard this becomes more easy, cause spirit link just divides the damage by all allied units having a buff provided by a spiritlink ability, therefore no complex group saving is needed.
 
Level 21
Joined
Apr 8, 2017
Messages
1,530
Well i can do it by myself if i get the of get mana cost but i think i have to do like KILLCIDE said.

===========================================
MODERATOR NOTE: Accidently merged two posts by different users.

Dark_Axl said:

This is a really tedious spell. As of right now, there's no way to get the mana cost of an ability, so what you will need to do is map the mana cost of every single spell that can be casted in your project (preferably hashtables, but you can use arrays).

Whenever an ability is casted, check if that unit has the "chain link" debuff. If they do, find out which ability was casted, find it's mana cost with however you stored it, then divide that mana cost by the number of units it's linked with, and subtract accordingly. Another thing you will need to watch out for is to give the caster the mana you subtracted from the other units. If not, the caster will loose all the mana it costed for the spell in addition to the other linked units losing their portion of mana.

as the mana cost is distributed evenly to all affected units,
another method to get mana cost of an ability is using the "begin casting an ability" to record the mana before cast and using "starts the effect of an ability" event to record mana after cast.

so when an unit begin cast an ability, check if the unit has the buff,
if yes, save the mana then check the mana after cast using the "starts the effect of an ability" event,
the difference is the mana cost (note: unless some mana burn or mana manipulating effect happen between event)

if that note concern you, the only method available is like KILLCIDE said above, though be reminded that not only you should store the mana cost of every ability, you need to do that for all levels of ability.

and you need to think about few cases, like:
- what if an affected unit has Immolation turned on? (it will cost mana periodically while not triggering cast event)
 
Last edited by a moderator:
Level 21
Joined
Apr 8, 2017
Messages
1,530
as the mana cost is distributed evenly to all affected units,
another method to get mana cost of an ability is using the "begin casting an ability" to record the mana before cast and using "starts the effect of an ability" event to record mana after cast.

so when an unit begin cast an ability, check if the unit has the buff,
if yes, save the mana then check the mana after cast using the "starts the effect of an ability" event,
the difference is the mana cost (note: unless some mana burn or mana manipulating effect happen between event)

if that note concern you, the only method available is like KILLCIDE said above, though be reminded that not only you should store the mana cost of every ability, you need to do that for all levels of ability.

and you need to think about few cases, like:
- what if an affected unit has Immolation turned on? (it will cost mana periodically while not triggering cast event)
Wow, nice, i will think to use the "start casting/cast" or the "mana-cost-list" system, keep calm the m-c-l will just use like 25 spells.

Thanks all :)
 
Level 13
Joined
May 10, 2009
Messages
868
Take into consideration what Tasyen said. The "Starts the effect..." event fires exactly when an ability goes into its cooldown state, but the mana's not been subtracted yet.
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
  • Actions
    • Game - Display to (All players) the text: (caster's current mana: + (String((Integer((Mana of (Triggering unit)))))))
Untitled-1.png

Still, auto-cast abilities such as searing arrows, cold arrows, black arrow, etc... won't trigger it. Unless a unit casts them manually.
 
Level 21
Joined
Apr 8, 2017
Messages
1,530
Take into consideration what Tasyen said. The "Starts the effect..." event fires exactly when an ability goes into its cooldown state, but the mana's not been subtracted yet.
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
  • Actions
    • Game - Display to (All players) the text: (caster's current mana: + (String((Integer((Mana of (Triggering unit)))))))
View attachment 289718
Still, auto-cast abilities such as searing arrows, cold arrows, black arrow, etc... won't trigger it. Unless a unit casts them manually.
Ty, lets make some triggers.
 
Level 13
Joined
May 10, 2009
Messages
868
Something like this:
  • Initialization
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set spentMana_Table = (Last created hashtable)
  • StartEffect
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Unit Group - Add (Triggering unit) to spentMana_Group
      • Countdown Timer - Start spentMana_Timer as a One-shot timer that will expire in 0.00 seconds
      • -------- you might wanna use a hash table in order to store targets, and/or some other useful values for later. --------
      • Hashtable - Save (Mana of (Triggering unit)) as 0 of (Key (Triggering unit)) in spentMana_Table
  • GetManaSpent
    • Events
      • Time - spentMana_Timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in spentMana_Group and do (Actions)
        • Loop - Actions
          • Set tmp_realManaCost = ((Load 0 of (Key (Picked unit)) from spentMana_Table) - (Mana of (Picked unit)))
          • Game - Display to (All players) the text: (Mana cost: + (String((Integer(tmp_realManaCost)))))
      • Unit Group - Remove all units from spentMana_Group
Then:

Untitled-2.png


EDIT: This does not solve all of your problems, because there are other relevant factors. For example, what would happen if a unit is attacked by another one which has feedback ability, or mana burn, or mana drain?
 
Last edited:
Level 21
Joined
Apr 8, 2017
Messages
1,530
Something like this:
  • Initialization
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set spentMana_Table = (Last created hashtable)
  • StartEffect
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Unit Group - Add (Triggering unit) to spentMana_Group
      • Countdown Timer - Start spentMana_Timer as a One-shot timer that will expire in 0.00 seconds
      • -------- you might wanna use a hash table in order to store targets, and/or some other useful values for later. --------
      • Hashtable - Save (Mana of (Triggering unit)) as 0 of (Key (Triggering unit)) in spentMana_Table
  • GetManaSpent
    • Events
      • Time - spentMana_Timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in spentMana_Group and do (Actions)
        • Loop - Actions
          • Set tmp_realManaCost = ((Load 0 of (Key (Picked unit)) from spentMana_Table) - (Mana of (Picked unit)))
          • Game - Display to (All players) the text: (Mana cost: + (String((Integer(tmp_realManaCost)))))
      • Unit Group - Remove all units from spentMana_Group
Then:

View attachment 289719

EDIT: This does not solve all of your problems, because there are other relevant factors. For example, what would happen if a unit is attacked by another one which has feedback ability, or mana burn, or mana drain?
But, what really do this? ty*
 
Level 9
Joined
Dec 12, 2007
Messages
489
Take into consideration what Tasyen said. The "Starts the effect..." event fires exactly when an ability goes into its cooldown state, but the mana's not been subtracted yet.
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
  • Actions
    • Game - Display to (All players) the text: (caster's current mana: + (String((Integer((Mana of (Triggering unit)))))))
View attachment 289718
Still, auto-cast abilities such as searing arrows, cold arrows, black arrow, etc... won't trigger it. Unless a unit casts them manually.
got to learn something new everyday... thank you for clarifying...
 
In the end, there's no way to make this reliably enough. You should honestly drop the idea, since no matter what you do you are going to get SOME sort of a bug (unless you trigger absolutely all mana regen/regain and index all spells' mana cost for all levels).

Here's an alternate idea:

When units are "mana linked", instead of sharing the used mana, mana is instead BALANCED.

This means that mana flows from units that have more, to units that have less. If a unit has 0 mana and another has 200, 100 mana will flow from it to the 0 mana unit, etc.

This is probably the best way to implement this idea, and it can be done fairly easily.
 
Last edited:
This map contains a ring reducing inital manacosts for spells by 40% when carried.

  • Regain Mana start
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • ((Triggering unit) has an item of type Ring of Archmage LVL 4) Equal to True
    • Actions
      • Set Regain_Mana_Old = (Mana of (Triggering unit))
      • Set Regain_Mana_User = (Triggering unit)
      • Countdown Timer - Start Regain_Mana_Timer as a One-shot timer that will expire in 0.00 seconds
  • Regain Mana do
    • Events
      • Time - Regain_Mana_Timer expires
    • Conditions
    • Actions
      • Set Regain_Mana_Spent = (Regain_Mana_Old - (Mana of Regain_Mana_User))
      • -------- Dont manipulate managain magic --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Regain_Mana_Spent Greater than 0.00
        • Then - Actions
          • Game - Display to (All players) the text: (Spells-Costs: + (String(Regain_Mana_Spent)))
          • Game - Display to (All players) the text: (reduce cost by: + (String((Regain_Mana_Spent x 0.40))))
          • Game - Display to (All players) the text: (total cost: + (String((Regain_Mana_Spent x 0.60))))
          • Game - Display to (All players) the text: -----------------
          • Unit - Set mana of Regain_Mana_User to ((Mana of Regain_Mana_User) + (Regain_Mana_Spent x 0.40))
          • Game - Display to (All players) the text: (Old-Mana: + (String(Regain_Mana_Old)))
          • Game - Display to (All players) the text: (now Mana: + (String((Mana of Regain_Mana_User))))
          • Game - Display to (All players) the text: -----------------
        • Else - Actions
 

Attachments

  • Save Mana.w3x
    17.8 KB · Views: 30
Level 21
Joined
Apr 8, 2017
Messages
1,530
This map contains a ring reducing inital manacosts for spells by 40% when carried.

  • Regain Mana start
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • ((Triggering unit) has an item of type Ring of Archmage LVL 4) Equal to True
    • Actions
      • Set Regain_Mana_Old = (Mana of (Triggering unit))
      • Set Regain_Mana_User = (Triggering unit)
      • Countdown Timer - Start Regain_Mana_Timer as a One-shot timer that will expire in 0.00 seconds
  • Regain Mana do
    • Events
      • Time - Regain_Mana_Timer expires
    • Conditions
    • Actions
      • Set Regain_Mana_Spent = (Regain_Mana_Old - (Mana of Regain_Mana_User))
      • -------- Dont manipulate managain magic --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Regain_Mana_Spent Greater than 0.00
        • Then - Actions
          • Game - Display to (All players) the text: (Spells-Costs: + (String(Regain_Mana_Spent)))
          • Game - Display to (All players) the text: (reduce cost by: + (String((Regain_Mana_Spent x 0.40))))
          • Game - Display to (All players) the text: (total cost: + (String((Regain_Mana_Spent x 0.60))))
          • Game - Display to (All players) the text: -----------------
          • Unit - Set mana of Regain_Mana_User to ((Mana of Regain_Mana_User) + (Regain_Mana_Spent x 0.40))
          • Game - Display to (All players) the text: (Old-Mana: + (String(Regain_Mana_Old)))
          • Game - Display to (All players) the text: (now Mana: + (String((Mana of Regain_Mana_User))))
          • Game - Display to (All players) the text: -----------------
        • Else - Actions
Yes!! it works, Thanks bro! Thread solved.
 
Level 21
Joined
Apr 8, 2017
Messages
1,530
Triggers (Share mana costs)
  • High link ef
    • Events
      • Time - ManaLink_act expires
    • Terms
    • Actions
      • Set ManaLink_cost = (ManaLink_mp - (Mana of ManaLink_caster))
      • If (All Conditions is True) then do (Then Actions) else do (Else Actions)
        • Yes: Conditions
          • ManaLink_cost Greater than 0.00
        • Then: Actions
          • Game - Display to (All players) the text: Cost
          • Game - Display to (All players) the text: (String ((Integer (ManaLink_cost))))
          • Unit - Set mana of ManaLink_caster to ((Mana of ManaLink_caster) + ManaLink_cost)
          • -------- - --------
          • Set ManaLink_users = (Units owned by (Owner of ManaLink_caster))
          • Unit Group - Pick every unit in ManaLink_users and do (Actions)
            • Loop: Actions
              • If (All Conditions is True) then do (Then Actions) else do (Else Actions)
                • Yes: Conditions
                  • ((Picked unit) has buff Slow down) Same as False
                • Then: Actions
                  • Unit group - Remove (Picked unit) from ManaLink_users
                • Others: Actions
          • -------- Eject --------
          • Unit Group - Pick every unit in ManaLink_users and do (Actions)
            • Loop: Actions
              • If (All Conditions is True) then do (Then Actions) else do (Else Actions)
                • Yes: Conditions
                  • ((Picked unit) has buff Slow down) Same as True
                • Then: Actions
                  • Set ManaLink_split = (ManaLink_cost / (Real ((Number of units in ManaLink_users))))
                  • Unit - Set mana of (Picked unit) to ((Man of (Picked unit)) - ManaLink_split)
                • Others: Actions
          • Game - Display to (All players) the text: Splitted
          • Game - Display to (All players) the text: (String ((Integer (ManaLink_split))))
          • -------- - --------
          • Set vSpellhighmanauni = (Position of (Triggering unit))
          • Floating text - Create floating text that reads (((String ((Integer (ManaLink_cost)))) + /) + ((String ((Number of units in ManaLink_users))) + ((+ ((String ((Integer (ManaLink_split )))) +))))) at vSpellhighmanauni with Z offset 50.00, using font size 14.00, color (20.00%, 50.00%, 100.00%), and 30.00% transparency
          • Floating text - Set the velocity of (Last created floating text) to 64.00 to 90.00 degrees
          • Floating text - Change (Last created floating text): Deactivate permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 0.01 seconds
          • Custom script: call RemoveLocation (udg_vSpellhighmanauni)
        • Others: Actions
-
  • High link
    • Events
      • Unit - A unit Initiates the effect of a skill
    • Terms
    • Actions
      • If (All Conditions is True) then do (Then Actions) else do (Else Actions)
        • Yes: Conditions
          • ((Triggering unit) has buff Slow down) Same as True
        • Then: Actions
          • Set ManaLink_mp = (Man of (Triggering unit))
          • Set ManaLink_caster = (Triggering unit)
          • Countdown of the clock - Start ManaLink_act as a A shot timer that will expire in 0.00 seconds
        • Others: Actions
I translate them, i use spanish version.
 
Status
Not open for further replies.
Top