Another maths question :(

Grags_1977

Ultra Cool Member
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
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.
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
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.
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
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
: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.
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

칼리
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.
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
 

Iwan_Krissov

New Member
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.
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.
  • tom_mai78101 tom_mai78101:
    Thanks for the context.
    +1
  • The Helper The Helper:
    Happy Hump Day!!!
  • Blackveiled Blackveiled:
    TH old fart gotta have a beer with me one of these days
  • The Helper The Helper:
    I am down anytime Blackveiled
  • Blackveiled Blackveiled:
    count on it then cause you don't live that far from me hah
  • The Helper The Helper:
    really that is cool!
  • The Helper The Helper:
    Hey Tom I added a new Weird tag to the News Prefixes
  • The Helper The Helper:
    What is up Blackveiled?
  • Blackveiled Blackveiled:
    Chillin', lurkin'. :D
  • The Helper The Helper:
    I am working on a bunch of site projects right now doing a bunch of behind the scenes stuff and trying to clean up some stuff that I let slide when I got lazy with the site for a few years...
  • The Helper The Helper:
    Are you in Houston Blackveiled or just in Texas?
  • Blackveiled Blackveiled:
    Houston
  • Blackveiled Blackveiled:
    I've been living here since 2014.
  • The Helper The Helper:
    OK banlord we need to get together soon! The only other member of the site I know in Houston is XXX Conan
  • The Helper The Helper:
    and he does not want none lol
  • The Helper The Helper:
    he put up a picture of his mom one time and she was HOT!
  • The Helper The Helper:
    I wish we still had that
  • Blackveiled Blackveiled:
    Lmao you scared him off I see.
  • The Helper The Helper:
    he will be back
  • The Helper The Helper:
    Conan was like 12 when he started here
  • The Helper The Helper:
    I literally think I was his male role model
  • Blackveiled Blackveiled:
    Yeah I was 12 when I started here as well.
  • The Helper The Helper:
    you guys were just kids
  • The Helper The Helper:
    I was in my 30s when i got the Blizzard MVP
  • The Helper The Helper:
    I am 53

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top