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

Help! 🤦‍♀️🤦‍♂️

Status
Not open for further replies.
Level 3
Joined
Sep 25, 2020
Messages
36
Hi awesome Hive team!

Can someone please help me with a trigger that once I created a farm, every 10 seconds this farm generates an item(wheat) in its location.
 
Level 3
Joined
Sep 25, 2020
Messages
36
Hi Uncle

Thank you so much for the reply, unfortunately It doesnt seem to hold.
1640323299019.png
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Guessing you're not on the latest patch then?

Here's all of the Triggers and the Script if you wish to recreate it yourself:
Variable Types:
FarmHash = Hashtable
FarmUnit = Unit
FarmDuration = Real
FarmTrigger = Trigger
FarmPoint = Point

  • Farm Initialize
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet FarmHash = (Last created hashtable)
      • -------- --------
      • -------- Instructions: --------
      • -------- Set these variables: FarmUnit, FarmDuration, FarmTrigger --------
      • -------- Then create a new action ---> Custom script: call FarmTimerStart() --------
      • -------- --------
      • -------- For ending timers for a specific farm, set FarmUnit and call this function: --------
      • -------- Custom script: call FarmDestroyTimer() --------
      • -------- --------
      • -------- You can also end an expired timer by using this function in it's trigger (Farm Timer Expires): --------
      • -------- Custom script: call FarmDestroyExpiredTimer() --------
  • Farm Construction
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set VariableSet FarmUnit = (Triggering unit)
      • Set VariableSet FarmTrigger = Farm Timer Expires <gen>
      • Set VariableSet FarmDuration = 10.00
      • Custom script: call FarmTimerStart()
  • Farm Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set VariableSet FarmUnit = (Triggering unit)
      • Custom script: call FarmDestroyTimer()
  • Farm Timer Expires
    • Events
    • Conditions
    • Actions
      • -------- This triggers Actions run whenever a Farm timer expires. --------
      • -------- The Farm Timers system has automatically Set the FarmUnit variable to be equal to the correct Farm. --------
      • -------- So you can use the FarmUnit variable to reference the Farm whose Timer just expired. --------
      • -------- --------
      • Set VariableSet FarmPoint = (Position of FarmUnit)
      • Item - Create Cheese at FarmPoint
      • Custom script: call RemoveLocation(udg_FarmPoint)

You need to copy all of this code, create a new Custom Script in the Trigger Editor (Control + U), and then paste the code inside of it:
JASS:
// This code will create a timer and link it to the designated farm.
// Use the GUI variables: FarmUnit, FarmDuration, and FarmTrigger.
// FarmUnit will be set to the associated Farm when it's Timer expires.
// You can use this to create GUI-friendly local timers.

function FarmTimerCallback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    local trigger trig = LoadTriggerHandle(udg_FarmHash, id, 1)
    set udg_FarmUnit = LoadUnitHandle(udg_FarmHash, id, 0)

    // run the GUI trigger
    call TriggerExecute(trig)

    // clean up memory leaks
    set t = null
    set trig = null
endfunction

function FarmTimerStart takes nothing returns nothing
    local timer t = CreateTimer()
    local integer id = GetHandleId(t)

    // save to hashtable
    call SaveUnitHandle(udg_FarmHash, id, 0, udg_FarmUnit)
    call SaveTriggerHandle(udg_FarmHash, id, 1, udg_FarmTrigger)
    call SaveTimerHandle(udg_FarmHash, GetHandleId(udg_FarmUnit), 0, t)

    // start timer
    call TimerStart(t, udg_FarmDuration, true, function FarmTimerCallback)
 
    // clean up memory leaks
    set t = null
endfunction

function FarmDestroyExpiredTimer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    call FlushChildHashtable(udg_FarmHash, id)
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
endfunction

function FarmDestroyTimer takes nothing returns nothing
    local timer t = LoadTimerHandle(udg_FarmHash, GetHandleId(udg_FarmUnit), 0)
    local integer id = GetHandleId(t)
    if id == 0 then
        set t = null
        return
    endif
    call FlushChildHashtable(udg_FarmHash, id)
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
endfunction
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Are you not sure which Actions to use or rather where to find them? Search For Text is there for a reason!

It looks a lot more intimidating than it really is. If I were you I would create the 5 Variables first:
FarmHash = Hashtable
FarmUnit = Unit
FarmDuration = Real
FarmTrigger = Trigger
FarmPoint = Point

Then make each Trigger one by one.

You don't need to make the Comments though, I put those in there to teach you how to use the system:
  • -------- Instructions: --------

So feel free to skip those. This is how simple the first trigger is without Comments:
  • Farm Initialize
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet FarmHash = (Last created hashtable)

The rest of the triggers only have a couple or so Actions as well.

For the code stuff it's a real simple matter of copying and pasting. It's actually the easiest thing to do despite the scary wall of text.

Edit:
Also, if you wouldn't mind changing the thread title to something that describes your problem, that'd be nice.
Something like: "Make building periodically spawn items" would work.
 
Last edited:
Status
Not open for further replies.
Top