• 🏆 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!

[General] How to calculate the number of upgrades the hero gets with current gold?

Status
Not open for further replies.
In this trigger what I'm trying to do is to increase the computer players' heroes attributes. Eeach upgrade costs 150 gold. By default every player gets 1000 gold at the beginning of the game. So, I must calculate how much upgrades 1000 gold contains. However, in its current state, when this trigger is ran, the game crashes. If I disable the variables and attribute increase it doesn't crash EVEN IF THERE ARE NO COMPUTER PLAYERS.


  • Upgrade Items of Heroes
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) controller) Equal to Computer
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Level Less than or equal to 6
                • Then - Actions
                  • Hero - Create Item[(Random integer number between 1 and 100)] and give it to Hero[(Integer A)]
                • Else - Actions
              • Set TempGold_Real = (Real(((Player((Integer A))) Current gold)))
              • Set TempGold_Real = (TempGold_Real / 150.00)
              • Set TempGold = (Integer(TempGold_Real))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Unit-type of Hero[(Integer A)]) Equal to Demon Hunter (9)
                      • (Unit-type of Hero[(Integer A)]) Equal to Warden (10)
                      • (Unit-type of Hero[(Integer A)]) Equal to Blademaster (4)
                      • (Unit-type of Hero[(Integer A)]) Equal to Shadow Hunter (6)
                      • (Unit-type of Hero[(Integer A)]) Equal to Dark Ranger (19)
                      • (Unit-type of Hero[(Integer A)]) Equal to Firelord (20)
                      • (Unit-type of Hero[(Integer A)]) Equal to Ranger (13)
                • Then - Actions
                  • Hero - Modify Agility of Hero[(Integer A)]: Add TempGold
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Unit-type of Hero[(Integer A)]) Equal to Paladin (1)
                      • (Unit-type of Hero[(Integer A)]) Equal to Mountain King (2)
                      • (Unit-type of Hero[(Integer A)]) Equal to Tauren Chieftain (5)
                      • (Unit-type of Hero[(Integer A)]) Equal to Dreadlord (11)
                      • (Unit-type of Hero[(Integer A)]) Equal to Crypt Lord (8)
                      • (Unit-type of Hero[(Integer A)]) Equal to Alchemist (15)
                      • (Unit-type of Hero[(Integer A)]) Equal to Tinker (17)
                      • (Unit-type of Hero[(Integer A)]) Equal to Beastmaster (18)
                      • (Unit-type of Hero[(Integer A)]) Equal to Pandaren Brewmaster (21)
                      • (Unit-type of Hero[(Integer A)]) Equal to Pit Lord (22)
                • Then - Actions
                  • Hero - Modify Strength of Hero[(Integer A)]: Add TempGold
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Unit-type of Hero[(Integer A)]) Equal to Blood Mage (3)
                      • (Unit-type of Hero[(Integer A)]) Equal to Lich (7)
                      • (Unit-type of Hero[(Integer A)]) Equal to Warlock (14)
                      • (Unit-type of Hero[(Integer A)]) Equal to Naga Sea Witch (16)
                      • (Unit-type of Hero[(Integer A)]) Equal to Sorcerer (23)
                      • (Unit-type of Hero[(Integer A)]) Equal to Archmage (12)
                      • (Unit-type of Hero[(Integer A)]) Equal to Keeper of the Grove (24)
                • Then - Actions
                  • Hero - Modify Intelligence of Hero[(Integer A)]: Add TempGold
                • Else - Actions
              • Player - Set (Player((Integer A))) Current gold to (((Player((Integer A))) Current gold) - (TempGold x 150))
            • Else - Actions
 
Level 12
Joined
May 22, 2015
Messages
1,051
Hero - Create Item[(Random integer number between 1 and 100)] and give it to Hero[(Integer A)]
What is this doing? Do you initialise this somewhere else? You could try taking this part out. I don't know what happens if you try to do this with an array that hasn't been initialised.
 
Level 11
Joined
Jun 2, 2013
Messages
613
It may have to do with your conversion of real to integer. 1000\ 150 is 6.66666...
My guess is it has to do with those variables.

Edit* You may need to set your TempGold integer using an arithmetic operation if you insist on using a real.

You could also try bumping starting gold to 1500 just to see if it goes away.
 
Level 11
Joined
Jun 2, 2013
Messages
613
Something about this part doesn't look right to me.

attachment.php


What are you doing in that last variable?
 

Attachments

  • Capture.PNG
    Capture.PNG
    14.3 KB · Views: 109
Level 12
Joined
May 22, 2015
Messages
1,051
Do you know what point the trigger crashes? You could disable all the actions and enable them one at a time until the trigger crashes to see what is causing it.

When you say that other part works, is it because you see the hero gets the item? Or maybe it was working before you added the other part?

Anyway, it is hard to help since there is some other stuff that has to happen before this trigger is run and those triggers aren't displayed. The item list and the hero list are the main ones. I feel like if you try to modify hero stats on a null unit it might break it, but I am not sure. It would just be a lot easier to know what is causing the game to crash, whether or not we know why.
 
Level 12
Joined
May 22, 2015
Messages
1,051
So A Player's Current Gold is a real number? I thought it was an integer?

Hero Attributes are integers too so my thought is you should only have to be dealing with integers for what you're trying to do.

All of that shouldn't matter. It was already explained above, anyway. It crashed when it was just integers as well.

Does it crash from the calculations or afterwards? Do you see the heroes get the items or do you mean it is just not crashing from it? A lot of actions are protected in the code in that they will do something by default if their target is invalid, but some others will crash the game.
 
Level 12
Joined
May 22, 2015
Messages
1,051
That array just corresponds to the Hero owned by the respectable Player, I don't see an issue with it.

So if you set TempGold to, a hardcoded number such as say 5, does the game still crash?

It is not set in this trigger, though. It could be all nulls. Giving the item to a null might just spawn it at (0,0), but trying to modify the hero attributes could cause it to crash.

Using a hardcoded number is still a good idea, though.
 
trying to modify the hero attributes could cause it to crash.

This cannot happen, because I already check if the player is computer. And if the player is computer that means he already has hero unit linked with the unit variable.

EDIT: Actually, when I added check to see if the unit is not equal to no unit it works.

EDIT 2: Nah, still crashing. Tho When I tried only with one computer player it didn't crash and worked fine!?

EDIT 3: I tried to solve it by making TempGold array. Still crashing.

  • Upgrade Items of Heroes
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) controller) Equal to Computer
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Level Less than or equal to 6
                • Then - Actions
                  • Hero - Create Item[(Random integer number between 1 and 100)] and give it to Hero[(Integer A)]
                • Else - Actions
              • Set TempGold[(Integer A)] = (((Player((Integer A))) Current gold) / 150)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Unit-type of Hero[(Integer A)]) Equal to Demon Hunter (9)
                      • (Unit-type of Hero[(Integer A)]) Equal to Warden (10)
                      • (Unit-type of Hero[(Integer A)]) Equal to Blademaster (4)
                      • (Unit-type of Hero[(Integer A)]) Equal to Shadow Hunter (6)
                      • (Unit-type of Hero[(Integer A)]) Equal to Dark Ranger (19)
                      • (Unit-type of Hero[(Integer A)]) Equal to Firelord (20)
                      • (Unit-type of Hero[(Integer A)]) Equal to Ranger (13)
                • Then - Actions
                  • Hero - Modify Agility of Hero[(Integer A)]: Add TempGold[(Integer A)]
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Unit-type of Hero[(Integer A)]) Equal to Paladin (1)
                      • (Unit-type of Hero[(Integer A)]) Equal to Mountain King (2)
                      • (Unit-type of Hero[(Integer A)]) Equal to Tauren Chieftain (5)
                      • (Unit-type of Hero[(Integer A)]) Equal to Dreadlord (11)
                      • (Unit-type of Hero[(Integer A)]) Equal to Crypt Lord (8)
                      • (Unit-type of Hero[(Integer A)]) Equal to Alchemist (15)
                      • (Unit-type of Hero[(Integer A)]) Equal to Tinker (17)
                      • (Unit-type of Hero[(Integer A)]) Equal to Beastmaster (18)
                      • (Unit-type of Hero[(Integer A)]) Equal to Pandaren Brewmaster (21)
                      • (Unit-type of Hero[(Integer A)]) Equal to Pit Lord (22)
                • Then - Actions
                  • Hero - Modify Strength of Hero[(Integer A)]: Add TempGold[(Integer A)]
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Unit-type of Hero[(Integer A)]) Equal to Blood Mage (3)
                      • (Unit-type of Hero[(Integer A)]) Equal to Lich (7)
                      • (Unit-type of Hero[(Integer A)]) Equal to Warlock (14)
                      • (Unit-type of Hero[(Integer A)]) Equal to Naga Sea Witch (16)
                      • (Unit-type of Hero[(Integer A)]) Equal to Sorcerer (23)
                      • (Unit-type of Hero[(Integer A)]) Equal to Archmage (12)
                      • (Unit-type of Hero[(Integer A)]) Equal to Keeper of the Grove (24)
                • Then - Actions
                  • Hero - Modify Intelligence of Hero[(Integer A)]: Add TempGold[(Integer A)]
                • Else - Actions
              • Player - Set (Player((Integer A))) Current gold to (((Player((Integer A))) Current gold) - (150 x TempGold[(Integer A)]))
            • Else - Actions
 
Level 12
Joined
May 22, 2015
Messages
1,051
This cannot happen, because I already check if the player is computer. And if the player is computer that means he already has hero unit linked with the unit variable.

EDIT: Actually, when I added check to see if the unit is not equal to no unit it works.

EDIT 2: Nah, still crashing. Tho When I tried only with one computer player it didn't crash and worked fine!?

EDIT 3: I tried to solve it by making TempGold array. Still crashing.

It seems like it is the only action that would cause a crash. That is why I am still bringing it up lol. Try checking if the unit is a hero before doing it. See what happens then.
 
Level 11
Joined
Jun 2, 2013
Messages
613
I also see where SAUS is going. Where are you setting the unit - Hero (1-10) variables. Can we see that trigger as well? What he's trying to say you can't add attributes to a Hero that doesn't exist.

You should have another trigger that sets the Hero[PlayerNumber] variable when a hero enters playable map area, yes?
On the other hand, that attribute action shouldn't run if it isn't set because you are checking unit types. If the variable isn't set it shouldn't even try to add attributes to anything because that block of code doesn't execute when a condition isn't met.
 
Level 11
Joined
Jun 2, 2013
Messages
613
Actually now that I think about it, attribute's may be a real. You can set them to decimal numbers (5.25, 3.5, etc) in Object Editor in the Agility/Intelligence/Strength per level field.

You might could look into adding the attribute as a real number instead of an integer, unless you said you've already tried that.
 
OK. I found that the item variable causes crash now. Why? All items are set. 1 - 100, all set. Or maybe th whole trigger? It's strange because I tried once to disable the atributes and leave items. No problem. Then I anabled attributes and launched the game with only one computer. Worked. Then I tried with more. Crashed. Then I disabled Item. Works. Now, I need to also put item on every hero...
 
Last edited:
Status
Not open for further replies.
Top