• 🏆 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!
  • ✅ HD Level Design Contest #1 POLL is now OPEN! Check out the stunning visuals of the final entries. 🔗Click here to cast your vote!

Creating an income that loops [Awaiting Improving: Ralle]

How well did this help?

  • Awsome 5/5!

    Votes: 4 25.0%
  • Very Well 4/5!

    Votes: 1 6.3%
  • Average 3/5

    Votes: 7 43.8%
  • Needs Tweaks 2/5

    Votes: 2 12.5%
  • Needs Alot of Work 1/5

    Votes: 2 12.5%

  • Total voters
    16
Level 13
Joined
Jun 10, 2007
Messages
780
Creating a Looping Income

Don't vote on numbers, but on how it would help someone in need of this. Even if this wouldn't help you, it just might help somebody else. Don't write retarded comments like "Oh my god so easy!!1". I DON'T care if you know how to do it. If you can, good for you.

Requirements
World Editor [Comes with Wc3]
General Trigger Knowledge
General Variable Knowledge

Difficullty:3/10

Contents
Hold Ctrl and press F to skip to a section.
-Introduction
-Step 1
-Step 2
-Step 3
-Extras
-Closing



Introduction

Income is an amount of money (gold in this case :wink:) that you obtain over a certain period of time. In this short tutorial, I will show you the basics of making an income that can loop if needed.


Step 1

Before we make any part of the income, we will need a variable, which stores the amount of income.
Steps
1)Open the trigger editor
2)Press Ctrl+B
Once your there you create a new variable. I'm naming mine Income just for the purpose of the tutorial. Now, make the variable an integer because its storing a number (our income number). Make it array if you have multiple incomes.
Now your variable should look a little like this:

Tut1.png

Change the initial value if you want to have a starting income. Now that we have the variable we can move onto step 2.


Step 2

Now we will need to diagnose what we need the income for. Some may need a looping income for a tower defense, some may need it for there job income. Ill show you the basic use for it.

  • Income Give
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
  • For each (Integer A) from 1 to 6, do (Player - Add Income[(Integer A)] to (Player((Integer A))) Current gold)
This will give players 1-5 an income every 30 seconds. Of course you would add income to each player on your game and you would change the time but this is a basic use. Now comes the harder part of the tutorial.. This part requires you to add the income. To add income, we will require a different trigger.


Step 3

Create a new trigger and name it adding income or something by that means. You will need a specific event for giving income. Heres a small example

  • Example1
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Owner of (Killing unit)) is an ally of (Owner of (Dying unit))) Equal to False
      • (Owner of (Killing unit)) Not equal to (Owner of (Dying unit))
    • Actions
      • For each (Integer A) from 1 to 6, do (If ((Owner of (Killing unit)) Equal to (Player((Integer A)))) then do (Set Income[(Player number of (Owner of (Killing unit)))] = Income[(Income[(Player number of (Owner of (Killing unit)))] + 1)]) else do (Do nothing))
When the unit dies, it will add +1 to the killing unit's owner's income. So if red kills teals Blademaster, red will gain an extra +1 income. The event is very flexible and even add conditions to change what you want the income to affect.

All you have to do is give value to the integer and it will give income! to add to an already existing income then do this

Tut2.png

Extras

I have some extra actions and information if you would like to add them to your triggers.

Having an initial income value
If you would like your players to start out with an initial (beginning) income value, there are two ways of doing it.

1:Go into your variable editor and change the income variables default value to any number.

2: Use this trigger
  • For each (Integer A) from 1 to 10, do (Set Income[(Integer A)] = 30)
This changes the income for players 1-10 (Red - LB)'s income to 30.


Closing

I hoped this tutorial has helped someone and thanks for reading! Reply in the thread so that I can make this tutorial better!
UPDATE: I added more to the testmap and fixed things up a bit. I added some more sections as well :grin:. Heres the demo map for the income View attachment Income Version 2.0.w3x


OLD VERSION: View attachment Income.w3x
 
Last edited:
Level 21
Joined
Sep 22, 2007
Messages
2,772
An easier way for the actual income is this:

  • Event
  • Time - Every 30.00 seconds of game time
  • Conditions
  • Actions
  • Player Group - Pick every player in (All Players) and add ((Picked Player)'s gold + (Income(Player Number of Picked Player))) to (Picked Player)'s gold.
...something like that...
 
Level 2
Joined
Mar 25, 2005
Messages
4
An easier way for the actual income is this:

  • Event
  • Time - Every 30.00 seconds of game time
  • Conditions
  • Actions
  • Player Group - Pick every player in (All Players) and add ((Picked Player)'s gold + (Income(Player Number of Picked Player))) to (Picked Player)'s gold.
...something like that...

This leaks, quite a bit, it leaks a player group, you would need to add the player to a variable, of a player group.


  • Income
    • Events
      • Time - Every (What ever you want) seconds of game time
    • Conditions
    • Actions
      • Set Income_Group = (All players)
      • Player Group - Pick every player in Income_Group and do (Actions)
        • Loop - Actions
          • Player - Add (Whatever you want) to (Picked player) Current gold
      • Custom script: call DestroyForce(udg_Income_Group)
That would fix the problem
 
Omg, You guys should learn how to build algorithms.

Achtung, Kinder!
JASS:
function Unit_Dies_Actions takes nothing returns nothing
local integer i = GetPlayerId(GetOwningPlayer(GetAttacker()))
    set Income[i] = Income[i] + 1
endfunction

and for the 30 seconds timer

JASS:
function Income_Actions takes nothing returns nothing
local integer i = 0
local player p
    loop
        exitwhen i > 12 //use 16 if you want to use every neutral as well.
        set p = Player(i)
        call SetPlayerState(p, PLAYER_STATE_GOLD_GATHERED, GetPlayerState(p, PLAYER_STATE_GOLD_GATHERED) + Income[i])
        call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) + Income[i])
        set i = i + 1
    endloop
//don't use forces for useless things like this. Forces are used for administrating players.
//I normally use them for alliences and things that require to group players(very few).
endfunction

Note: I never use non-native functions for actions that must be extremely fast.
 

Ralle

Owner
Level 77
Joined
Oct 6, 2004
Messages
10,089
When setting up the array you didn't set it to how many players you want, didn't note it either.
Please use the new [h1][h2][h3] tags, read the The Hive Workshop - A Warcraft III Modding Site - Announcements in Forum : Tutorial Submission.
Please use smarter triggers
- Pick all players from all players and add income[number of player] to picked player's gold
- Also, set income[ owner of killing unit ]*to income[ owner of killing unit ]+1 and remember to check that you didn't kill your own unit.
 
Level 3
Joined
Jul 20, 2008
Messages
41
This leaks, quite a bit, it leaks a player group, you would need to add the player to a variable, of a player group.


  • Income
    • Events
      • Time - Every (What ever you want) seconds of game time
    • Conditions
    • Actions
      • Set Income_Group = (All players)
      • Player Group - Pick every player in Income_Group and do (Actions)
        • Loop - Actions
          • Player - Add (Whatever you want) to (Picked player) Current gold
      • Custom script: call DestroyForce(udg_Income_Group)
That would fix the problem

You just destroyed "All players" . You shouldnt :wink:
 
Top