• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

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,255
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