• 🏆 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!

Trigger/JASS Request

Status
Not open for further replies.
Level 12
Joined
Mar 6, 2008
Messages
1,057
Hello there. I am currently in the process of making a campaign, and there are some basics I want to do first before proceeding with the project. These basics I'll need will be essential for every map included in the campaign, and they are part of the default game-play I am planning to make.

Now, I managed to complete the trigger #2 just by using GUI. (I am well experienced in GUI, however JASS was never my thing and simply can't learn it, due to not knowing jack shit about programming) However, as I've seen it might cause leaks and it's not really effective as much as I'd like it to be.

Below I'll write down what triggers I need done, and they shouldn't be too hard for those who are able to write them down in JASS. I'll of course give proper credits to them in the campaign, and in addition to that I am planning to make some Easter Eggs in game for each user whose resources I use and whoever helped on making that project come to life.

Here are the triggers I'll need:

Trigger #1:
I want gold mines (I'll use the default gold mines, even though everything else will be custom made, such as races etc.) to restore lost gold up to 10,000 after not being used for 30 seconds. So for example, if I send a Peasant to collect some gold for me from the mine, mine will lose the gold by defaults. However, if its not mined for at least 30 seconds at all, it'll restore 1 gold each second until mined again.

Oh and have no worries, I don't plan on using the Haunted gold mines nor Night Elven ones. All my races, as the whole campaign itself, will have custom made content and fictional races - where each and every will use default gold mines to gather gold, even the Undead and Dark Elves. (My version of Night Elves)

Short:
1. Maximum amount of gold a Gold Mine is supposed to have is 10,000.
2. If not mined for at least 30 seconds, it'll restore 1 gold each second up to 10,000. (Slowly returning back to maximum)
3. Once mined again, it doesn't restore anything until it stops getting mined for at least 30 seconds.

--------------------------------------------------------------------------------------------------------------------

Trigger #2:
The second one is rather simple, and will be reasoned well why I need it to be like that. My style of making maps is somewhat close to the way MMORPG's function as in whole. I don't spam trees, I don't make them have any huge importance in the ways my maps look, and my maps are more aimed towards the realism rather than default game-play as presented in default Warcraft III.

What I mean by what I've written above is that my maps have a few trees here and there, just to serve as decoration for some other doodads and are purposely placed on each spot they are on. Of course, that as well depends on the region where map is taking place. Here is an example of what I mean by random and calculated placement of trees where they belong, at least in my opinion. Screen-shot is taken from the WIP of first chapter of the campaign I'm making.

Now to get to the trigger itself:
I want trees to, when a worker type of unit is issued an order to harvest, restore their health points to 100%. That way trees can be cut down by other stuff, such as artillery with attack ground and that stuff, however when someone wants to harvest them, they cannot take them down. That is simply because there are not too many trees, and resource gathering is not a priority in my campaign. I want to focus more on the battlefield and tactics.

Short:
1. When a unit is issued an order to harvest the tree, that tree receives a restoration of its health points back to 100%.
2. It can still be destroyed by any other means, such as attack ground by Mortar Team.

--------------------------------------------------------------------------------------------------------------------

Another example of the way my sandbox terrains work is here. These screen-shots are still in WIP stage and much more decorations will be added to the map. Anyhow yeah, just so you can see what I mean by tree placement, that's the purpose of uploading these two images.

Thanks in advance, and of course in case you can do this for me, expect huge credits and an Easter Egg in the campaign related to you, your name or whatever can be recognized as yours.
 
Level 4
Joined
Sep 13, 2014
Messages
106
The difficulty with this is that there is inadequate API for detecting when a gold mine or tree is harvested from.

Anyway, I have attached a map with a system for doing what you want.

The gold mine one was also actually quite a bit easier than the lumber one.

Note: To make the gold mine one, I used the hit points on the gold mines as a variable, to avoid having to use hashtables or arrays or custom unit values, making it simpler. But you do need to be aware of that, in case you want to use it for something else.

Note 2: If enough units are harvesting from a tree at a time (50 peons/peasants, 25 ghouls or 5 shredders), or the tree was partially damaged before workers started gathering from it, then it is still possible for the tree to be destroyed by lumber gatherers.
 

Attachments

  • Gold And Lumber.w3x
    55.4 KB · Views: 61
Level 12
Joined
Mar 6, 2008
Messages
1,057
Thanks a lot for your effort. I am downloading it at the moment and going to test it out.

As for the "If enough units are harvesting from a tree at a time (50 peons/peasants, 25 ghouls or 5 shredders), or the tree was partially damaged before workers started gathering from it, then it is still possible for the tree to be destroyed by lumber gatherers" part, I was well aware of that no matter which system is in use. Anyhow, I doubt they'll be able to use that effort to harvest one tree on my maps.

Once again thanks a lot, I am about to test it right now! :) I'll edit the post with an outcome!
 
Level 12
Joined
Mar 6, 2008
Messages
1,057
I have tested it on the map you provided, and it works flawlessly! I'm amazed. I have just a few questions regarding it as I've read it in Trigger Editor.

1. I see you have stated the types of destructible in the triggers, I mean this. Common sense tells me that I'd have to add custom created trees to the list if I wish to have them included into the system?
2. Another thing related to tree system is the workers, these to be exact. I understand those are used to determine which units are ordered to harvest the lumber? However what bothers me is that I've stated that my campaign will include fully custom tech-trees, with unique and fictional units - nothing of the default ones. Even creeps in the maps will be fully custom made.

So yeah, gold system works flawlessly and I've tested it in like 10 ways, upon which it worked flawlessly and didn't fail for a second. Trees work flawlessly as well, however yes those two questions I've written above are the only things I have to ask before proceeding with it.

By the way, I've already started making something related to you in the Object Editor, so yeah... :)
 
Level 4
Joined
Sep 13, 2014
Messages
106
1. Yes, add custom trees to the list in both HarvestDetect and SmartHarvestDetect.

2. To add custom harvesters, firstly add the harvester to the list you pointed out. Secondly, if it does not harvest at a rate similar to an existing worker, copy one of these triggers and change this number (and the wait time if necessary):

addingcustomunit2-png.240565


Thirdly, copy one of these if statements, add the harvester to the conditions, and change the action to run the trigger you created. Alternatively, if the harvester is similar to an existing one, simply add it to one of the conditions, making sure to use an "or" condition.

addingcustomunit1-png.240566



Two problems I just noticed with my code:

Now that I think about it, using health as a variable for the gold mines could be problematic with haunted/entangled gold mines. In fact, I didn't actually test it with them at all, and it doesn't work. I made a new map that works with constructed gold mines, and it is attached.

Also, it leaks in some places. This is fixed in the new version, but in the old version, you can fix it by adding this to the end of gmDecreaseCheck:

  • Custom script: set goldMine = null
and this to the end of trHealWhileHarvestNormal, trHealWhileHarvestGhoul, and trHealWhileHarvestShredder:

  • Custom script: set healTree = null
  • Custom script: set lumberGatherer = null
The new system uses hashtables rather than hp to store the replenish cooldown, which is probably what I should have done from the beginning, but oh well. I don't think the new system is better in any way other than the removal of the local variable leaks and the ability to handle constructed gold mines.

In the new system, if you want to have a custom gold mine, add it to gmConstructGold and gmDestroyGold
addingcustomgold2-png.240569
and if there are any custom constructed gold mines on the map initially, copy this and set TempGroup = units of type custom.
addingcustomgold1-png.240568
 

Attachments

  • AddingCustomUnit2.png
    AddingCustomUnit2.png
    19.5 KB · Views: 114
  • AddingCustomUnit1.png
    AddingCustomUnit1.png
    22 KB · Views: 113
  • Gold And Lumber v1.01.w3x
    57 KB · Views: 41
  • AddingCustomGold1.png
    AddingCustomGold1.png
    12.6 KB · Views: 103
  • AddingCustomGold2.png
    AddingCustomGold2.png
    12.7 KB · Views: 102
Status
Not open for further replies.
Top