• 🏆 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 with Planting system

Status
Not open for further replies.
Level 4
Joined
Aug 16, 2012
Messages
62
I used the Build Tiny Blacksmith as a base for the ability for planting a crop. I want to know how to make the constructed building die after construction has been completed and upon death an item is spawned at that area.

To give a clear example Shade Gabriel's Founders of The North style of Farming.

Also i want to know how to make buildings spawn items around it and also in its inventory space.
 
Level 9
Joined
Apr 23, 2011
Messages
527
Use the event
  • Unit - A unit Finishes construction
for such triggers.

Kill triggering unit, Use If-Then-Else statements or a loop to detect which type of building was constructed, then spawn the respective item.

For your second part, it depends how exactly you want it. Mind explaining more?
 
Level 4
Joined
Aug 16, 2012
Messages
62
Maybe the mill building that automatically collects nearby plants ?

regards
-Ned

Maybe i made a mistake on how i typed it. A tree(buildable) from Founders of the North spawns fruit(item) near it.

Whilst a mine generates a resource (Stone)- A item stack appears in Slot 1 of the building's inventory space and keeps getting added constantly if it is built on an ore Deposit.

Apologies should have typed them as separate things.
 
Level 4
Joined
Aug 16, 2012
Messages
62
Use the event
  • Unit - A unit Finishes construction
for such triggers.

Kill triggering unit, Use If-Then-Else statements or a loop to detect which type of building was constructed, then spawn the respective item.

For your second part, it depends how exactly you want it. Mind explaining more?

Well here is how i want it The building is being built. The bar becomes full and it is constructed then it dies. An item is created at its dying position.
But I think i have poor text knowledge.

Item create at position of Dying Unit does not work because I used the Kill triggering unit.

I am confused and have been experimenting the logical commands.
 
Level 6
Joined
Aug 28, 2015
Messages
213
There are two ways to do this:(there are obviously more but this ones looks for me the most logical ones)
#1
How Light said:
Event:
A unit finishes construction
Action
Set variable tempUnit to triggering unit(safes to call always the function is a bit more performant but also little bit unsafe)
Set variable tempLocation to position of tempUnit.
If type of unit tempUnit equals yourFirstType then
Create FirstItemType at tempLocation
If type of unit tempUnit equals yourSecondType then
Create SecondItemType at tempLocation
Remove tempUnit
Custom script call removeLocation(udg_tempLocation)
#2
Give all buildings a negative regeneration and a small amount of health so they die by itself.
Variables:
Unit Type Array plantingUnitTypes
Item Type Array plantingItemTypes
Integer index
Integer maxIndex
Unit tempUnit
Location tempLocation

Event:
Map initialization
Action:
Set plantingUnitType[1] to yourFirstType
Set plantingItemTypes [1] to yourFirstItem
....
Set maxIndex to the amount of different types you have.

Event:
Generic unit dies
Action:
If type of unit unequal no unit type then
Set tempUnit to triggering unit
Set tempLocation to location of tempUnit
For index from 1 to maxIndex
If type of unit tempUnit equals plantUnitTypes[index] then
Create item plantingItemTypes [index] at tempLocation
Remove tempUnit
Set tempUnit equals no unit
Custom script call removeLocation (udg_tempLocation)
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
@apsyll Is this some weird hybrid between GUI, JASS and some other script that behaves differently ?
  • Event:
    • Generic unit dies
  • Action:
    • If type of unit unequal no unit type then
      • Set tempUnit to triggering unit
      • Set tempLocation to location of tempUnit
      • For index from 1 to maxIndex
        • If type of unit tempUnit equals plantUnitTypes[index] then
          • Create item plantingItemTypes [index] at tempLocation
          • Remove tempUnit
          • Set tempUnit equals no unit
What if the plant is killed ? You'd get an item.
You have to exit the loop or you will get a null pointer (or at least you should?) on next iteration.
Code:
 If type of unit unequal no unit type then
What is this?

Your first trigger could use a loop instead of repeating if/then/else.

Use trigger or code or jass tags.

regards
-Ned
 
Level 6
Joined
Aug 28, 2015
Messages
213
@nedio95 This is out of my head gui because I am mostly on mobile and can't use real gui but it should give the right direction what to do.
The nulling of tempUnit will be done after the loop is done
And the second one is to check if the triggerinf unit exists
You are right about the killing tho haven't thought about this will do it now and see if I get a good wa,y as workaround you could add on finished construction to a group and check if the unit is in group by killing.
Thats why I made two examples you can mix and match them using if or a loop depending on how many different tyoes you have.
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
@nedio95 This is out of my head gui because I am mostly on mobile and can't use real gui but it should give the right direction what to do.
K, I am not using WE either.
The nulling of tempUnit will be done after the loop is done
This is not clear as you have not used indentation or trigger/code tags.
You don't need to null UDG variables, although, you have to ensure that they always point to the correct data you want to use without interference.
And the second one is to check if the triggering unit exists
If the trigger runs, it exists. That should be fairly obvious?
You are right about the killing tho haven't thought about this will do it now and see if I get a good wa,y as workaround you could add on finished construction to a group and check if the unit is in group by killing.
  • Custom script: endloop
or
  • Custom script: exitloop
I do not remember the syntax for this...
For the killing unit, if you change this:
  • If type of unit unequal no unit type then
to
  • Unit Comparison - (Killing unit) equals to No Unit
or null or whatever, meaning that there is no killing unit, the unit has died without being killed, e.g. health became lower than 0.456 with negative regen.
This may work as intended.
Thats why I made two examples you can mix and match them using if or a loop depending on how many different tyoes you have.
Tbh, I did not understand that there are two different examples in there. I read through the post again and it sounds like you are suggesting a single way to do it.

regards
-Ned
 
Level 4
Joined
Aug 16, 2012
Messages
62
i spent like 5 hours on farming system alone trying make the right logic. I will try again tomorrow thanks to everyone who helped.
 
Level 4
Joined
Aug 16, 2012
Messages
62
Thank you for all those who helped.
I found a solution.
I divided into 2 triggers
Construction will be finished after the construction is finished an ability will be given that murders the plant. Really cool though please tell me if this could cause a crash or a bug.
 
Status
Not open for further replies.
Top