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

NEED HELP! Gold generation for a building and BR mechanics

Status
Not open for further replies.
Level 2
Joined
May 15, 2016
Messages
3
NEED HELP! Gold generation for a building and Battle Realms mechanics

So... as a newbie in W3WE, i just need a few tips because I'm going to convert Warcraft 3 elements into Battle Realms style of gamplay :) soo... how do i achieve the following:

1.) Convert the Farm building as a gold generator (+1 gold per second per farm constructed and 0 if none are built as well as if all are destroyed) (If i just need to create a custom ability I would appreciate it if you guys would give me pointers ;) )

2.) Like the sacrifice ability of the Sacrificial Pit, I would convert other units into other units(Like converting a peasant into a militia permanently and converting that militia into a footman, etc.)

I would appreciate some help from our masters in the hive :) Thanks in advance :D
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
I dont really understand that first one...
Is it like, generating one gold per second?

That sacrifice ability might be easy to do by just going to the ability tab in the object editor, searching that ability, create a copy of it, change the settings of targets and the transformation units, and adding that ability to your building. (Sorry sacrifice is hard coded to change into a shade.)
If you want to have one ability that can be cast on any unit changing it respectively to what it should be, then you have to trigger that and check for all unit types that it is.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
The easy way is to have a trigger that runs every second looping through all farms (or all units filtering farms) on the map and giving gold to the owner (possibly counting it first and then giving 59 + numberOfFarms if the number is greater than 0).
 
Level 2
Joined
May 15, 2016
Messages
3
My problem for number 1 now is that:

1.) I build farm 1 (+1 gold per second)
2.) I try to construct another farm (farm 2) (still.. 1 gold per second)
3.) farm 2 dies (0 gold per second)

do i have to array the farms that is fully constructed or what i don't know if there is a "If unit dies from full construction" or "If unit destroyed is not on construction" event or condition

thanks for the responses btw i fully appreciate it :)

and btw here is my work so far:





Something like this is what you want, right? By the way sacrifice + build crash the game when a player presses the build button.

I'll try it thanks :thumbs_up:
 
Last edited by a moderator:
Level 11
Joined
Oct 9, 2015
Messages
721
Here we set the number of farms to current number of farms + 1
  • Trigger1
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Farm
    • Actions
      • Set Farms = (Farms + 1)
Here we subtract the number from the farm number
  • Trigger2
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set Farms = (Farms - 1)
Here is the periodic trigger, we set the gold to current gold of player + number of farms
  • Trigger3
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) + Farms)

Here's an multiplayer version, in case you need! just turn the Farms Integer variable into an array.

In this trigger we specify the player number in the array, in this case the owner of the constructed structure.
  • Trigger1
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Farm
    • Actions
      • Set Farms[(Player number of (Owner of (Constructed structure)))] = (Farms[(Player number of (Owner of (Triggering unit)))] + 1)
Same here, but instead of using "Constructed Structure" you can use Triggering Unit OR Dying Unit!
  • Trigger2
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set Farms[(Player number of (Owner of (Triggering Unit)))] = (Farms[(Player number of (Owner of (Triggering unit)))] - 1)
In this one we set the gold for the player. First we pick all players then set it's gold to it's curent gold + Farms Variable array specifiec by the number of the picked player. If it has no farms it's gold will be set to it's current gold + 0 therefore staying unaltered!
  • Trigger3
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Player - Set (Picked player) Current gold to (((Picked player) Current gold) + Farms[(Player number of (Picked player))])
Hope this have been of help and you could understand how it's done, which is the most important! Feel free to ask anything, and everyone to point any flaws!
 
Level 2
Joined
May 15, 2016
Messages
3
Here we set the number of farms to current number of farms + 1

Hope this have been of help and you could understand how it's done, which is the most important! Feel free to ask anything, and everyone to point any flaws!

Just like i said in my dilemma:

1.) I build 1 farm (+1 gold/second)
2.) I construct (but not finish) one farm (still 1 gold/second)
3.) Farm being constructed dies (0 gold/second)

This is a very good solution but I noticed that bug and I thought what if the building farm was to autocast an ability (generate_gold) and per farm casting generate_gold will have +1 gold per second to the current owner
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
When you have finished constructing the structure (in the first trigger), you set a boolean variable to true. This variable is a boolean array.
The Id that is used is the custom value of the constructed structure (you do require a unit indexer and I can recommend Bribe's).

When a unit dies, you do not check if the unit type is a farm, but instead you check if the value of that boolean array with the custom value of the dying unit is true.
If so, you reduce the amount and set the value to false again.

In the last trigger, you also need to check if "Farms[(Player number of (Picked player))]" is greater than 0, if so you add that value and 59 (as the first farm should give 60 gold instead of 1 if I understood it correctly).
 
Level 11
Joined
Oct 9, 2015
Messages
721
Thanks for pointing that out, Rheiko, with other's point of view we can always find room for improvement!

So for it o work correctly it would be like this:
We add the building to the unit group "FarmGroup". We don't need to make the group an array for specific player because we'll use it only for checking purposes to see if the building is finished, not to see if it is owned by this or that player.
  • Trigger1
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Farm
    • Actions
      • Set Farms[(Player number of (Owner of (Constructed structure)))] = (Farms[(Player number of (Owner of (Triggering unit)))] + 1)
      • Unit Group - Add (Constructed structure) to FarmGroup
On this one when the Farm dies, we check if it is in FarmGroup, which would mean it's an finished farm, then we subtract one from the Farm Integer Array. After that we remove it from the FarmGroup as we are no longer needing it in the group.
  • Trigger2
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in FarmGroup) Equal to True
        • Then - Actions
          • Set Farms[(Player number of (Owner of (Triggering Unit)))] = (Farms[(Player number of (Owner of (Triggering unit)))] - 1)
          • Unit Group - Remove (Triggering unit) from FarmGroup
        • Else - Actions
The periodic trigger (Trigger3) should't be modified as it's working fine for us, the only matter as Rheiko pointed out was that unfinished farms would be subtracted from the integer too, and we already corrected it in the triggers above.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You should use the boolean array though, no need for unit groups here.
Also, you should remove that condition if the unit is equal to a farm in the death trigger.

If you will make multiple structures and one have more bonus than the other (for example
"Big Farm" which gives +3 gold,) then you create the If/Then/Else after checking if the boolean is true, that way you can reduce the unnecessary checks.
 
Status
Not open for further replies.
Top