• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] How to detect harvesting.

Status
Not open for further replies.
Level 21
Joined
Aug 21, 2005
Messages
3,699
@ Eleandor: You might be right, and i might be wrong, but still,, dont be so negative,
Well, believe me, I'd love to see a 3rd harvestable resource too. If you can pull it off, it'll be great, but that doesn't take away I'm very sceptic and I really doubt it's possible anyway. At least, the current way you've taken will not be a good solution, so you'll have to look at another - more efficient - way...

Pick all units on the map of type (worker) and filter them by the current order.
If it is harvest, check distance between the unit and the target.
Should be a bit more efficient.

Still the same problem. As soon as a worker has delivered its resources to a town hall (or lumber mill, whatever), it receives the "harvest" order, and its current order will stay "harvest" until a player orders it to return resources or its lumber capacity is full. You can't time when he will have harvested 1 wood because you can't predict the future.



The only possible harvesting system would be a completely triggered system, ignoring the warcraft 3 implementation of lumber harvesting.
You have 2 channel based abilities: 1 for gathering and 1 for returning. The gathering has "destructible" targets and a range of, say, 100. Cast time of 1.5 (i.e. the cooldown time of the harvest process)

Whenever the gathering ability is cast, you damage the target destructible with 1 (or the amount of harvested resource) and you increase the unit's custom value. Next, you order the unit to recast the gathering ability on the tree, or if the tree is dead, you check the nearest tree.

When the custom value becomes larger than 0, the harvesting ability is hidden (but can still be used) and the "return" ability is now available to be used. When the custom value becomes e.g. 10, the return ability is automatically given to the nearest building that accepts the resource.

That should work, but still has some consequences with the "smart" order...
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
I already have something for the 'smart' order,,
A unit is issued order targeting an object

Issued order euqal to smart
Unit is a peon-type-unit equal to true

Wait until distance between position of target destrucible and position of triggering unit less then or equal to 140
order Triggering unit to harvest target destructible

---
That makes the order 'harvest' and stops the 'smart' order,,
The thing about WHEN the lumber is harvested, is easy,, the time between each cut is 1.5 secs,, so you add an ability, and set it to +1 every 0.5 secs,, whenever the ability reaches 3 AND the life of the destructible is less then some variable (which is set to the current life after this action every time) then set the custom value,,

Not that hard =)

P.S. I did nothing about leaks yet, that all comes when the sys is almost done,,
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Making a custom harvest system is rather easy - if you use units instead of destructibles.

Detecting when a unit harvests wood from trees is rather hard, as there are not many events for destructibles.
 
Level 18
Joined
Oct 18, 2007
Messages
930
Jass is no option, custom scripts are fine.
So one more time: I need a trigger that will run as soon as a tree is harvested, then I need to check what kind of tree it is.
Depending on the tree the unit will get an custom value, lets say summer tree is value 1 while barrens is value 2.
When the 'lumber' is returned I want to cancel the deposit and the message showing the lumber and instead based of the custom value of the unit store a value to the fitting integer and also show a message.

My main problem is detecting when a resource is harvested and when it's deposited. xD

  • Tree Shit
    • Events
      • Unit is issued to target an object
    • Conditions
      • Issued order equal to "harvest"
    • Actions
      • [Your actions]
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Well, if you would have read about the very first page, you would know that that is no option :grin:
since that doesnt mean it already is harvesting,, and you can also issue that order form the other side of the map,,
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Hmm, the custom harvesting thing seems better yes.
And more simple, oh spiwn I find it rather annoying to use units for there will be like more then a 1000 of those deposits.

With a 1000 units you are better off running Mirror's Edge on a Pentium 2 ;)

I was referring to something like 10-20 per map. Like with gold mines.
I guess you might be able to have 1000 units just staying there as trees but then you won't have many other units :p

If i had more time I would give it a shot at miking a custom tree(wood, lumber, destructible) harvesting system.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
How about doing it like this:
Pick all units on the map of type (worker) and filter them by the current order.
If it is harvest, check distance between the unit and the target.
Should be a bit more efficient.

I tried doing this, but i couldnt figure out (dont know if i write it right) how to know what the units target is,,

This is what i got so far:
  • Maybe
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Entire map) matching ((((Matching unit) is A peon-type unit) Equal to True) and ((Current order of (Matching unit)) Equal to (Order(harvest))))) and do (Actions)
        • Loop - Actions
          • Destructible - Pick every destructible within 150.00 of (Position of (Picked unit)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked destructible) Equal to (Rally-Point of (Picked unit) as a destructible)
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is in zz_Destr_Group) Equal to True
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Custom value of (Picked unit)) Equal to 10
                        • Then - Actions
                          • Unit - Remove Harvest Check from (Picked unit)
                          • Unit Group - Remove (Picked unit) from zz_Destr_Group
                        • Else - Actions
                          • Unit - Set level of Harvest Check for (Picked unit) to ((Level of Harvest Check for (Picked unit)) + 1)
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Harvest Check for (Picked unit)) Equal to 3
                            • Then - Actions
                              • Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) + 1)
                              • Unit - Set level of Harvest Check for (Picked unit) to 1
                              • Game - Display to (All players) the text: ((String((Custom value of (Picked unit)))) + wood!)
                            • Else - Actions
                    • Else - Actions
                      • Unit - Add Harvest Check to (Picked unit)
                      • Unit - Set level of Harvest Check for (Picked unit) to 2
                      • Unit Group - Add (Picked unit) to zz_Destr_Group
                • Else - Actions
I know the Rally/point thing isnt right,, THAT is where it went wrong, how can i check if the picked destructible the target destructible is,,
Otherwise, this method would be the greatest! Only, now i cant set the life into a variable, since you pick a different destr every time,,
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
I still do not have much time to make a harvesting system, but I made something.

You didn't quite get that: All units of type is faster than all units matching condition(Type of Matching unit is The type).

But anyway I realized there is no way to get the target of the current order, so I made something to optimize your process.

You need to edit only "Your Trigger".

P.s. forgot to put a lumber mill or something :D
 

Attachments

  • Tree.w3x
    14.8 KB · Views: 109
Level 17
Joined
Jun 12, 2007
Messages
1,261
I still do not have much time to make a harvesting system, but I made something.

You didn't quite get that: All units of type is faster than all units matching condition(Type of Matching unit is The type).

But anyway I realized there is no way to get the target of the current order, so I made something to optimize your process.

You need to edit only "Your Trigger".

P.s. forgot to put a lumber mill or something :D

Oh noez it's in Jass!
And Jass = Chinese to me! xD

If Yixx can't fix his system, or if somebody does not create something in gui I'll have to use an alternate way of gaining those resources. xD
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
There is nothing in the jass parts that you need to pay attention to.
In order to implement in any other map, just copy/paste the folder.
The main trigger where actions are done is in GUI

And again I say, I am to busy to complete this.
I just made something so that I can sort of assist Yixx.
Someone still has to make the rest.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Ok,, i have taken a look at it,,
But the Group, that has all the harvesting units in it?
So i can just set the custom value,,
But there still is the thing about the time it takes to harvest,,
I can just implent my 'harvest check' abillity in it?
Does it cover walking away from the tree and getting back on cutting?
Cause that caused some problem with mine,,
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
In the group are all the units that their current order is to harvest trees(including smart harvest).
Their custom value is the index for the destructible array that has the trees stored in it.
When the unit is issued any order it is removed from the group, if the order is to harvest a tree, they are added again.

Atm it basically does roughly nothing if you reorder the unit to harvest the same tree.

Edit:
All, to implement, you also have to create the integer variables.
 
Last edited:
Level 16
Joined
Oct 12, 2008
Messages
1,570
Ok, i took a little closer look at it, (BTW, you set the Real to (distance between point 1 and 2), but you didnt set point 2, you set point 1 twice, think that was a mistake of yours, fixed it, if it wasnt,, please say so immediately:grin:)
I renamed the variables, so it is easier to see what variables are used (when airandius is using more variables you know)
(Luckily the Jass converted them too immediately!:grin:)
But, now all i have to do is check if the Real variable is less then 140 (or something) and then use my 'check ready' ability??
Also, you set the custom value to 1 in the beginning, but you didnt set it again and again, so it starts by one, and stays one,,
I set in the GUI trigger Set custom value to + 1, but then it starts with 2, any idea?
Well, that are all the questions so far,,

EDIT:
This is the GUI trigger now (increased the interval, cause it went off to fast)
  • YourTrigger
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in zz_DUnitGroup and do (Actions)
        • Loop - Actions
          • Set zz_DPoint1 = (Position of (Picked unit))
          • Set zz_DPoint2 = (Position of zz_Destructables[(Custom value of (Picked unit))])
          • Set zz_DReal = (Distance between zz_DPoint1 and zz_DPoint2)
          • -------- Go on from here, but do not destroy the group --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • zz_DReal Less than or equal to 140.00
            • Then - Actions
              • Unit - Increase level of Harvest Check for (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Harvest Check for (Picked unit)) Equal to 3
                • Then - Actions
                  • Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) + 1)
                  • Game - Display to (All players) the text: (String((Custom value of (Picked unit))))
                  • Unit - Set level of Harvest Check for (Picked unit) to 1
                • Else - Actions
            • Else - Actions
Ok, when a unit has 7 custom value, you run away from the tree, and order again, then it starts with 3 =S
When i do again, it starts with 4, and then 5! But the unit already has more wood!! =S Strange
 

Attachments

  • (1) Tree Harvest System.w3x
    17.4 KB · Views: 46
Level 12
Joined
Apr 27, 2008
Messages
1,228
Making mistakes is not strange to me.
First comment:
The group managing triggers used the custom values in order to identify the destructibles.
Two choices here:
I can change the jass code so that it uses an attachment system or game-cache.
Or you do not use the custom values to store something, but instead you use an integer array. Use the custom value as an index to that array. In that case you have to add a line in the code:
In the trigger "Order", in the actions function ("Trig_Order_Actions") the line
set udg_*Name_of_Array*[i]=0

so it looks something like this(it can be any line except the first)
JASS:
function Trig_Order_Actions takes nothing returns nothing
    local integer i=AllocateValue()
    set udg_Destructables[i]=GetOrderTargetDestructable()
    call GroupAddUnit(udg_TreehUnitGroup,GetTriggerUnit())
    set udg_*Name_of_Array*[i]=0
    call SetUnitUserData(GetTriggerUnit(),i)
endfunction

The second is easier and better(though the first isn't hard).

P.s. The value in the custom value of a worker is a unique value, assigned to that unit when it is ordered to harvest.
Note that at the moment my group managing works only for peons. Easily changeable to anything anyone wants.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Making mistakes is not strange to me.
First comment:
The group managing triggers used the custom values in order to identify the destructibles.
Two choices here:
I can change the jass code so that it uses an attachment system or game-cache.
Or you do not use the custom values to store something, but instead you use an integer array. Use the custom value as an index to that array. In that case you have to add a line in the code:
In the trigger "Order", in the actions function ("Trig_Order_Actions") the line
set udg_*Name_of_Array*[i]=0

so it looks something like this(it can be any line except the first)
JASS:
function Trig_Order_Actions takes nothing returns nothing
    local integer i=AllocateValue()
    set udg_Destructables[i]=GetOrderTargetDestructable()
    call GroupAddUnit(udg_TreehUnitGroup,GetTriggerUnit())
    set udg_*Name_of_Array*[i]=0
    call SetUnitUserData(GetTriggerUnit(),i)
endfunction

The second is easier and better(though the first isn't hard).

P.s. The value in the custom value of a worker is a unique value, assigned to that unit when it is ordered to harvest.
Note that at the moment my group managing works only for peons. Easily changeable to anything anyone wants.

Ok, i think i understand, so (like some maps do) every unit (most of the times in the map but now) in the group has an own custom value, and you set a variable ( SomeIntegerReplacingCustomValueVariable[custom value of unit] ) to +1?
Is that where you are going to?
And you mean peon-type units, or workers?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Ok, i think i understand, so (like some maps do) every unit (most of the times in the map but now) in the group has an own custom value, and you set a variable ( SomeIntegerReplacingCustomValueVariable[custom value of unit] ) to +1?
Is that where you are going to?
And you mean peon-type units, or workers?

Yeah that is what I meant.

Yeah, except in this case it is not for all units, but only for workers. But a system like PUI can be used and all units will get an index including the workers.

And I meant peasants :p
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Yeah that is what I meant.

Yeah, except in this case it is not for all units, but only for workers. But a system like PUI can be used and all units will get an index including the workers.

And I meant peasants :p

Ok, but this way, you cant return the resources, cause they only have the custom value when they are in the group (close to a tree)
Can you maybe make something to fix it? Or can you just add the unit to the unit group again( and set the custom value) when it gets to the lumber mill or castle,,??
Can you please make a trigger for that,i think then, the system will be done,,
And you will have done the most xD

Oh, and making mistakes is only human (dont know how to say in english), so dont worry,,

BTW: Good job on the system, it really is a little bit about 50 times better then mine xD
Might there be any possible way to make the system in GUI with some custom scrips? Just to satifsy Airandius? =P
I will take a look at it,,
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Hm.
I will do something later.

In the meantime:
How do you intend to detect when the worker deposits?
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Whenever a unit comes within range of a unit matching unit is town-hall type or lumbermill type, then wait unit the lumber of the owning player gets higher, add lumber according to tree-type (something airandius wants) and the integer value, and remove 1 * Integer value (since it is the same as wood carried)

But i found one bug, or actually, cheat,,
When you keep on telling the worker to harvest the tree, and you click away soon enough for him not to cut, you will get integer value extra, but the unit still has no wood,,
Any way to prevent that? Maybe something to think about =P,,
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Lol.
Is Airandius interested only in the deposition, that would be a lot easier :D
Lets check first page.
*checking*
Still not sure.

Hm.
How do you intend to get rid the +## message?

Anyways, if this is only to detect when a unit deposits lumber, none of this is necessary.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Lol.
Is Airandius interested only in the deposition, that would be a lot easier :D
Lets check first page.
*checking*
Still not sure.

Hm.
How do you intend to get rid the +## message?

Anyways, if this is only to detect when a unit deposits lumber, none of this is necessary.

xD Srsly?
He wants to give lumber to a player, according to the lumber carried by a unit, and according to the type of the lumber harvested (snowy tree lumber, or summer tree lumber, you know)

Is this all not needed then?
But since there is no way to check how much lumber a unit carries, I though there was no way to do it easily, so i thought of a destructible harvest system,, That was the whole idead =P
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
You can use the event Player - Player 1's current lumber becomes greater than 0

If Current lumber of Triggering Player is greater than PlayerLumberOld[ Player number of Triggering Player]
Turn this trigger off
Do stuff
Turn it back on

(endif)

set PlayerLumberOld[ Player number of Triggering Player]=Current lumber of Triggering Player


But I thought he wanted to do something with the workers, something else.

P.s. Of course add more events :p
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
You can use the event Player - Player 1's current lumber becomes greater than 0

If Current lumber of Triggering Player is greater than PlayerLumberOld[ Player number of Triggering Player]
Turn this trigger off
Do stuff
Turn it back on
else
set PlayerLumberOld[ Player number of Triggering Player]=Current lumber of Triggering Player


But I thought he wanted to do something with the workers, something else.

P.s. Of course add more events :p

No, there is nothing specifical with the workers, it is only, you cant check which tree the unit harvested if you dont check which unit havested, and set a (maybe string) variable 'attached' to that unit,,
The thing is,, we cant do it easily, i think,, so lets get on with the system =P
Oh, i gotta go now,,
Cya tomorrow maybe =)
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Actually the logic I posted above works every time a worker deposits lumber, and you can get the amount he deposited.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Actually the logic I posted above works every time a worker deposits lumber, and you can get the amount he deposited.

Yes, but how do you want to check what sort of lumber it is?
Like i sais above (or even earlier maybe), Airandius wants to check What kind of tree is harvested AND the amount, so he can give more wood for 'rare' trees or something,, How do you want to check that?
And also,, (dunno didnt check) is there any way to check WHICH unit it is your way??
(dont think so huh?? wel,, i didnt check actually but i thought there wasnt just a quick way,,)
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Better way:
When a unit is ordered to harvest a tree including smart(this part I have already done), set the level of its harvest ability to the coresponding value.
This way different tree types will give you different amounts , text tag on delivery will show you the exact numbers and you could harvest a tree that yeilds a small amount and directly change to another that yeilds more, keeping what you got from the first tree.
P.s. I ain't sure, as I cant examine the Object editor data of the harvest ability atm.

I can make what I began and you ask, but I feel it may be useless.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
yeah ok, but what if you first cut a summer tree,, and then a barrens tree (or some other rare tree) Example:
You cut 9 summer tree wood: you will get 9 wood for it,,
Before you return, you cut 1 barrens wood (rare) Then you will get 40 (or so) for it!
It might be a little useles,, but maybe add a variable to the unit for each wood, so:
  • Set CustomValue[custom value of unit] = (CustomValue[custom value of unit] + 1)
  • Set Wood1[custom value of unit] = (some integer according to the wood type)
  • Set Wood2[custom value of unit] = (some integer according to the wood type)
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Lol
Today I tested my map, It turns out it doesn't work at all :D

Then I played around with the harvest ability and came up with a way to do this, but the floating text's number wont be accurate.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Well, I tried increasing the level of Harvest - no good.
Then I tried replacing harvest with a different harvest - worked, but the lumber carried wasn't saved.
And then I tried adding another harvest - worked :)
(except that there were two messages on delivery)
So The way I came up with:
Make several versions of harvest, exactly the same(with 1 damage to tree).
All but one should go in a spell book. Not sure, as I haven't tested but I think that they can go in different levels of the same spell book. (All) The spell books will be disabled so that they are not displayed.
So when a unit is ordered to harvest a tree, check the tree type and set level of the spell book(or if the above doesn't work add/remove the proper amount of spell books).
Now, when the unit harvests a tree, the tree will be damaged for as much as the number of harvest abilities the units has(assuming they all are set to 1). Also the unit will carry that same amount. And when it delivers the lumber, the player will get the proper amount, but the message will still display a lot of number on top of each other.
This way requires that the tries that yield more lumber have more live.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Well, I tried increasing the level of Harvest - no good.
Then I tried replacing harvest with a different harvest - worked, but the lumber carried wasn't saved.
And then I tried adding another harvest - worked :)
(except that there were two messages on delivery)
So The way I came up with:
Make several versions of harvest, exactly the same(with 1 damage to tree).
All but one should go in a spell book. Not sure, as I haven't tested but I think that they can go in different levels of the same spell book. (All) The spell books will be disabled so that they are not displayed.
So when a unit is ordered to harvest a tree, check the tree type and set level of the spell book(or if the above doesn't work add/remove the proper amount of spell books).
Now, when the unit harvests a tree, the tree will be damaged for as much as the number of harvest abilities the units has(assuming they all are set to 1). Also the unit will carry that same amount. And when it delivers the lumber, the player will get the proper amount, but the message will still display a lot of number on top of each other.
This way requires that the tries that yield more lumber have more live.

Ok, i actually dont understand what you mean xD
I totaly suck at spellbooks, i dont know anything about it, so,,
Well so you got a solution,, Can you set it in a map? :grin:

BTW Good job on finding the solution!!
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
it was a valid solution till i tested :D
Everything works as I said, but blizzard made one last protection to their harvesting system:
When a unit has multiple Harvest based abilities they are always displayed. Putting them in a spell book(be that a disabled one or not) doesn't help.

I guess going back to old way. The problems with it can be fixed and it is not very hard. The only thing that will remain a problem is the message on delivery. But I am too busy. I will have time around 17.02.
 
Level 14
Joined
Mar 4, 2009
Messages
1,156
E-unit is issued targeting an object
C-issued order equal to harvest
C-destructible type of issued order equal to tree
C-distance between ordered unit and targeted destructible less than 150

-Your Actions.....

EDIT ˙(maybe i miss read something xD)
 
Status
Not open for further replies.
Top