• 🏆 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] Question about an Income Trigger

Status
Not open for further replies.
Level 4
Joined
May 20, 2011
Messages
59
Hey Guys,
I'm developing a Map similar to the style of Maps such as Greece. Risk, and so forth and I'm having a bit of trouble trying to have an income system based on the number of acquired buildings. I've seen pseudo-code such as this obtained from How do you make buildings that generate money? - Warcraft III: The Frozen Throne Message Board for PC - GameFAQs

*Code*
Farms
Events
Time - Every 60.00 seconds of game time
Conditions
Actions
Player - Add ((Number of living Farm units owned by Player 1 (Red)) x 3) to Player 1 (Red) Current gold
Player - Add ((Number of living Farm units owned by Player 2 (Blue)) x 3) to Player 2 (Blue) Current gold
Player - Add ((Number of living Farm units owned by Player 3 (Teal)) x 3) to Player 3 (Teal) Current gold
Player - Add ((Number of living Farm units owned by Player 4 (Purple)) x 3) to Player 4 (Purple) Current gold
Player - Add ((Number of living Farm units owned by Player 5 (Yellow)) x 3) to Player 5 (Yellow) Current gold
Player - Add ((Number of living Farm units owned by Player 6 (Orange)) x 3) to Player 6 (Orange) Current gold
Player - Add ((Number of living Farm units owned by Player 7 (Green)) x 3) to Player 7 (Green) Current gold
Player - Add ((Number of living Farm units owned by Player 8 (Pink)) x 3) to Player 8 (Pink) Current gold
Player - Add ((Number of living Farm units owned by Player 9 (Gray)) x 3) to Player 9 (Gray) Current gold
Player - Add ((Number of living Farm units owned by Player 10 (Light Blue)) x 3) to Player 10 (Light Blue) Current gold
Player - Add ((Number of living Farm units owned by Player 11 (Dark Green)) x 3) to Player 11 (Dark Green) Current gold
Player - Add ((Number of living Farm units owned by Player 12 (Brown)) x 3) to Player 12 (Brown) Current gold
*Code*

But the problem with this is that I'm literally unaware of what I should be clicking as I go through the triggers to obtain this kind of result, this is perfect and is exactly what I'm looking for, but the farthest I can get right now is this:

GenerateIncomeExample
Events: Time - Every 60.00 Seconds of the Game
Conditions: N/A
Actions: Add((Number of living City units owned by Player 1 (Red)) to Player 1 (Red) Current Gold

So how can I have it multiply the amount of living cities (the number generated by that reference) by an integer, such as 3, 10 and so forth? Like literally what am I clicking as I go through to edit it? Thank you all so much for the help to come. As always, it is greatly appreciated.

Cordially,
Adorm
 
Level 10
Joined
Sep 16, 2016
Messages
269
Firstly, the whole long lines of action can be reduced a lot by using integer loop and conversion of player index to player. Which is:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Add 1000 to (Player((Integer A))) Current gold
The multiplying part is "Arithmetic". I.e: choose the 1000 in the example above and find that word, you can extend the formula.
 
Level 4
Joined
May 20, 2011
Messages
59
Firstly, the whole long lines of action can be reduced a lot by using integer loop and conversion of player index to player. Which is:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Add 1000 to (Player((Integer A))) Current gold
The multiplying part is "Arithmetic". I.e: choose the 1000 in the example above and find that word, you can extend the formula.
If I was going to keep the setup as is and not make it a loop, how would I go about it?
 
Level 4
Joined
May 20, 2011
Messages
59
Currently I was able to figure out to be like this, I followed creating a loop as you advised, but I'm having a hard time understanding how to set it up as (Player(Integer A)), I'm familiar with Coding as I know Java and understand the concepts, but not being able to write in the code manually gets me a bit lost, like in regards to what I click through to get to that point and such. Been a while likely just a learning curve I need to pass through, thank you though as this helps so much.

****

For each (Integer A) from 1 to 12, do (Actions)
Player - Add(10x(Number of City units owned by Player 1(Red)) to Player 1 (Red) Current gold.

^^^ My Current Trigger
 
Level 4
Joined
May 20, 2011
Messages
59
Was able to figure this out. Wasn't really there in the open if your not familiar with the editor. To anyone searching as I did, I was able to complete the trigger by selecting the Player as Integer A by selecting Function: Conversion - Convert Player Index to Player and then selecting integer A. The concept is similar to that of a For Loop in Java. And may be even written as the following had the same task been needed to complete with that Programming Language:

for (int i = 0; i < numPlayers; i++) {
//Code in Java that would be Equivalent to the Trigger
}

**Only provided this for conceptualization**
 
Level 4
Joined
May 20, 2011
Messages
59
In the function of choosing player, there is an option called Conversion - convert player index to player
In the function of choosing integer, there is an option called For loop integer A
Just saw this as soon as I posted my reply as to figuring it out. Thank you so much for all your help, this was a great breakthrough that will push this project forward strides for me :D
 
This looks like it was already solved but I'll answer anyway:

JASS:
function Trig_Farms_Loop takes nothing returns nothing
    local integer i = 0
    loop
        call SetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED, GetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED) + 1000)
        //tantamount to call AdjustPlayerStateBJ(1000, Player(i), PLAYER_STATE_GOLD_GATHERED)
        exitwhen i == 11
        set i = i + 1
    endloop
endfunction

function InitTrig_Farms takes nothing returns nothing
    call TimerStart(CreateTimer(), 60., true, function Trig_Farms_Loop)
endfunction
 
Level 4
Joined
May 20, 2011
Messages
59
This looks like it was already solved but I'll answer anyway:

JASS:
function Trig_Farms_Loop takes nothing returns nothing
    local integer i = 0
    loop
        call SetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED, GetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED) + 1000)
        //tantamount to call AdjustPlayerStateBJ(1000, Player(i), PLAYER_STATE_GOLD_GATHERED)
        exitwhen i == 11
        set i = i + 1
    endloop
endfunction

function InitTrig_Farms takes nothing returns nothing
    call TimerStart(CreateTimer(), 60., true, function Trig_Farms_Loop)
endfunction
How would you put this in the Editor as Code? Using a Custom Script? I'm not familiar with how this would be implemented but this looks like it would be great.
 
How would you put this in the Editor as Code? Using a Custom Script? I'm not familiar with how this would be implemented but this looks like it would be great.

This is in JASS. (Sorry for including it in a predominantly GUI thread)

You would look for the convert to custom text option for your trigger. Let's say you have a trigger called SomeName

  • SomeName
  • Events
  • Conditions
  • Actions
When you convert the trigger into custom text, you will see something like this:

JASS:
function Trig_SomeName_Actions takes nothing returns nothing
endfunction

function InitTrig_SomeName takes nothing returns nothing
    set gg_trg_SomeName = CreateTrigger()
    call TriggerAddAction(gg_trg_SomeName, function Trig_SomeName_Actions)
endfunction

You can then replace the following code with this:

JASS:
function Trig_SomeName_Actions takes nothing returns nothing
    //Here, you add your functions...
endfunction

function InitTrig_SomeName takes nothing returns nothing
    call TimerStart(CreateTimer(), 60, true, function Trig_SomeName_Actions)
    //the fourth parameter (function Trig_SomeName_Actions) is the function
    //you want to execute, which means that it could be any function.
endfunction

As for this part, I will explain a bit:

JASS:
function Trig_Farms_Loop takes nothing returns nothing
    local integer i = 0
    loop
        call SetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED, GetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED) + 1000)
        //tantamount to call AdjustPlayerStateBJ(1000, Player(i), PLAYER_STATE_GOLD_GATHERED)
        exitwhen i == 11
        set i = i + 1
    endloop
endfunction

the part SetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED, GetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED) + 1000) is the native called when you try to add resources.
For the local integer i, you start with 0. Why 0? It is because the player id of players is their number minus one. That means Player 12 is in reality, Player(11). As you can see in the commented section, if you use this action...

  • Player - Add 1000 to (Player((Integer A))) Current gold
And convert it into JASS, it becomes...

JASS:
call AdjustPlayerStateBJ(1000, Player(GetForLoopIndexA()), PLAYER_STATE_GOLD_GATHERED)

Now, if you're asking which one you should use, it is all up to you to decide.

As for your question itself, which I think is resolved already, you can use the arithmetic operation found in the integer section of the GUI.

Again, I apologize for introducing a bit of JASS into a GUI thread.
 
Last edited:
Level 4
Joined
May 20, 2011
Messages
59
This is in JASS. (Sorry for including it in a predominantly GUI thread)

You would look for the convert to custom text option for your trigger. Let's say you have a trigger called SomeName

  • SomeName
  • Events
  • Conditions
  • Actions
When you convert the trigger into custom text, you will see something like this:

JASS:
function Trig_SomeName_Actions takes nothing returns nothing
endfunction

function InitTrig_SomeName takes nothing returns nothing
    set gg_trg_SomeName = CreateTrigger()
    call TriggerAddAction(gg_trg_SomeName, function Trig_SomeName_Actions)
endfunction

You can then replace the following code with this:

JASS:
function Trig_SomeName_Actions takes nothing returns nothing
    //Here, you add your functions...
endfunction

function InitTrig_SomeName takes nothing returns nothing
    call TimerStart(CreateTimer(), 60, true, function Trig_SomeName_Actions)
    //the fourth parameter (function Trig_SomeName_Actions) is the function
    //you want to execute, which means that it could be any function.
endfunction

As for this part, I will explain a bit:

JASS:
function Trig_Farms_Loop takes nothing returns nothing
    local integer i = 0
    loop
        call SetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED, GetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED) + 1000)
        //tantamount to call AdjustPlayerStateBJ(1000, Player(i), PLAYER_STATE_GOLD_GATHERED)
        exitwhen i == 11
        set i = i + 1
    endloop
endfunction

the part SetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED, GetPlayerState(Player(i), PLAYER_STATE_GOLD_GATHERED) + 1000) is the native called when you try to add resources.
For the local integer i, you start with 0. Why 0? It is because the player id of players is their number minus one. That means Player 12 is in reality, Player(11). As you can see in the commented section, if you use this action...

  • Player - Add 1000 to (Player((Integer A))) Current gold
And convert it into JASS, it becomes...

JASS:
call AdjustPlayerStateBJ(1000, Player(GetForLoopIndexA()), PLAYER_STATE_GOLD_GATHERED)

Now, if you're asking which one you should use, it is all up to you to decide.

As for your question itself, which I think is resolved already, you can use the arithmetic operation found in the integer section of the GUI.

Again, I apologize for introducing a bit of JASS into a GUI thread.
Don't be apologetic at all! I'm eager to learn more and more about how to perform the complicated stuff in regards to the editor, I know Java and already understand the concepts of coding so I'm able to read this easily, this is an awesome opportunity for me to learn more of the Syntax for and begin to introduce myself to JASS, thank you so much for explaining how to do this. I'm gonna probably mess around and spend some time today or later turning simple triggers into JASS and then practicing writing them as hardcoded JASS. Thank you so much for taking the time to explain this, it is greatly appreciated and is quite fascinating!
 
Level 8
Joined
Jan 28, 2016
Messages
486
Would it be better to use timers instead? I don't know if this helps explain my point but let's take the following scenario:
  • At Time = 0 seconds, the game begins and the GUI periodic trigger starts
  • At T=30, you have 10 farms
  • At T=60, you gain X gold per farm
  • At T=80, you lose 5 farms
  • At T=100, you rebuild the 5 farms you lost
  • At T=120, you still gain X gold per farm, even though 5 have only been up for 20 seconds.
If you end up using Jass though, you could make the income MUI by starting a timer when a building is complete that has the 60 second time-out. That way, you would need the building to stand for at least 60 seconds no matter what. Hope this makes sense.


You can then replace the following code with this:

JASS:
function Trig_SomeName_Actions takes nothing returns nothing
    //Here, you add your functions...
endfunction

function InitTrig_SomeName takes nothing returns nothing
    call TimerStart(CreateTimer(), 60, true, function Trig_SomeName_Actions)
    //the fourth parameter (function Trig_SomeName_Actions) is the function
    //you want to execute, which means that it could be any function.
endfunction

I hate to nitpick here but wouldn't you need to register an event with that trigger? For instance, TriggerRegisterTimerEvent.
 
Would it be better to use timers instead? I don't know if this helps explain my point but let's take the following scenario:
  • At Time = 0 seconds, the game begins and the GUI periodic trigger starts
  • At T=30, you have 10 farms
  • At T=60, you gain X gold per farm
  • At T=80, you lose 5 farms
  • At T=100, you rebuild the 5 farms you lost
  • At T=120, you still gain X gold per farm, even though 5 have only been up for 20 seconds.
If you end up using Jass though, you could make the income MUI by starting a timer when a building is complete that has the 60 second time-out. That way, you would need the building to stand for at least 60 seconds no matter what. Hope this makes sense.




I hate to nitpick here but wouldn't you need to register an event with that trigger? For instance, TriggerRegisterTimerEvent.

I removed the trigger object itself and used a timer directly. Since the name of the function starts with InitTrig, it will get called in the InitCustomFunctions (something) portion of the code, which is inaccessible to the coder, which means that on map Initialization, the function that I wrote above will run.

For now, I provided a basic function that does what the code in the post does and kept the naming convention.
 
Level 8
Joined
Jan 28, 2016
Messages
486
I removed the trigger object itself and used a timer directly. Since the name of the function starts with InitTrig, it will get called in the InitCustomFunctions (something) portion of the code, which is inaccessible to the coder, which means that on map Initialization, the function that I wrote above will run.

For now, I provided a basic function that does what the code in the post does and kept the naming convention.

I see. Wasn't aware that you could run a timer like that; that's pretty cool.
 
Status
Not open for further replies.
Top