"Receive lumber"-trigger

krog99

New Member
Reaction score
2
Hi everyone :)

What should a trigger, which provides player with 25 lumber per second, if the player builded a specific building?


Events: Time - Every 1.00 seconds of game time

Actions: If ..................... then do (Player - Add 25 to Player 1 (Red) Current lumber) else (Do nothing)

Krog99
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Just pick all units of that type, and then give 25 lumber to the onwer of the picked unit ;)
 

krog99

New Member
Reaction score
2
What do you mean, or rather how do i do that?

I think of it a bit like Vampirism Zero's. You build a lumberbase, and then receive some lumber, until the lumberbase has been destroyed.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
This should work ;)

Trigger:
  • Lumber Income
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set LumberMillCount[(Integer A)] = 0
      • Set TempGroup = (Units of type Lumber Mill)
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set LumberMillCount[(Player number of (Owner of (Picked unit)))] = (LumberMillCount[(Player number of (Owner of (Picked unit)))] + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LumberMillCount[(Player number of (Owner of (Picked unit)))] Greater than 1
            • Then - Actions
              • Unit - Kill (Picked unit)
              • Set LumberMillCount[(Player number of (Owner of (Picked unit)))] = 1
            • Else - Actions
              • Player - Add 25 to (Owner of (Picked unit)) Current lumber
      • Custom script: call DestroyGroup(udg_TempGroup)
 

krog99

New Member
Reaction score
2
Ain't there a more simplified way to do it?

A boolean-condition that is true, if red builds a lumbermill, and then turns false, if the lumbermill is destroyed or upgraded?
 

Sui-cookie

You can change this now in User CP.
Reaction score
49
its a variable that is set, in the "all" tab of actions, its just a couple down. called "set variable"

the "LumberMillCount[(Player number of (Owner of (Picked unit)))]" is the variable, which is an array (hoping you know what all that is) and the rest is just sectioned off.
 

Sui-cookie

You can change this now in User CP.
Reaction score
49
when you go to put in the number in the array(ed) variable, you can just go up to the drop down box and select "for loop integer A" and that becomes "integer A" :]
 

Sui-cookie

You can change this now in User CP.
Reaction score
49
no, its a small line of jass that removes the leak that is in your trigger. too many leaks makes your warcraft crash :/
 

Bogrim

y hello thar
Reaction score
154
Follow my instructions and I'll explain it to you step-by-step:

You already have the periodic time event fixed, but the actions need to be the following:

First find the action, "For Each (Integer A) from 1 to 10, do (Actions)" under the general tab. This allows you to create a loop of actions, allowing you to repeat said actions for every player in the game. This is helpful because players not only have color index, but also have a number index. Player numbers range from 1 to 12 (the maximum number of players), so by running a loop 12 times, you can perform an action for each player. These loops also have a number of their own, allowing you to match them to the player's indexes. Your loop should look like this:
Trigger:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions

Next you will want to create a handle for your units. Using a handle is the key to how the game perform actions in the game. We typically refer to handles as variables. Because you are handling multiple units, you need a unit group variable with the action "Set [/u]Variable[/u] = Value". To do this you first need to create the variable by opening the variable window (CTRL + B). Create a new variable (CTRL + N) and find "Unit Group" on the drop down list, name it "Temp_Group".

The reason for I name it "Temp_Group" is because you don't want to create a bunch of handles (as it lags), so you want a handle for temporary use. Hence the popular name, "Temp_Group".

Begin creating your handle in the loop with the Set Variable action:
Trigger:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Set Temp_Group = Value

The next following parts are tricky.

We need to "select" the units in a way that players only gain lumber for the buildings that belong to them, and that the building is in fact alive and not deceased. For this we need conditions to "filter out" what we don't need. The trick here is that we are not limited to a single condition. For this, choose the group handle "Units In Region Matching Condition"

Trigger:
  • Set Temp_Group = (Units in (Playable map area) matching (Condition)


Units in (Playable map area) will cover every unit in the game.

In order to insert multiple conditions, find the condition "And". "And" splits the input choices into two, which is something you're allowed to do more than once, inserting multiple conditions this way. The conditions we are looking for are:

1. A Unit-type comparison. This will allow you to compare the unit-type of your ideal unit to the unit-type you want to provide lumber, filtering out any other unit type. The condition should look like this:
Trigger:
  • (Unit-type of (Matching unit)) Equal to Your Unit Type

Make sure it's "Matching unit". It's important to use the right references when setting up things like conditions, as the game won't otherwise know which unit to use. When you're comparing a unit through a condition, you're basically looking for units "matching a condition", henceforth "matching unit".

2. A player comparison. This is the most tricky part, using the loop's index to our advantage. When we compare players, we compare the owner of the unit in question to the owner matching the current loop. (Each loop has a number of its own, which matches that of a player. First loop is 1, which will correspond to player 1.) To do this, make the following player comparison saying:
Trigger:
  • (Owner of (Matching unit)) Equal to (Player((Integer A)))

You need to use the "Conversion - Convert Player to Index" in order to insert "Integer A", which is actually called "For Loop A" on the list of integer values. Integer A is the variable containing the current loop's number.

3. A Boolean comparison, a condition essential to make sure the building doesn’t grant any lumber while it’s dead but still in the game. In the list of Boolean comparisons, find:
Trigger:
  • ((Matching unit) is alive) Equal to True

And your conditions are good to go. Now the unit group handle be complete and look like this:
Trigger:
  • Set Temp_Group = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Lumber Mill) and (((Owner of (Matching unit)) Equal to (Player((Integer A)))) and (((Matching unit) is alive) Equal to True))))

It’s a pretty long line, but it doesn’t matter. Make sure they're identical, though. Once you created the handle, create make the player action called “Add Property”. It’s going to say “Add 1000 to Player 1 (Red) Current Gold[color/]
There are three fields to edit here. Take the integer value (“1000”) first:

1. Choose "Arithmetic" on the dropdown list. This is how you insert a mathematic equation into the trigger. You'll notice how the area below suddenly changes to allow for several fields to be adjusted. What you have to do is to multiply the number of units in your group handle with the number you wish players to gain per building. I'll explain:

In the red "Value" field, simply scroll down to the first unit-type value called "Unit - Count Units In Unit Group”, and choose your handle Temp_Group in the new window. Change the plus to an “x” for multiplication, and replace the 1 with the desired number of lumber per building.

Trigger:
  • Player - Add ((Number of units in (Units in (Playable map area))) x 25) …


2. Next in the action line, you need to repeat the same trick with the player index. Convert the player to an index and choose For Loop Integer A on the list.

Trigger:
  • Player - Add ((Number of units in (Units in (Playable map area))) x 25) to (Player((Integer A))) …


3. Lastly, change “Current Gold” to “Current Lumber”.

Trigger:
  • Player - Add ((Number of units in (Units in (Playable map area))) x 25) to (Player((Integer A))) Current lumber

You're almost done and your trigger in fact works, but it’s leaking a lot of handles, which generates lag. To prevent this, you have to "delete" the handle in the game. This isn't part of the user interface, so you have to insert a custom line of code using the “Custom Script” action from the General actions. Insert this exact text:

call DestroyGroup( udg_Temp_Group )
Trigger:
  • Custom script: call DestroyGroup( udg_Temp_Group )

This is Jass language and you should consider reading this tutorial for better insight.

Your finished trigger should look like this:
Trigger:
  • Your Trigger
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set Temp_Group = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Lumber Mill) and (((Owner of (Matching unit)) Equal to (Player((Integer A)))) and (((Matching unit) is alive) Equal to True))))
          • Player - Add ((Number of units in Temp_Group) x 25) to (Player((Integer A))) Current lumber
          • Custom script: call DestroyGroup( udg_Temp_Group )

I hope this helps you.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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