• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Selling towers for 80% Gold Cost

Status
Not open for further replies.
Level 7
Joined
Aug 5, 2010
Messages
147
I have this trigger which sells a tower and gives 100% gold, and it works perfectly.

  • Events
    • Unit - A unit Finishes casting an ability
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • And - All (Conditions) are true
          • Conditions
            • (Ability being cast) Equal to Sell Tower [Normal Tower]
            • (Level of Sell Tower [Normal Tower] for (Casting unit)) Equal to 1
      • Then - Actions
        • Player - Add (Point-value of (Triggering unit)) to (Owner of (Casting unit)) Current gold
        • Unit - Remove (Casting unit) from the game
        • Special Effect - Create a special effect at (Position of (Casting unit)) using Abilities\Spells\Other\Transmute\PileofGold.mdl
      • Else - Actions
Then i have this which is meant to return 80% Gold, but it doesnt work.
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • And - All (Conditions) are true
        • Conditions
          • (Ability being cast) Equal to Sell Tower [Normal Tower]
          • (Level of Sell Tower [Normal Tower] for (Casting unit)) Equal to 2
    • Then - Actions
      • Player - Add ((80 / 100) x (Point-value of (Casting unit))) to (Owner of (Casting unit)) Current gold
      • Unit - Remove (Casting unit) from the game
      • Special Effect - Create a special effect at (Position of (Casting unit)) using Abilities\Spells\Other\Transmute\PileofGold.mdl
    • Else - Actions
The part that isn't working is this
  • Player - Add ((80 / 100) x (Point-value of (Casting unit))) to (Owner of (Casting unit)) Current gold
So my question is how do i make it so selling a tower will return 80%/60%/40%/20% of the point-value of the casting unit.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,232
The part that isn't working is this
That is because you multiply by 0? 80 / 100 = 0 in integer mathematics as it cannot represent fractional components.

Change the order of the operations and it will work fine.
((80 x (Point-value of (Casting unit))) / 100)
What this does is multiply the point value by 80 first so it is a big number (>>100) and then divide by 100 to get your fractional result. Tips like this are used often to avoid the use of floating point numbers (which can represent fractions) as floating points are considerably slower than integer operations.
 
Level 7
Joined
Aug 5, 2010
Messages
147
That is because you multiply by 0? 80 / 100 = 0 in integer mathematics as it cannot represent fractional components.

Change the order of the operations and it will work fine.
((80 x (Point-value of (Casting unit))) / 100)
What this does is multiply the point value by 80 first so it is a big number (>>100) and then divide by 100 to get your fractional result. Tips like this are used often to avoid the use of floating point numbers (which can represent fractions) as floating points are considerably slower than integer operations.

Thanks, i tried doing different ordering but i just cant math properly it would seem.
 
Status
Not open for further replies.
Top