• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Help with building limitations...

Status
Not open for further replies.
Level 2
Joined
Feb 15, 2018
Messages
8
First of all, Hi guys! I'm new to the forum and this of triggers, I'm trying to make my firts map but I have some problems so... let's go to the point.

I'm making a trigger that limit a type of building (in this case the gold mine) and raise the limit every time the town hall is upgraded (this is a custom town hall), every time the town hall is upgraded one level, a new gold mine is available to build, the problem is that I can't build a new gold mine til I upgrade some of them, for example: I have the town hall lv.2 and one gold mine lv.1, its supposed that I can build one more gold mine but I can't til I upgrade the existing one to lv.2.

This is the trigger:

  • Gold mine limiter
    • Events
      • Unit - A unit Finishes construction
      • Unit - A unit Finishes an upgrade
    • Conditions
    • Actions
      • If ((Unit-type of (Constructed structure)) Equal to Gold Mine Lv.1) then do (Set Numberofgmines[(Player number of (Owner of (Triggering unit)))] = (Numberofgmines[(Player number of (Owner of (Triggering unit)))] + 1)) else do (Do nothing)
      • If ((Unit-type of (Constructed structure)) Equal to Town Hall Lv.1) then do (Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] + 1)) else do (Do nothing)
      • If ((Unit-type of (Triggering unit)) Equal to Town Hall Lv.2) then do (Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] + 1)) else do (Do nothing)
      • If ((Unit-type of (Triggering unit)) Equal to Town Hall Lv.3) then do (Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] + 1)) else do (Do nothing)
      • If ((Unit-type of (Triggering unit)) Equal to Town Hall Lv.4) then do (Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] + 1)) else do (Do nothing)
      • If ((Unit-type of (Triggering unit)) Equal to Town Hall Lv.5) then do (Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] + 1)) else do (Do nothing)
      • If ((Unit-type of (Triggering unit)) Equal to Town Hall Lv.6) then do (Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] + 1)) else do (Do nothing)
      • Player - Limit training of Gold Mine Lv.1 to (Limitofgmines[(Player number of (Owner of (Triggering unit)))] - Numberofgmines[(Player number of (Owner of (Triggering unit)))]) for (Owner of (Triggering unit))
Most probably this isn't the best way to make this type of trigger, so if you could help me I would be very grateful.
 
Last edited:
Level 5
Joined
Jul 27, 2017
Messages
73
Hello,
first of all i recommand to use the if-then-else construction with more lines (not the single-one) --> looks better
also your code is quite redundant --> a personal favor of mine would be to give all Townhalls a special point-value (e.g. 101) and make this a condition for raising the limit.

something i´m not sure about is if upgrades change the limit training of units (sorry at the moment i don´t have the time to test it)
--> my suggestion (a fast one)
Events: A unit finishes an Upgrade
A unit finishes an upgrade

Actions
If
any condition
Point-Value of Triggering unit == 101
Point-Value of Constructed unit == 101 //not sure if this is available
Then
Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = Limitofgmines[(Player number of (Owner of (Triggering unit)))] +1
Player - Limit training of Gold Mine Lv.1 to (Limitofgmines[(Player number of (Owner of (Triggering unit)))])

i hope this helps.
 
Level 2
Joined
Feb 15, 2018
Messages
8
Thanks for the advice, the trigger is more simple now:

  • Gold mine limiter 2
    • Events
      • Unit - A unit Finishes construction
      • Unit - A unit Finishes an upgrade
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Point-value of (Triggering unit)) Equal to 50
        • Then - Actions
          • Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] + 1)
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Point-value of (Triggering unit)) Equal to 54
        • Then - Actions
          • Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] - 1)
        • Else - Actions
          • Do nothing
      • Player - Limit training of Gold Mine Lv.1 to Limitofgmines[(Player number of (Owner of (Triggering unit)))] for (Owner of (Triggering unit))
50=All the Town Hall levels
54=Gold mine Lv.1

But I still have the previous problem, I can't build a new gold mine til I upgrade the last one...
I mean, the limit function works, after I build the new gold mine the trigger don't let me build more til I upgrade the Town Hall, but if I want to build another one after the Town Hall upgrade I need to upgrade also the previous gold mine, and I don't want that to happen.

Also, is there a way to limit the unit-type by its point value? e.g: Limit to X all the units with a point value of Y
If that can be made I think the problem is resolved.
 
Level 5
Joined
Jul 27, 2017
Messages
73
ok if i understand you correctly the situation is like that:
let´s say you have 1 Goldmine (Gm in this text) and 1 Townhall (Th) lvl 1 and the limit of a Gm lvl 1 is 1
You want to build another Gm so you start to upgrade the first Gm.
When the first Gm is a Gm lvl 2 you can build another Gm lvl 1 (this also means that my suggestion of upgrades which don´t affect the limit of a unit is wrong)

If this is true, then you need another trigger to check if a Gm starts to upgrade and one to check if a Gm cancels an upgrade to adapt the training limit to the current situation.
Since i use a german editor i´ll just post the trigger as a text.

First Trigger
Event
Unit - A unit starts an upgrade
Condition
(Unit-type of (Triggering unit) equals Gm_lvl1)
Action
Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = Limitofgmines[(Player number of (Owner of (Triggering unit)))] +1
Player - Limit training of Gold Mine Lv.1 to (Limitofgmines[(Player number of (Owner of (Triggering unit)))])

The second trigger looks pretty the same but with the difference that the event is Cancelling an upgrade
and that limit is decreased by 1

The problem is that this can be abused to build unlimited Gms lvl1 via upgrading an cancelling (even if lvl2 is better than lvl1 but you see the problem) and you have to decrease the limit of the Gm lvl1 when the upgrade is finished.



About the second question: as far as i know this not possible unless you save all (used) units in an array and do a loop action.
If you intend to do something like that, i would build an extra trigger where you save all units of a certain point-value using if-then-else-structs and use variables to give the trigger the information which group of unit-types has to be changed to which value. (This can also be done with Jass because there you can use local variables)
example in GUI
upload_2018-2-17_8-53-57.png


Another hint: Do nothing is not needed in these if-then-else-structs.
I hope this helps you.
 
Level 2
Joined
Feb 15, 2018
Messages
8
I have found the solution without using the player - limit training part!

The final result was this:

  • Gold mine limiter
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gold Mine Lv.1
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Numberofgmines[(Player number of (Owner of (Triggering unit)))] Equal to Limitofgmines[(Player number of (Owner of (Triggering unit)))]
        • Then - Actions
          • Unit - Remove (Triggering unit) from the game
          • Set Numberofgmines[(Player number of (Owner of (Triggering unit)))] = (Numberofgmines[(Player number of (Owner of (Triggering unit)))] - 1)
          • Game - Display to (Player group((Owner of (Triggering unit)))) the text: You have reached th...
        • Else - Actions
This is for the Town Hall:

  • Gold mine limiter 2
    • Events
      • Unit - A unit Finishes construction
      • Unit - A unit Finishes an upgrade
    • Conditions
      • (Point-value of (Triggering unit)) Equal to 50
    • Actions
      • Set Limitofgmines[(Player number of (Owner of (Triggering unit)))] = (Limitofgmines[(Player number of (Owner of (Triggering unit)))] + 1)
And these three for the Gold Mine:

  • Gold mine limiter 3
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gold Mine Lv.1
    • Actions
      • Set Numberofgmines[(Player number of (Owner of (Triggering unit)))] = (Numberofgmines[(Player number of (Owner of (Triggering unit)))] + 1)
  • Gold mine limiter 3 part 2
    • Events
      • Unit - A unit Cancels construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gold Mine Lv.1
    • Actions
      • Set Numberofgmines[(Player number of (Owner of (Triggering unit)))] = (Numberofgmines[(Player number of (Owner of (Triggering unit)))] - 1)
  • Gold mine limiter 3 part 3
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Point-value of (Triggering unit)) Equal to 55
    • Actions
      • Set Numberofgmines[(Player number of (Owner of (Triggering unit)))] = (Numberofgmines[(Player number of (Owner of (Triggering unit)))] + 1)

I can sleep in peace now
Thank you gauda for your help! :D
 
Status
Not open for further replies.
Top