Buildings and Upgrades

Level 7
Joined
Sep 8, 2011
Messages
211
Buildings and Upgrades [SOLVED]

I don't really understand how you can trigger around buildings mid upgrade.

Here is what I am trying to do. In the map I am making, each player has a custom resource (known as materials). I want the player to be able to upgrade a building they own using that custom resource (this doesn't replace gold or lumber or food). The only way I can think of doing this is checking if the player has enough materials when the upgrade begins and if they don't, cancel the upgrade.

What I have figured out:

  • Upgrading House
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Ordered unit)) Equal to Tower Base
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(Scout Tower))
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Mats_Number Greater than or equal to 500
                • Then - Actions
                  • Set Mats_Number = (Mats_Number - 500)
                • Else - Actions
                  • Game - Display to Player Group - Player 1 (Red) for 3.00 seconds the text: You don't have enou...
                  • Selection - Select (Ordered unit) for (Owner of (Ordered unit))
                  • Wait 0.01 seconds
                  • Game - Force (Owner of (Ordered unit)) to press Escape/Cancel
            • Else - Actions
        • Else - Actions
If the player doesn't have enough, it should cancel the upgrade. I tested it and couldn't stop the player from bugging it. I added a wait timer but the player can just quickly spam select another unit (even though I force them to select the building) and the building will continue to upgrade. Is there any other way to make it work?

EDIT: Managed to find this post and it answers my question perfectly.
 
Last edited:
Level 11
Joined
Jan 23, 2015
Messages
788
Why not try using Issue unit with no target without waiting?

And don't select the unit for the owner if the one who's starting the upgrade isn't the owner. Cause it may bug when a player has shared control over other player's units and tries to upgrade some of them.
 
Last edited:
Level 11
Joined
Jan 23, 2015
Messages
788
The players can never have shared control on this map. I tried to issue the unit to stop but that doesn't do anything, the only thing I could find that solved my issue was the custom script.

If I don't add the wait in there nothing happens.

I was talking about cancelling construction (but I'm not sure if that even exists)

Why dont you actually create a requirement called "500 materials"? When a player has above that amount you create a unit for that player, when the player falls below that amount you remove the unit.

That's a better solution, you check if there's enough materials, and if there is, you replace the building and select it, and if there isn't, nothing happens (this depends on the spell you're gonna use for upgrade, make sure you modify it so it won't do anything when activated.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
Nono, no need to replace anything.

have a variable to store the required unit and then check the material and the existence of this dummy required unit. Something like this: Note that the point 0,0 should be somewhere that there is nothing of happening.

  • Actions
    • Set pNum = (Player number of Player 1 (Red))
    • Set tempPoint = (Point(0.00, 0.00))
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Material[pNum] Greater than or equal to 500
      • Then - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • reqMaterial500[pNum] Equal to No unit
          • Then - Actions
            • Unit - Create 1 ReqMaterial500 for (Player(pNum)) at tempPoint facing Default building facing degrees
            • Set reqMaterial500[pNum] = (Last created unit)
          • Else - Actions
            • Unit - Kill reqMaterial500[pNum]
            • Set reqMaterial500[pNum] = No unit
      • Else - Actions
    • Custom script: call RemoveLocation(udg_tempPoint)
 
Top