Creating units using triggers

Dangime

New Member
Reaction score
1
Hello, I am new to the forums. I apologize if what I am asking is covered in another thread or in a tutorial I missed.

Thanks to the numerous tutorials on this site I've made alot of head way into making my first map. Right now I've hit a stumbling block on my triggers for creating units.

I had planned to create units by checking for the continued existance of serveral buildings (one for each player) inside the base. If the existance was confimed, then a set of units is produced for the allied AI, then I hoped to send them off to fight the enemy. 5 upgrades are available, so I can give more and better units after the upgrade.

I felt like I made a trigger than would successfully work, for the first level of the building. I used a boolean comparison to check to see if the particular building was still alive, then had the even make the units I want. (I still need to figure out how to force the AI to send them out to die, but that's not my only problem right now).

But then I thought, what about when the player upgrades the building? There's not a way for me to check for a building being alive if it doesn't exist yet (to my knowlegde).

I struggled looking for a condition that would work like, if unit is upgraded to X, but I didn't find any option like that.

Any advice you can provide is appreicated
 

the Lumpy

►►►
Reaction score
53
Well, for that you need to use variables. If you haven't yet, read this tutorial:
http://www.world-editor-tutorials.thehelper.net/variables.php

You need a trigger that fires whenever a unit upgrades. Then you can set the new upgraded unit to the variable, and check if it is alive later using that variable. As for the AI, I'm not quite sure.

If you have any more trouble, post your trigger here. You can right-click the trigger and do "Copy as text" and paste it here.

(Hi, welcome to the forums. I'm happy! Another new person that uses correct spelling and punctuation! :D )
 

Rad

...
Reaction score
228
Code:
Spawning
    Events
        Time - Periodic event - every 30.00 seconds of the game
    Conditions
    Actions
        For each (Integer A) from 1 to 10, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Peasant 0001 <gen> is alive) Equal to True
                    Then - Actions
                        Unit - Create 4 Footman for (Owner of Peasant 0001 <gen>) at (Position of Peasant 0001 <gen>) facing Default building facing degrees
                        Unit Group - Pick every unit in (Last created unit group) and do (Unit - Order (Picked unit) to Attack-Move To (Player 12 (Brown) start location))
                        Unit - Create 2 Rifleman for (Owner of Peasant 0001 <gen>) at (Position of Peasant 0001 <gen>) facing Default building facing degrees
                        Unit Group - Pick every unit in (Last created unit group) and do (Unit - Order (Picked unit) to Attack-Move To (Player 12 (Brown) start location))
                        Unit - Create 1 Knight for (Owner of Peasant 0001 <gen>) at (Position of Peasant 0001 <gen>) facing Default building facing degrees
                        Unit Group - Pick every unit in (Last created unit group) and do (Unit - Order (Picked unit) to Attack-Move To (Player 12 (Brown) start location))
                    Else - Actions
                        Do nothing
[Note: To use code use
Code:
 and [COLOR=Black][/co[/color][COLOR=Black]de][/COLOR] tags]

You will need to replace Peasant with a variable [with an index size of 10, for 10 players, also change the for each integer 1-10 to 1-<number of players>]
Also, when you check if the unit is alive you may want to check its owner to. If its ownedby player 1 then attack player 12, if owned by player 12 attack player 1 etc.

Other than the missing fields, you just need to either get this to work per player [remove for each integer part] or get a system to work with variables [for using for each integer]

NOTE: For each integer is a basic loop, if its 1-8 it runs 8 times, 1-12 is 12 times, 5-12 is 7 times etc. You can also refer to the current loop as 'For integer A' in integer fields. Also use integer B if you need an integer within an integer.
 
C

Clive

Guest
For the computer to die i think you mean for it to move and attack your base kinda like dota, to me thats not really an Ai i think thats more of a trigger.

Event: periodic event- Every 200secs of the game
Condition:
Action:Units-Create 5 footmen at the center of region "footmanspawn"

Now for the the computer to move to get killed or kill

Event: Periodic event- every 200.1 secs
Condition:Triggering Unit = footman
Action: Unit Group- make every unit in region "footmanspawn" move/attack to region "attackzone".

Sometimes they might go another path to the "attack Zone then you want so you just make like points like a 1/2 point or 1/4 and keep making the units that enter that region to go to the next region and to the next until they get to the "attackzone"

Some of the things in the trigger you might have to modify like instead of having footman you wanted idk uhh.. Zombie switch the unit to zombie instead of footman and you might want to midffy the # of units cause i only put 5 but for all I know you might want 10 to spawn and the region could be named differtly.

Hope this helps with the coomputer attacking you. Talk to me again cause i was a little bit confused with your post.
 
H

Heptameron

Guest
Dangime said:
I struggled looking for a condition that would work like, if unit is upgraded to X, but I didn't find any option like that.
You mean, like a Boolean Comparision? Like how the existing ones are for alive, dead, etc., you just want one along the lines of "<town hall> is upgraded to Keep"? Unless I'm misunderstanding, you can use Unit-Type Comparision and check "(Unit-type of <town hall>) Equal to Keep"...
 

Dangime

New Member
Reaction score
1
Thanks for all the help so far. I think it will definately help. Let me explain a little better. I think most of you got what I was asking for, but I'll try to clear it up more.

You are right that it is a DOTA or TOB style map.

My plan is to have the existance of a building, one belonging to each player, activate a trigger if it is still alive that will produce units for the allied AI.

The problem occurs when the player upgrades the building. I'm not sure how to write the trigger to make the better units after the upgrade is done, since it doesn't exist yet.

I think the answer does lie with the variables and a trigger that goes off on every upgrade. I'm going to investigate that now.


The moving problem is secondary since if I can't make the units properly there's no need to move them, but thanks for the help there because I'll want to move them if I ever get that far.
 

Dangime

New Member
Reaction score
1
Heptameron said:
You mean, like a Boolean Comparision? Like how the existing ones are for alive, dead, etc., you just want one along the lines of "<town hall> is upgraded to Keep"? Unless I'm misunderstanding, you can use Unit-Type Comparision and check "(Unit-type of <town hall>) Equal to Keep"...

Yes, but this particular building I've made isn't a town hall. I just based it off a farm, then changed the arts for 5 different upgrades to represent a better capacity to make units. I guess I could change the buildings and do it that way, but only having 3 levels would limit my options.
 
R

Ruination

Guest
Instead of changing the model of the farm for each upgrade, replace the farm with its upgraded version. You'll want a different structure for each upgrade, but they can all be based on farm if you wanted. Give them all different names, and refer to them for the correct spawnage. GL
 

NoxMortus

All Along the Watchtower
Reaction score
104
Make all your spawning triggers, like this:

Code:
Spawning Trigger 1
Events:
Every 55 seconds of game time
Conditions:
Actions:
For each integer from 1 to 3 do actions
Unit - create 1 footman at <your region>
Unit - order last created unit to attack-move to <enemy region>
For each integer from 1 to 1 do actions
Unit - create 1 rifleman at <your region>
Unit - order last created unit to attack-move to <enemy region>

That trigger represents your first level spawn, so the building hasnt been upgraded.

Code:
Spawning Trigger 2
Events:
Every 55 seconds of game time
Conditions:
Actions:
For each integer from 1 to 3 do actions
Unit - create 1 knight at <your region>
Unit - order last created unit to attack-move to <enemy region>
For each integer from 1 to 1 do actions
Unit - create 1 mortar team at <your region>
Unit - order last created unit to attack-move to <enemy region>

That trigger represents your second level spawn, so the building has been upgraded once. This trigger is initially off, as are all other spawning triggers except for the level 1 spawning trigger


Then you would need something like this

Code:
Events:
Unit - Unit finishes upgrade
Conditions:
Unit - Upgrading unit equal to spawning farm  - [I]Here, you may need an 'Or - Multiple Conditions' and then put in all of the types of spawning buildings you have for this team.[/I]
Actions:
Set UpgradeLevel to UpgradeLevel + 1
Trigger - Turn off SpawningTriggers[(UpgradeLevel)- 1]
Trigger - Turn on SpawningTriggers[(UpgradeLevel)]

You would then need to make a trigger that stops units spawning when the building is killed:

Code:
Events:
Unit - A unit is killed
Conditions:
Unit - Dying unit equal to Spawning Farm  - [I]You may also need to put in a 'Or - Multiple Conditions' in here, with all the types of spawning buildings for this team[/I]
Actions:
For each integer from 1 to 12 do actions
Turn off SpawningTriggers[(Integer A)]

You would need 2 variables for this to work:

UpgradeLevel an - Integer variable.

SpawningTriggers - a Trigger variable with an array the size of how many spawning levels you want.

Also note:

Iif you have more than one spawning building then you would need to have more sets of these triggers. i.e if you had 3 spawning buildings, you would have to have 3 sets of the above triggers, with modified conditions, and spawned units.

'For each integer from 1 to __' For action in the spawning triggers, change the blank number to how many of that unit you want to spawn.

I don't have WE on here right now, so this is slightly inaccurate information, but im 99.9% sure it can be done.
 

the Lumpy

►►►
Reaction score
53
If you have a "Unit - a unit Finishes an upgrade" event, what do you use to get the upgraded unit? :confused: There is no "Event Response - Upgraded unit".

EDIT: 200th post! :D
 

Dangime

New Member
Reaction score
1
Well I am not an expert but I solved the problem in a roundabout way. The only reason that it worked was the fact that each player character only had one structure of his or her own, the upgrade building.

I made 10 values called player1basevalue, etc.

I used a player specific "unit finishes an upgrade" command to itterate the base value, then I was able to condition the various levels of spawns I wanted based on the basevalue. I used the fact that the players only had one building to use a player owned unit dies command with a condition that it was a building. In that case, the value is set to 0, and no new units come out.

I made a more complicated set of triggers using player1base as a unit variable, and the same techinque to reassign the variable (player last constructed building), but in the end I didn't use it for anything.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top