Another maths question :(

Grags_1977

Ultra Cool Member
Reaction score
32
I want to take away 20% gold of my hero when he dies.

Set player1 gold to player1 gold - 20%

How do I do this please?

:eek::eek::eek::eek::eek::eek::eek::eek::eek:
 

merlinds

Member
Reaction score
15
Set gold of the player = Gold of the player - (Gold of the player * 0.2)
or
Set Gold of the player = (Gold of the player * 0.8)
:D
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
would you want to do a straight 20%?
or you open to maybe a more dynamic ammount, a set ammount, increasing with every level, with a random integer tacked on the end to make it appear to be a random number, along with a game text that says that you lost X gold
 

Grags_1977

Ultra Cool Member
Reaction score
32
Well this is the whole trigger. (Including the new 20% gold loss) i'm open to suggestions.

Trigger:
  • Revive Hero
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
    • Conditions
      • (Triggering unit) Equal to Unit_Hero
    • Actions
      • Sound - Stop Sound_Music After fading
      • Sound - Play Sound_Death <gen>
      • Set Real_TimeOfDay = (In-game time of day)
      • Game - Set the time of day to 0.00
      • Set TempPoint[14] = (Position of Unit_Hero)
      • Set TempUnitGroup[10] = (Units within 2000.00 of TempPoint[14])
      • Custom script: call RemoveLocation( udg_TempPoint[14] )
      • Unit Group - Pick every unit in TempUnitGroup[10] and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to 100.00%
      • Custom script: call DestroyGroup ( udg_TempUnitGroup[10] )
      • Wait 2.00 seconds
      • Game - Display to (All players) the text: |cffff0000You have ...
      • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) - ((Player 1 (Red) Current gold) x (Integer(0.20))))
      • Wait 8.00 seconds
      • Sound - Stop Sound_Death <gen> After fading
      • Trigger - Run Force Push <gen> (ignoring conditions)
      • Camera - Pan camera for Player 1 (Red) to TempPoint[14] over 0.00 seconds
      • Hero - Instantly revive (Triggering unit) at TempPoint[14], Show revival graphics
      • Custom script: call RemoveLocation( udg_TempPoint[14] )
      • Selection - Select Unit_Hero for Player 1 (Red)
      • Special Effect - Create a special effect attached to the overhead of Unit_Hero using UI\Feedback\GoldCredit\GoldCredit.mdl
      • Special Effect - Destroy (Last created special effect)
      • Sound - Play Sound_Music
      • Game - Set the time of day to Real_TimeOfDay


|cffff0000You have died and lost 20% of your gold!

You will be revived in 8 more seconds.

^ thats the death message (Red)

I was contimplating making death permanent forcing the user to save & load. But decided against it. But I don't want death to be just a tiny inconvenience either. I would LOVE to make the user lose all thier experience towards thier next level. But wouldn't have the slightest idea where to begin. As setting the hero's xp to zero really does set it to zero (Includes ALL levels they have)
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
this is my suggestion, its gonna be jass since im practicing, but thats nice cuz all you do is copy and past then:
JASS:
function GoldLoss takes integer a, integer b, integer c returns integer
  return ( ( a + b ) / 2 ) + c - 20
endfunction


Trigger:
  • Actions
    • Set Int[1] = gold of the player x 0.8
    • Set Int[2] = (SqrRoot of level of the hero) x (whatever you want, this would be x10 at lvl 100 etc)
    • Set Int[3] = Random number between 1 and 40
    • Custom Script: set udg_Gold_Loss = GoldLoss( udg_Int[1], udg_Int[2], udg_Int[3])


this would set the gold loss equal to the average between the square root of the heroes level x an integer and 20% of the total gold + (random number between -20 and 20)
 

merlinds

Member
Reaction score
15
Trigger:
  • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) - ((Player 1 (Red) Current gold) x (Integer(0.20))))

mmm, if you convert 0.2 to integer does it becomes 0??
i think you must convert the current gold to real first, then multply and the turn it into integer.
 

Grags_1977

Ultra Cool Member
Reaction score
32
:confused:

I think i'll stick with the way Merlins done it :thup:



EDIT: Thanks Merlin, I'm glad you caught that before I ran another full test.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
it would be like this:
gold integer -> gold real -> x0.8 -> new gold integer

or

gold - (gold/5)

ya that would probably be best, i more just wanted to practice my jass :p
 

Ayanami

칼리
Reaction score
288
Trigger:
  • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) - ((Player 1 (Red) Current gold) x (Integer(0.20))))

mmm, if you convert 0.2 to integer does it becomes 0??
i think you must convert the current gold to real first, then multply and the turn it into integer.

That will not work. When you convert 0.20 to an integer, it becomes 0. So essentially, you're not subtracting any gold. You'd have to convert the current gold to real, then work from there. Example:

Trigger:
  • Actions
    • Set TempInt = (Integer(((Real((Player 1 (Red) Current gold))) x 0.20)))
    • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) - TempInt)


Or, to do it in 1 line:

Trigger:
  • Actions
    • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) - (Integer(((Real((Player 1 (Red) Current gold))) x 0.20))))


Lots of conversion :)
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
thats gui for u :p, you should only convert the gold to real then back after the math is done, so 2 conversions for the minimal ammount
 

Grags_1977

Ultra Cool Member
Reaction score
32
Urgh, I can't rep anyone... I have to spread it about.

But thanks a lot for the replys.
 

Iwan_Krissov

New Member
Reaction score
18
I was contimplating making death permanent forcing the user to save & load. But decided against it. But I don't want death to be just a tiny inconvenience either. I would LOVE to make the user lose all thier experience towards thier next level. But wouldn't have the slightest idea where to begin. As setting the hero's xp to zero really does set it to zero (Includes ALL levels they have)
This can be done also. At first you need to know which amount of experience is needed for which level. This can be found in the gameplay constants. Afterwards you can make an integer-array that stores the minimum-experience for every level and finally you can than write your trigger, which sets the experience of the hero to an minimumvalue according to the level the hero currently has.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
In the unlikely event that he still needs it, why not use:
Trigger:
  • Player - Set Player 1 (Red) Current gold to (((Player 1 (Red) Current gold) / 5) x 4)

since 4x/5 gives the same as x - 20%.
 
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