• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Spawning units

Status
Not open for further replies.
Level 3
Joined
May 12, 2008
Messages
28
Every 30 seconds I need a unit to spawn at a building, for each building I have.

A really good example is in the Farmers VS Hunters maps where they have sheeps and pigs spawn at their farms every 30 seconds or something. Of course I'd look at these maps except their all in jass or are protected.

Help is appreciated.
 
Level 6
Joined
Mar 15, 2005
Messages
112
  • Spawn
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Barracks) and do (Unit - Order (Picked unit) to train/upgrade to a Footman)
Just make the unit's build time 30 seconds.
EDIT: BTW you might want to remove gold/lumber/food costs that might prohibit this trigger from running.
 
Level 3
Joined
May 12, 2008
Messages
28
=/ I don't think any of these will work, because it requires me to choose one single unit that the animal will spawn at.

The game starts with no farms. Players have to build a farm, and they can do it on any point on the map. I guess my problem now is that I don't see how I can make it be a general unit type of farm, not a specific one that you select.
 
Level 6
Joined
Mar 15, 2005
Messages
112
  • Unit Group - Pick every unit in (Units of type Farm) and do (Unit - Order (Picked unit) to train/upgrade to a WhatEverUnit)
This should work for farms built during the game.
For your other problem you have to change the Build tool tip. Inside the build tool tip it will say "Build |cffffcc00F|rarm" or something similar.
 
Level 3
Joined
May 12, 2008
Messages
28
If that didn't work for you, you are either a total noob at triggers or a retard. In either case, go look at the tutorials...

No tutorials have helped. The only one I could find on spawning didn't help in anyway. And yes, I'm quite a noob to triggers. Hence my asking for help.

If it helps, what I'm doing is EXACTLY how its done in Farmers VS Hunters, which unfortunately is in JASS. When a Farmer builds lets say a Pig Farm, a pig will spawn every 30 seconds and roam around. Each pigs gives x amount of income every x seconds.

If your trigger does fit what I'm trying to accomplish, then will it create a "temp_loc" for each Pig Farm created and stay throughout the whole game, unless destroyed, for every player? It doesn't look like it to me because it says to remove the temp_loc at the end of that same trigger.

So if your trigger does fit: I cannot get it to work. I'm not too experienced with variables. With the temp_loc variable, where do you get the (position of(x)) function? And "your barracks" is specific. I need a unit-type, since the game starts without these buildings. Is there a way to do a unit type after I figure out how to do the position part?

Your help is still appreciated, as well as all others. If I can't figure this out then I'll have to go with an alternative I'd rather not take in my map. Thanks!
 
Last edited:
No tutorials have helped. The only one I could find on spawning didn't help in anyway. And yes, I'm quite a noob to triggers. Hence my asking for help.

If it helps, what I'm doing is EXACTLY how its done in Farmers VS Hunters, which unfortunately is in JASS. When a Farmer builds lets say a Pig Farm, a pig will spawn every 30 seconds and roam around. Each pigs gives x amount of income every x seconds.

If your trigger does fit what I'm trying to accomplish, then will it create a "temp_loc" for each Pig Farm created and stay throughout the whole game, unless destroyed, for every player? It doesn't look like it to me because it says to remove the temp_loc at the end of that same trigger.

So if your trigger does fit: I cannot get it to work. I'm not too experienced with variables. With the temp_loc variable, where do you get the (position of(x)) function? And "your barracks" is specific. I need a unit-type, since the game starts without these buildings. Is there a way to do a unit type after I figure out how to do the position part?

Your help is still appreciated, as well as all others. If I can't figure this out then I'll have to go with an alternative I'd rather not take in my map. Thanks!
sorry, temp_loc should be a variable made in the variable editor by you :)
 
Level 3
Joined
May 12, 2008
Messages
28
Did you add the every 30 seconds of game time event?

Otherwise you could use the create action instead of train action.

Yes I did. And how would I do this trigger with create action?

sorry, temp_loc should be a variable made in the variable editor by you :)

That totally ignored many of my questions/thoughts. So I am still confused as to why this trigger won't work. If its any help this is what the farmer vs hunter map uses for its animal spawning in jass.

JASS:
function Trig_Animals_Spawn_Func001002 takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'nshe', GetOwningPlayer(GetEnumUnit()), GetUnitLoc(GetEnumUnit()), bj_UNIT_FACING )
endfunction

function Trig_Animals_Spawn_Func002002 takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'npig', GetOwningPlayer(GetEnumUnit()), GetUnitLoc(GetEnumUnit()), bj_UNIT_FACING )
endfunction

function Trig_Animals_Spawn_Func003002 takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'n00D', GetOwningPlayer(GetEnumUnit()), GetUnitLoc(GetEnumUnit()), bj_UNIT_FACING )
endfunction

function Trig_Animals_Spawn_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsOfTypeIdAll('h002'), function Trig_Animals_Spawn_Func001002 )
    call ForGroupBJ( GetUnitsOfTypeIdAll('h001'), function Trig_Animals_Spawn_Func002002 )
    call ForGroupBJ( GetUnitsOfTypeIdAll('n00C'), function Trig_Animals_Spawn_Func003002 )
endfunction

//===========================================================================
function InitTrig_Animals_Spawn takes nothing returns nothing
    set gg_trg_Animals_Spawn = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Animals_Spawn, 60.00 )
    call TriggerAddAction( gg_trg_Animals_Spawn, function Trig_Animals_Spawn_Actions )
endfunction

Sigh. Once this is figured out I know its going to be really simple on how to make it work =/
 
Level 17
Joined
Jan 21, 2007
Messages
2,013
Yes I did. And how would I do this trigger with create action?

Well, instead of training the unit you would simply create 1 footman at the farm. basically the same thing but with:
Action
pick every unit with type (barracks) and do (Create 1 (footman) at (position of (picked unit)) for (owner of (picked unit)).)

Not sure at all if this is the problem.
 
  • Spawn Units
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Farm) and do (Actions)
        • Loop - Actions
          • Set temp_loc = (Position of (Picked unit))
          • Custom script: set bj_wantDestroyGroup = true
          • Unit - Create 1 Footman for (Owner of (Picked unit)) at temp_loc facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_temp_loc)
This is exactly the same as the Jass one, except it doesn't leak. BTW you need to make the variable temp_loc (a Point) in the variable editor for this to work. If you want to make it so other building automatically create units, just copy and paste that for another building. No other trigger is needed
 
Level 3
Joined
May 12, 2008
Messages
28
Thank you for more help! Very much appreciated. I'll add you to my list of who to rep once it will actually count! This helps my map quite a bit, and I'm sure I've learned some from it.
 
Status
Not open for further replies.
Top