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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      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