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

Structure Costs Items To Build?

Status
Not open for further replies.
Level 5
Joined
Feb 5, 2021
Messages
89
Hello there everybody! Thanks for checking in :)

I have been working on a map inspired by survival minecraft with alot of randomness, i want to be able to "chop a tree" and get wood, this part i have down pretty well, so the interesting part here is the fact that i cant for the love of god make anything work, this said i am no expert, i dont even believe myself to be amateur, but way below, i can do some basic things where i get stuff to spawn / move and these things SO.
My Question.. :D

What do i need to do to make it so that when i craft lets say "Wood Wall" it removes like 5 "Wood" from the hero's inventory, and if he doesnt have 5 "Wood" then it would Error in some way?

I am up for using pretty much anything to make this work :)
I have structures already with a custom inventory and all that and i can make it work with normal gold and lumber but i really dig the whole "inventory building" theme.

- Thanks, Ruvven
 
Level 5
Joined
Feb 5, 2021
Messages
89
It does not ring a bell no, could you maybe explain what it does and where i can find it? :D
 
Level 23
Joined
Jun 26, 2020
Messages
1,838
I don't know what exactly you wanna do, but if you have the items like the mormal inventary of W3 and I assume that items you acumulate them (aka increase the number of charges of that item) you can use that function to know how many of that item you have.

And pls, show me how work what are you doing just in case.
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,457
Look at some Items that have charges already like Wand of Lightning. Once you have Item charges working you can move onto the next step:

Units issue orders for just about everything they do in Warcraft 3. So when a worker is instructed to build a structure by the player, the worker is issued a specific order to do so. You can detect this order using the Event "A unit is issued an order targeting a point". To figure out the name of these orders you can Display a text message:
  • Game - Display to (All players) the text: (String((Issued order)))
From there you can check the number of charges that your worker has. So if your worker's Wood item has enough charges then you allow the structure to be built, otherwise, you interrupt the build order. The mechanics here are stubborn and I found that the only way to properly interrupt the worker's build order was to issue a "move" order to it. In this case you can issue a move order to the position of the worker offset by a small amount, which effectively stops the worker. In most other cases you can simply issue a "stop" order to interrupt a unit.

After that you'll want to handle what happens when the order was successful, which in this case would be subtracting the Wood charges. This will be done when the unit actually begins constructing the structure. The Event here is called "A unit begins construction". You can do something simple like have a Condition that checks the Unit-Type of the Constructing unit. If it's a Farm (let's say Farms cost 5 Wood) then you subtract 5 charges from the worker's Wood item. Now here's the tricky part, this Event doesn't actually provide you with an Event Response equal to the Worker. So you can't get the worker that began constructing the structure. But what you can do is get the player who began constructing the structure (Owner of constructing unit) and from there get that player's worker. (This is assuming that you control a single worker that will be using these Wood items, if you will have more than 1 unit with Wood it becomes a bit more complicated).

Anyway, you do this using a Unit array variable. It's assigned to each player's worker using that Player's number as the [Index]:
  • Set Variable Worker[1] = Player 1's worker unit
  • Set Variable Worker[2] = Player 2's worker unit
  • Set Variable Worker[3] = Player 3's worker unit
With those variables assigned (usually at the start of the game) you can do something like this:
  • Events:
  • Unit - A unit begins construction
  • Actions:
  • Set Variable PN = Player number of (Owner of (Constructing unit))
  • Unit - Kill Worker[PN]
Obviously you don't want to kill the worker but this is just an example to show you how you can interact with it. PN is an Integer variable that I use as a shortcut here, I set it to be equal to the Player Number of whoever began construction, so 1 if Red, 2 if Blue, 3 if Teal, etc. This is useful if you want to reference the player's worker multiple times since PN is a lot quicker than doing Player number of (Owner of (Constructing unit)) over and over again. Work smart, not hard ;)

So in the above trigger you would subtract the charges from the Worker's Wood item. Sorry for not giving you the exact triggers to do this but hopefully you can piece it together using what I've provided.
 
Last edited:
Level 5
Joined
Feb 5, 2021
Messages
89
I don't know what exactly you wanna do, but if you have the items like the mormal inventary of W3 and I assume that items you acumulate them (aka increase the number of charges of that item) you can use that function to know how many of that item you have.

And pls, show me how work what are you doing just in case.
Currently i have nothing as nothing i have tried concerning this specific problem has worked but it seems like you get the idea from what you wrote :)

Look at some Items that have charges already like Wand of Lightning. Once you have Item charges working you can move onto the next step:

Units issue orders for just about everything they do in Warcraft 3. So when a worker is instructed to build a structure by the player, the worker is issued a specific order to do so. You can detect this order using the Event "A unit is issued an order targeting a point". To figure out the name of these orders you can Display a text message:
  • Game - Display to (All players) the text: (String((Issued order)))
From there you can check the number of charges that your worker has. So if your worker's Wood item has enough charges then you allow the structure to be built, otherwise, you interrupt the build order. The mechanics here can be stubborn and I found that I had to issue a "move" order to prevent the worker from building the structure anyway. I ordered the worker to move to it's position offset by some very small amount like 0.01. It's weird... Anyway, with that design you can now prevent the construction of the structure from ever happening in the first place.

After that you'll want to handle what happens when the order was successful, which in this case would be subtracting the Wood charges. This will be done when the unit actually begins constructing the structure. The Event here is called "A unit begins construction". You can do something simple like have a Condition that checks the Unit-Type of the Constructing unit. If it's a Farm (let's say Farms cost 5 Wood) then you subtract 5 charges from the worker's Wood item. Now here's the tricky part, this Event doesn't actually provide you with an Event Response equal to the Worker. So you can't get the worker that began constructing the structure. But what you can do is get the player who began constructing the structure (Owner of constructing unit) and from there get that player's worker. (This is assuming that you control a single worker that will be using these Wood items, if you will have more than 1 unit with Wood it becomes a bit more complicated).

Anyway, you do this using a Unit array variable. It's assigned to each player's worker using that Player's number as the [Index]:
  • Set Variable Worker[1] = Player 1's worker unit
  • Set Variable Worker[2] = Player 2's worker unit
  • Set Variable Worker[3] = Player 3's worker unit
With those variables assigned (usually at the start of the game) you can do something like this:
  • Events:
  • Unit - A unit begins construction
  • Actions:
  • Set Variable PN = Player number of (Owner of (Constructing unit))
  • Unit - Kill Worker[PN]
Obviously you don't want to kill the worker but this is just an example to show you how you can interact with it. PN is an Integer variable that I use as a shortcut here, I set it to be equal to the Player Number of whoever began construction, so 1 if Red, 2 if Blue, 3 if Teal, etc. This is useful if you want to reference the player's worker multiple times since PN is a lot quicker than doing Player number of (Owner of (Constructing unit)) over and over again. Work smart, not hard ;)

So in the above trigger you would subtract the charges from the Worker's Wood item. Sorry for not giving you the exact triggers to do this but hopefully you can piece it together using what I've provided.

This is deffo a mouthful with my very limited knowledge of how Wc3 works i will probably have to ask in the specific trigger thread for more help but i will try my very best on figuring out the construction thingie, you gave me alot of progress that i havn't been able to figure out myself, thank you very much! :D
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,457
I attached a map with the system I described above. It's not perfect and will bug out in certain situations but it should at least help to get you started.
 

Attachments

  • Wood Example.w3m
    19 KB · Views: 9
Level 5
Joined
Feb 5, 2021
Messages
89
I attached a map with the system I described above. It's not perfect and will bug out in certain situations but it should at least help to get you started.
Oh my! i will get right on top of it! :D Thank you very much!
 
Level 5
Joined
Feb 5, 2021
Messages
89
I attached a map with the system I described above. It's not perfect and will bug out in certain situations but it should at least help to get you started.
I had a lot of things personally to deal with so i have only just come to downloading your map now, it is really well done from a beginners point of view since you have not only given an example but also from what i can tell, you tried to show me how things work with each other, i really appreciate that!
Thank you very much buddy!
 
Status
Not open for further replies.
Top