- Joined
- Jan 9, 2005
- Messages
- 2,124
I'm trying to create a custom lumber-harvesting and I'm having some trouble picking the nearest tree to tell the unit to walk to it. Can anybody help?
Hmm, alright then. I hope this doesn't corrupt my map or anything. I'll do a backup to be safe.
I do have another question though. Once I import the libraries, how do I make use of them? Like for instance if I need to pick the nearest tree in a trigger, how do I do it? What's the custom script line to do it, etc.
/* function GetClosestDestructable takes real x, real y, boolean treeOnly, boolexpr filter returns destructable
* - Gets single destructable, nearest passed coordinates*/
Alright, I'll test it out later after I've installed JNPG. Have some +rep for your help
So it's working so far if for a few issues I'm having. I'd like to be able to exclude dead trees from being picked, and also exclude certain trees that are already being 'harvested' or targeted for harvesting.
This is how it works: a locusted unit enters map and targets nearest tree with an ability that once used initiates the harvesting. After X seconds, the tree dies and a treant is spawned in its place. The treant is ordered to cast a spell on the nearest townhall and waddles it way to it, and as it casts its spell the player gains lumber (through triggers) and dies. This creates a new unit that starts the cycle all over again.
The problems here are:
1. The restarting cycle is picking the closest tree, which is dead, and so the new unit can't cast its spell, which means it just stays there.
2. Two of the locusted units could target the same tree and consequently spawn two treants from 1 tree.
3. A tree picked for harvest could be destroyed before the unit has reached it, which would mean I need to find a way for the tree's death to trigger an event that can identify which unit was coming to harvest it and thus give it a new target. This would also be useful to redirect a unit who's tree was killed mid-harvest.
function FilterDest takes nothing returns boolean
return GetDestructableLife(GetEnumDestructable()) > 0
endfunction
The code isn't working (I'm not even sure I'm doing the first part right lol; I copied the function you gave me in a new trigger just like I did when pasting the libraries), and when I save WE tells me there's an undefined function FilterDest, and it cannot convert code to boolexpr, which I guess is one error causing the other.
The code isn't working (I'm not even sure I'm doing the first part right lol; I copied the function you gave me in a new trigger just like I did when pasting the libraries), and when I save WE tells me there's an undefined function FilterDest, and it cannot convert code to boolexpr, which I guess is one error causing the other.
library DerpyLib
endlibrary
Filter(function FilterDest)
because normal WE is a bit bitchy For targeting different trees I could get around this by using the Wisp's lumber harvesting but I can't find the order ID when it actively latches on to a tree.
As for dying trees, I might as well use hashtables since I can't for the life of me figure anything around this. Maybe create a dummy unit (which will be like the key) that every time a tree is targeted it is store in a hashtable. Then, every time a tree dies, the trigger checks if this tree isn't stored in that hashtable, and if it is, find the corresponding harvester, and order it to find a new tree.
Boy this got complicated quick >.<
Made the changes, and the errors are gone, though now the unit isn't moving at all
As for the OrderID (grabtree?) I might have gotten a bit ahead of myself... what's the event trigger to know when the order takes place? I tried with Unit is Issued an Order Targeting an Object but that doesn't work... maybe because no order is actively being issued and it's just... happening?
I also tried with detecting if the Wisp's gather skill triggers with Unit Starts the Effect of an Ability, but that's a bust as well.
Any ideas there?
Woo! Dead trees are no longer being targeted!
Still not quite sure in what context to utilise the GetIssuedOrderId()
I'll wait until you have a better way of typing code. No rush
That still didn't work but I think I found a way around it which may use a lot of hashtables lol (well, that method of lumber-harvesting doesn't require a lot of workers so I think we'll be safe from the 255 limit even if there are 12 players)... unless I can use custom values properly... I'll try something and give an update.
Also is there a way I can filter out a specific destructible from being selected? Like one stored in a variable?
Side question: what is the highest number of values a hastable can store?
2147483648 unique keys.