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

Training Guard units

Status
Not open for further replies.
Level 5
Joined
Jun 13, 2015
Messages
129
I need help where in the event a unit dies, a unit prod structure will train another unit to replace it(moving to it's region and facing north)
I would like it such that this newly trained unit, when killed, also will trigger another unit to be trained to take it's place so on and on.
 
Level 9
Joined
Apr 23, 2011
Messages
527
What I'm getting from this is that if buildings of type x dies, a new unit of type y is spawned at its location, is that correct? It should be simple to detect such things and create locations accordingly. However, I might be mistaken as to the nature of your trigger.
 
Last edited:
Level 13
Joined
Nov 4, 2006
Messages
1,239
is it only one guard per production building? or can one production building create guards for different positions?

in general the approach is to create a variable for each guard unit and then have a trigger that when this unit dies you train a new one, once it finishes production you set the variable to that unit and order it to go to the guard location.
 
Level 5
Joined
Jun 13, 2015
Messages
129
is it only one guard per production building? or can one production building create guards for different positions?

in general the approach is to create a variable for each guard unit and then have a trigger that when this unit dies you train a new one, once it finishes production you set the variable to that unit and order it to go to the guard location.
I would like for one production building to create guards for different positions. Also you mentioned you need a seperate variable for each guard unit, so in the case if i wanted many gaurds, I would require a whole lot of variables?
 
Level 13
Joined
Nov 4, 2006
Messages
1,239
well in this case you could use a variable array. so the name stays the same but you have a number at the end, one for each unit, to which you can refer to in your triggers.

so let's say you have 20 positions. you give each position a number from 1-20 and you also have an array with size 20 for the guards.

is the unit-type the same for all positions or is it different? how long is the build time for the guards? you have to be careful that you don't overfill the production queue if many guards die around the same time.
 
Level 5
Joined
Jun 13, 2015
Messages
129
well in this case you could use a variable array. so the name stays the same but you have a number at the end, one for each unit, to which you can refer to in your triggers.

so let's say you have 20 positions. you give each position a number from 1-20 and you also have an array with size 20 for the guards.

is the unit-type the same for all positions or is it different? how long is the build time for the guards? you have to be careful that you don't overfill the production queue if many guards die around the same time.

Well I haven't much experience working with arrays but I think I could make it work somehow. As for the unit-type similarity/difference do i need a new variable for each unit type?
This was very helpful as I would never have thought of using arrays. Thank you!
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
If you have only one type of guard you don't need any unit-type variables. If you have many, I would suggest doing something like this to store the data about each guard
  • -------- On map init set these --------
  • Set GuardType[1] = Footman
  • Set GuardType[2] = Militia
  • Set GuardType[3] = Gyrocopter
  • -------- Set these on map init to correspond to each guard post; this COULD be automated to happen at run-time --------
  • Set Guard[1] = (the unit, however your get it. maybe from a unit group - pick, maybe you click preplaced units idk)
  • Set WhatGuard[1] = 1 //guard 1 is a footman
  • Set GuardPosition[1] = (Center of Guard 1 <gen>) //or maybe Position of Guard[1], etc.
  • Set GuardTraining[1] = false //to know if a guard is currently queued for training and dispatch to an unguarded location, so you don't overpopulate your queue as UreDeD suggested
  • Set Guard[2] = (the unit, however your get it)
  • Set WhatGuard[2] = 3 //guard 2 is a gyrocopter
  • Set GuardPosition[2] = (Center of Guard 2 <gen>)
  • Set GuardTraining[2] = false
  • ...
Then when a unit dies, you loop through all the Guard[]s, find the one that's the same unit (whose index I'll call <number>), and train a GuardTypes[GuardPosition[<number>]], set GuardTraining[<number] = true, and set the rally point for the training unit to GuardPosition[<number>]. You'll have to consider training overlap with the rally point setting but I think that would be easier than detecting the trained unit event and trying to figure out where it's supposed to go once it's spawned.
 
Level 5
Joined
Jun 13, 2015
Messages
129
If you have only one type of guard you don't need any unit-type variables. If you have many, I would suggest doing something like this to store the data about each guard
  • -------- On map init set these --------
  • Set GuardType[1] = Footman
  • Set GuardType[2] = Militia
  • Set GuardType[3] = Gyrocopter
  • -------- Set these on map init to correspond to each guard post; this COULD be automated to happen at run-time --------
  • Set Guard[1] = (the unit, however your get it. maybe from a unit group - pick, maybe you click preplaced units idk)
  • Set WhatGuard[1] = 1 //guard 1 is a footman
  • Set GuardPosition[1] = (Center of Guard 1 <gen>) //or maybe Position of Guard[1], etc.
  • Set GuardTraining[1] = false //to know if a guard is currently queued for training and dispatch to an unguarded location, so you don't overpopulate your queue as UreDeD suggested
  • Set Guard[2] = (the unit, however your get it)
  • Set WhatGuard[2] = 3 //guard 2 is a gyrocopter
  • Set GuardPosition[2] = (Center of Guard 2 <gen>)
  • Set GuardTraining[2] = false
  • ...
Then when a unit dies, you loop through all the Guard[]s, find the one that's the same unit (whose index I'll call <number>), and train a GuardTypes[GuardPosition[<number>]], set GuardTraining[<number] = true, and set the rally point for the training unit to GuardPosition[<number>]. You'll have to consider training overlap with the rally point setting but I think that would be easier than detecting the trained unit event and trying to figure out where it's supposed to go once it's spawned.

Mmmm, I think this trigger may be what I needed. It's also pretty straightforward i guess compared to what I've been trying to do. Thanks all for your help, I think i'll mark this forum as solved now :)
 
Status
Not open for further replies.
Top