• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Spawning units for income

Status
Not open for further replies.
Level 12
Joined
Mar 30, 2013
Messages
664
Hi!

Im using a Fortress that players can send units and get income for it for an example. if they send units:

-Footman You get income of 2 Gold.
-Knight You get income of 5 Gold.
-Elite swordsman You get income of 10 Gold.

So im wonderring if some one knows how to make that income?

If you didnt understand it please comment below and i will fix your problems with it. :goblin_good_job:
 
There's many ways, you could use point value if your not using it already.

Unit dies as event
condition - killing unit is an enemy of triggering unit
action - player add gold - point value of dying or triggering unit.

These aren't the real triggers, just quick-similar made-up ones to try to help.

If you need it to be made or something else, let me know and I can see what I can do to help.
 
Level 12
Joined
Mar 30, 2013
Messages
664
Ok looks nice!

But i'll try to tell you the best i can.
When a player have send 1 knight for 5 gold. He recives 5 gold as income.
If he sends 3 more he got 20 gold as income and those 20 gold will be his income until a Timer have counted down to 30 to zero. And when it reached 0 he got his income and its 20 gold.
 
Level 7
Joined
Sep 9, 2007
Messages
253
I would save each players income into an Integer Variable and then recall the value of that variable when you want to give the income to the player. Each time the player trains another unit you use a trigger to add to the value of the variable.

If you don't know about Variables/Arrays then I strongly suggest reading a few of the Tutorials here on Hive (that is how I learned it and it's one of the most useful things to know in mapping). Here is a good one to start off with http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/variables-5896/

Firstly you open Variables which is the yellow X icon in the trigger editor. Create a new variable and give it a name (something like Income_Var so you can tell what it is when you are reading through your triggers). The Variable Type will be "Integer" and make sure you tick the box next to "Array". Now you have created your integer Array you will be able to see it in the trigger aditor where you will save some numbers into the variable.... Here are the triggers.


  • Add to income
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • Set Income_Var[(Player number of (Triggering player))] = (Income_Var[(Player number of (Triggering player))] + (Point-value of (Trained unit-type)))
The amount of Income added for training a unit depends on what the unit's Point Value, this can be set to each unit in the object editor (note this is not the only way to set how much income each unit will be worth but I think it's an easy way).

Using this method of setting each unit's point value in the object editor means you only need this single trigger to add income to any player for any unit type.



  • give income
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Player - Add Income_Var[(Integer A)] to (Player((Integer A))) Current gold
          • Game - Display to (Player group((Player((Integer A))))) for 4.00 seconds the text: (You got + ((String(Income_Var[(Integer A)])) + gold from income))
You can use If/Then/Else to check if the player is playing. or If player 12 is a computer player you could do for each Integer A from 1-11 and then it doesn't work for player 12.

I realise this is not exactly how you want it to work but I'm sure that you can edit this to work how you want, hopefully I am helping with the variable controlled income system.


Let me know if you don't know how these triggers work.
 

Attachments

  • test map INCOME.w3x
    16.3 KB · Views: 50
Level 25
Joined
May 11, 2007
Messages
4,650
  • For each Integer_Your_Awesome_Integer, 1 to 12
  • Loop - Actions
  • Player - Add Income_Var[(Integer_Your_Awesome_Integer)] to (Player((Integer_Your_Awesome_Integer))) Current gold
  • Game - Display to (Player group((Player((Integer_Your_Awesome_Integer))))) for 4.00 seconds the text: (You got + ((String(Income_Var[(Integer_Your_Awesome_Integer)])) + gold from income))
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
can you give an example of how to do this? I read your tutorial some time ago but I keep using the GUI loop because I didn't understand what you mean.
It honestly doesn't matter, but if you really want to do it for some reason then just use For Loop (Custom Integer) rather than For Loop Integer A or For Loop Integer B.
 
It honestly doesn't matter, but if you really want to do it for some reason then just use For Loop (Custom Integer) rather than For Loop Integer A or For Loop Integer B.

It actually does matter especially for larger loops. Integer A / B use more of the op-limit up than a custom integer. So the bigger the loop the worse it gets. Plus everyone always says function calls are slow on here. When using integer A as array indexer it calls a function which is why it hits op-limit much faster.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
It actually does matter especially for larger loops. Integer A / B use more of the op-limit up than a custom integer. So the bigger the loop the worse it gets. Plus everyone always says function calls are slow on here. When using integer A as array indexer it calls a function which is why it hits op-limit much faster.
  • The extra function calls will be inlined if you use JassHelper or War3MapOptimizer.
  • Even if the person doesn't use either of the above tools, I assure you that you, and 99% of other JASSers on the Hive, could replace every function call they ever make with an associated BJ (if applicable)--including all the associated downsides such as having to work with locations rather than coordinates and the presence of numerous minor leaks in Blizzard code--and they would literally never notice the performance difference in their career. In GUI, the same thing is complaining about the presence of a snowflake in a blizzard.

The only case in which it actually matters is when you're using a wait in your For Loop Integer A/B, which can cause issues for completely unrelated reasons.

I know that pedantic trivial optimization is the cool kid's thing to do these days and if you really want to do it then it's your funeral, but impressing upon newbies that it's as important as things which actually matter such as leak removal just confuses them completely unnecessarily. Someone who is worried about their code being influenced by the speed of BJs shouldn't be using GUI in the first place.

I think that a lot of modern coders, especially those on THW and influenced by the Nestharus school of thought, could really use being dropped in 2005 and trying to write some stuff with the tools at the time. You might be initially horrified by how inefficient and ugly the libraries we used (notably Local Handle Vars) were, and yet somehow people could still write physics systems with none of the modern optimizations (separate timer per projectile, no timer recycling, occasionally leaks that people didn't know existed etc etc) and yet stuff still didn't lag. JASS is by no means fast, but you still usually need to try pretty hard or leak absurd amounts of objects to make your map lag.
 
The extra function calls will be inlined if you use JassHelper or War3MapOptimizer.

Even if the person doesn't use either of the above tools, I assure you that you, and 99% of other JASSers on the Hive, could replace every function call they ever make with an associated BJ (if applicable)--including all the associated downsides such as having to work with locations rather than coordinates and the presence of numerous minor leaks in Blizzard code--and they would literally never notice the performance difference in their career. In GUI, the same thing is complaining about the presence of a snowflake in a blizzard.

Actually Jasshelper does not inline For Each Integer A / B

I know that pedantic trivial optimization is the cool kid's thing to do these days and if you really want to do it then it's your funeral, but impressing upon newbies that it's as important as things which actually matter such as leak removal just confuses them completely unnecessarily. Someone who is worried about their code being influenced by the speed of BJs shouldn't be using GUI in the first place.

That is just rude. I could care less about being cool on here lol. It is important to teach new people the correct way of coding rather than say doing this, then having them learn that what you taught them is incorrect.

I think that a lot of modern coders, especially those on THW and influenced by the Nestharus school of thought, could really use being dropped in 2005 and trying to write some stuff with the tools at the time. You might be initially horrified by how inefficient and ugly the libraries we used (notably Local Handle Vars) were, and yet somehow people could still write physics systems with none of the modern optimizations (separate timer per projectile, no timer recycling, occasionally leaks that people didn't know existed etc etc) and yet stuff still didn't lag. JASS is by no means fast, but you still usually need to try pretty hard or leak absurd amounts of objects to make your map lag.

Yes Jass is slow. All the more reason to optimize as much of your code as you can. With progress comes optimizations. If you don't optimize you might as well stay in 2005 as you put it. The way you want everyone to code means that we should accept all types of inefficient code that is put on here.
Maps with a ton of systems can and most likely will end up lagging that is why it is better to optimize everything. The more inefficient triggers the more chance of lag. Why ruin a good game because you got lazy with optimizing your code ?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
If you are using GUI you are by definition not optimizing your code. And no, I'm not saying people who have the option should go out of their way to replace all their function calls with BJs and such, but my point is that for people who are way below the level of paying attention to any of that stuff you are going to make them do extra work and confuse them for a completely unnoticeable efficiency gain. Nor am I saying that we should code by 2005 standards (for readability reasons if nothing else), merely that you'd be surprised at how much inefficiency can afford to be in even commonly called code without noticeably affecting performance, especially with modern tools which fix much of it after the fact.
 
Yes the new tools definitely help. But I don't see how efficient coding can confuse anyone. It makes code much more readable.
One system can be inefficient and still run without lag yes. But it still runs slower and the more systems you use the slower it gets.
I have seen a few maps get destroyed due to lag from one system. It is bad coding practice to code inefficiently. Also if those people have to spend hours going through their code after they finished because of lag then I bet they would've wished that we told them the correct way on how to code efficiently.
 
Level 7
Joined
Sep 9, 2007
Messages
253
@deathismyfriend

I think I'm with PurplePoot on this one.

When I posted my reply here I took the OP as someone who has only just started opening up the world editor and doesn't have any background in coding. If I think the better way of learning how to make a map is learn how all the basics work and worry about learning optimization later.

Having said that I did learn something from your post so thanks for posting it and I have learned a ton from your tutorials in the past. I just agree with PurplePoot that the OP should probably ignore optimisation for now and just focus on getting his systems working first.
 
Status
Not open for further replies.
Top