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

Is there a better way to do this?

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
  • Check if base is claimed
    • Events
      • Unit - A unit Begins construction
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Constructing structure)) Equal to Flag
          • (Base1 <gen> contains (Constructing structure)) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • BasesInUse[1] Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Bases[1] Not equal to (Owner of (Triggering unit))
                • Then - Actions
                  • Unit - Set (Constructing structure) construction progress to 0%
                • Else - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BasesInUse[1] Equal to False
                • Then - Actions
                  • Set Bases[1] = (Owner of (Triggering unit))
                • Else - Actions
        • Else - Actions

Basically, I have a unit. He can build a building which is a flag, the trigger activates when a building starts constructing. I check through a ton of variables which checks if the structure is equal to a flag, check if that specific base is in use or not. Check if base is in use then check if owner of constructing structure and if not then set the construction progress to 0, which I hope cancels the building and refunds the resources? And if the base isn't in use then set the variables to that specific player.

Idk how else to do this without this massive tech tree, I'm probably missing something too as I haven't tested this yet. I'm wondering if someone could help me shorten this or do it more efficiently?
 
Level 11
Joined
Jun 2, 2004
Messages
849
Well for one, that won't cancel construction. This custom script will:
Code:
call IssueImmediateOrderById(GetTriggerUnit(), 851976)
(replace triggering unit if appropriate)

However it comes with the downside that it won't work if used immediately when the building starts construction. You have to use a small wait or timer, which will probably be sufficient if a bit ugly.

The alternative is to remove the structure and refund the resources manually. If it's just these flags it's not a big deal, though if you have many buildings like this then keeping track of the resource cost of each and every one of them is going to be tedious.


Also you can shorten the code a bit like this:

  • Check if base is claimed
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Flag
      • (Base1 <gen> contains (Constructing structure)) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • BasesInUse[1] Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Bases[1] Not equal to (Owner of (Triggering unit))
            • Then - Actions
              • Unit - Set (Constructing structure) construction progress to 0%
            • Else - Actions
        • Else - Actions
          • Set Bases[1] = (Owner of (Triggering unit))
This is 100% equivalent to what you posted, just with less junk.
 
Level 12
Joined
Dec 2, 2016
Messages
733
It's the "cancel" order ID. Or so at least google tells me. And yes it needs to be that exact number.

I have this

  • Check if base is claimed test
    • Events
      • Unit - A unit Begins construction
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Base1 <gen> contains (Constructing structure)) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • BasesInUse[1] Equal to False
              • (Unit-type of (Constructing structure)) Equal to Flag
            • Then - Actions
              • Set Bases[1] = (Owner of (Constructing structure))
              • Set BasesInUse[1] = True
              • Game - Display to Humans the text: ((Name of (Owner of (Constructing structure))) + has claimed base 1!)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BasesInUse[1] Equal to True
                  • Bases[1] Not equal to (Owner of (Triggering unit))
                • Then - Actions
                  • Custom script: call IssueImmediateOrderById(GetTriggerUnit(), 851976)
                  • Game - Display to (Player group((Owner of (Constructing structure)))) the text: |cffffcc00This base...
                • Else - Actions
        • Else - Actions
I entered exactly what you wrote, the text comes up that the base is claimed but the unit does not exit constructing. I should mention the construction time is like 1 second do you think the trigger is running too slow vs the construction time?
 
Status
Not open for further replies.
Top