[Trigger] Unit upgrade trigger

Level 7
Joined
May 21, 2009
Messages
289
This trigger is supposed to upgrade the building if the player <ai> has enough gold. However, no matter how I try to re-arrange or use different code the building does not upgrade. The purpose here is to be able to keep adding in additional upgrades for the buildings with only a change in the type of building to be upgraded to.

  • AI init
    • Events
      • Map initialization
    • Conditions
      • (Player 4 (Purple) slot status) Equal to Is unused
    • Actions
      • Trigger - Turn on AI spawn upgrade <gen>
Here is the original code before I changed it multiple times. Player 4 only has 3 buildings for the entire game and I have checked to make sure player 4 has enough gold and that the upgrades are in the unit editor.

  • AI spawn upgrade
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Order (Random unit from (Units in (Entire map) owned by Player 4 (Purple))) to train/upgrade to a Peasant Farm
      • Unit - Order (Random unit from (Units in (Entire map) owned by Player 4 (Purple))) to train/upgrade to a Barracks
Any help would be much appreciated.
 
Level 6
Joined
Aug 31, 2011
Messages
125
Well, if you only want One unit to train a thing, don't use "Random Unit", thats probably why, because it can be anyone from "Entire map". and this trigger leaks too :p. Its Entire map, set it to a variable and destroy it like this
"call RemoveLocation(udg_PointVariable)" and that should solve the leaks. And now, if this still doesnt work, make sure the unit has the destination upgrade. For example, Scout Tower can be upgraded to Guard Tower. Well if the building does not have the upgrade, it cant do anything :p. But if you want it to be instant upgrade, dont waste your time on that hehe :p. Use Unit - Replace (or something like that). It will replace the unit with another unit. Meaning that the unit itself will not be in the game and another unit will take its place. And, once its already upgraded, you're gonna have to change the trigger because if it replaces/upgrades again, its just going to upgrade/replace to the same unit xD. But that is out of the question. But anyways, this should help. Edit - If purple isn't a player, it needs to have something so it can upgrade. If purple doesn't have anything, it wont work at all.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 59
Joined
Jan 18, 2005
Messages
26,664
What is the chance that a random unit from all the units in the entire map will be able to apply those upgrades? Your trigger makes no sense which is why it does not work.

You also leak group objects which is very bad.

What you need to do is detect when a player gets enough resources (I believe there is such an event) and then find a random unit from buildings which have that upgrade and send it the order. This however would make for some very stupid AI depending on the map design as it would not have any flexibility and might spend resources on poor choices.

It might also be more efficient to make a proper AI script to do this as that should need less complex script systems to run.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
you dont need to removelocation coz you are not creating a location, but a group instead...
anyway, better to use a global group and add the unit to that group after creation, then
loop the upgrade there rather than picking in the entire map, if the unit dies, remove it
from the group, that way you dont need to destroy a group...
 
Top