need help with tower defence

Discussion in 'Starcraft 2 (SC2) Editor Help' started by MissKerrigan, Mar 29, 2012.

  1. MissKerrigan

    MissKerrigan Active Member

    +23 / 0 / -0
    Hi I need some help with a tower defence, I don't want that poison towers or slow towers hit the same enemy

    Does anyone knows how to solve this?
  2. Dave312

    Dave312 Censored for your safe viewing

    +269 / 0 / -0
    You could add an effect to the attack which orders the tower to attack a random unit within its range. You could add the target unit to the exclude property to ensure it doesn't attack the same unit twice. The only problem is that if the player wants the tower to only attack a specific unit, it will always attack once then move onto another target.

    To implement, go to the Effects data type and create a new effect of the type Issue Order. Set the Ability: Ability property to Attack, set Target: Target + to Target Unit, and set Unit: Unit + to Caster. Now create another new effect of the type Search Area and open up the Search: Areas + property. Add a new area and set the Effect to the issue order effect you just created, Maximum Count to 1, and Radius to the attack range of your tower. Close the window and add Target to the Search: Exclude + property. Edit the Search: Search Filters property and uncheck Player and Ally (you probably want to make this the same as the Weapon: Target Filters property on the towers weapon). Finally set the Target: Impact Location + property to Caster Unit/Point.

    Now I assume that to add the special effects (ie slow and poison) to your towers weapon, you are using a Set effect? Find this set effect and add the Search Area effect you just created.

    I have tested this and have come across an issue that I haven't been able solve. The tower will keep attacking the same two units because of the way the game engine executes search area effects. Since we only want the tower to attack one unit, I have set the maximum count on the Search Area effect to 1. But the engine seems to count objects from Top Left to Bottom Right, so since the Search Area effect is limited to selecting one unit, it will always select the unit that is in the most Top Left (because it finds this unit first), hence the selection is not random but rather fixed. I do remember seeing something about selecting a random unit in the data editor but can't for the life of me remember where that was (maybe someone else might know?). However because you are working on a TD, and typically the creeps always keep moving, the unit in the Top Left should always keep changing, thus this issue might not be a problem for you.
  3. MissKerrigan

    MissKerrigan Active Member

    +23 / 0 / -0
    Alright Dave, thx at first !

    I tell you what I found out so far and what crazy things I tried! haha

    I edited the 'poison weapon' targets excluded: hidden
    I create a trigger:

    event: any player using effect 'poison'
    condition: none
    action 1: modify triggering effected 'target' unit 'hidden' on
    action 2: wait 5 seconds (poison time)
    action 3: modify triggering effected 'target' unit 'hidden' off

    Now my poison tower will attack some other target when poisoned a unit but here is a problem!
    Because I set the triggering effected 'target' unit to 'hidden' the unit disappears!! haha

    Does anybody know why I cannot change the unit attribute by trigger?
    For example trigger: switch unit to 'light' 'biological' or 'armored'
    This would make it possible to solve my problem because I set the poison weapon excluded targets 'biological' or 'armored' then

    I also tried to make a validator 'poison validator' but can't find anywhere in the editor to let the poisno weapon excluded this targets
    The only possibility for edit the weapon seems attributes, only here you can program which target your weapon can hit

    Another thing I tried is searching for unit priority but I can't find anywhere in the editor to make a trigger which increase the poisoned unit to a higher priority

    I hope Siretu reads this and know some anwser to it
    Come on, it's a starcraft 2 editor with like 100.000 possibilities, don't tell me this is not possible :)

  4. Dave312

    Dave312 Censored for your safe viewing

    +269 / 0 / -0
    There probably is a data based solution, but I just don't know. In the meantime, below is a trigger based solution. It just orders the tower to attack another random unit within range of the tower

    • Tower Redirect
      • Events
        • Unit - Any Unit is attacked
      • Local Variables
        • Unit Group = (Empty unit group) <Unit Group>
      • Conditions
        • (Unit type of (Attacking Unit)) == Poison Tower
      • Actions
        • Variable - Set Unit Group = (Units in (Region((Position of (Attacking Unit)), 7.0)) having alliance Enemy with player (Owner of (Attacking Unit)) matching Excluded: Missile, Dead, Hidden, with at most Any Amount)
        • Unit Group - Remove (Triggering unit) from Unit Group
        • Unit - Order (Attacking Unit) to ( Attack targeting (Random Living unit from Unit Group)) (Replace Existing Orders)
  5. Siretu

    Siretu Starcraft 2 Editor Moderator Staff Member

    +295 / 0 / -0
    Okay, I've been a little inactive lately due to a very busy week. However, I always read everything in this forum the same day. I messed around with this today and I learned a lot. I'm not completely sure of the issues you're still having but I think Target sorts are the solution to all of them.

    Let's recap your problems(tell me if I got this wrong):

    1. You want to prioritize poisoned units differently.

    2. You don't want the poison tower and slow tower to target the same unit.

    First of all, from what I know, target sorts are available in weapons and search effects. They might be available elsewhere but I haven't really gone around and searched for them. However there is one problem, I can't get the weapon's target sorts to work. I don't know if I'm doing something wrong or if they just don't work. From what I can gather on the internet, they used to not work so that is probably still the case.

    Target sorts are kind of what they sound like. They're a way to handle how something chooses in what order to target units. If you for example have a search effect that selects ONLY one unit in a 6 radius and you want it to pick the one with the lowest shield, you could do it pretty easily with a standard target sort.

    For this we will need to create a custom target sort, don't worrry though. They're pretty easy to make and they have very few fields.

    1. Prioritize poisoned units
    I assume all poisoned units have some sort of behavior that acts as a debuff. I didn't really understand if you want the poison tower to target a non-poisoned target or if you wanted other towers to target a poisoned tower. Hopefully, when you understand target sorts you'll be able to figure out both cases. I'll explain how to make the poison tower target a non-poisoned target.

    Open up the data editor and open the "Edit Advanced Data>Target sorts" tab. Create a new target sort named "TSPoison" of the "Behavior count type"

    In the ":Behavior" field set it to your poison behavior. This means it'll sort the units with 0 poison debuffs first(since ":Value" is 0). That's all we need to do in the Target Sorts tab.

    Now we have a problem. Your tower probably has a weapon but since I can't get the target sorts to work for weapons, we'll have to make the weapon use a search effect. First go into your poison tower's weapon. Remember the effect in the "Effect: Effect" field.

    Go to the effect tab and create a new search effect called something like "Poison Weapon (Search)". Open the "Search: Areas +" field and create a new area.

    Set the Maximum count to 1, radius to the range of the tower and Effect to the effect from the "Effect: Effect" field on the weapon. Press okay.

    Next, change the "Search: Maximum Count" to 1. Open up the "Target: Target Sorts + " field.

    There are 3 fields here. "Request Count", "Request Percentage" and "Sorts". "Request Count" is how many targets will be acquired with a target sorts. If you have a weapon that shoots 5 projectiles each time and you want one to target normally and the other to use targets sorts.

    "Request Percentage" is the chance that you use a target sort. "Sorts" is what kind of target sort to use. Since we only have one target we don't have to worry too much. Set "Request Count" and "Request percentage" to 1. Add a target sort to the "Sorts" list. Add the "TSPoison" target sort you added earlier.

    Make sure you set the "Search: Search Filters" to the same thing as the weapons target filters. Otherwise you might fire upon yourself or your allies.

    Finally, go back to the weapons tab and change the "Effect: Effect" field to "Poison Weapon (Search)" (the search effect you created)

    2. Prevent Poison and Slow Tower from firing on the same target.
    I would do something similar to what we just did. First of all, create two hidden behaviors with a duration around 5 seconds. This will be used to reserve a target. Each tower will use this to reserve a target. Each weapon will have its own target sort that gives units with the other tower's reservation buff lower priority.

    This is very similar to what we just did for the poison tower but done twice. You will also need each tower to apply its own behavior. I would create an "Apply Behavior" effect and a "Set" effect. Change the weapon's effect to the set effect and add the "Apply Behavior" effect and the old weapon's effect to the Set effect.

    This was a kind of short explanation and I you'll likely run into some problem on the way that I didn't think of. Tell me how far you get and what problems you run into and we'll solve it from there.
  6. MissKerrigan

    MissKerrigan Active Member

    +23 / 0 / -0
    Thx Siretu for all your explaination but I already figured it out


    I just created a validator 'compare behavior count' and selected the poison behavior
    I went to the hydralisk weapon (poison tower) and just added the validator to the weapon

    Got 2 questions for Dave:

    1. How old are you?
    2. Did you really didn't know this?

  7. Siretu

    Siretu Starcraft 2 Editor Moderator Staff Member

    +295 / 0 / -0
    The problem with your solution is that if all targets are poisoned, it wont fire at all. I thought you wanted it to fire at all times but giving higher priority to units that aren't poisoned.

    As for Dave, I think it's possible he didn't think of it as a solution as you mentioned trying to use a validator without success.
  8. MissKerrigan

    MissKerrigan Active Member

    +23 / 0 / -0
    Yes Siretu you are right, the poison tower won't fire if all creeps are poisoned, but the poison tower wont hit all creeps before they all passed unless it's a boss

    But I triggered so that the poison tower only does poison damage and not an additional poison for Example:

    poison tower deals 25 damage + 10 x 5 poison damage
    In this case my solution wont work but I also figured out that!

    I got a stun tower that deals 250 damage + 10% chance to stun targeted creep (stun for 5 seconds)
    So if I would use my validator trick with the stun tower, it wouldn't be able to fire when a creep got stunned

    So I created 2 behaviors:

    1. stun (normal behavior)
    2. target change

    I created a validator 'compare behavior count' and added target change in this
    I modified the behavior 'target change' duration to 0.5 seconds

    So this means if a creep got stunned, the stun tower wont be able for 0.5 seconds to fire at the stunned creep and it will automatically after it stunned search for another creep
    If there is no other creep, it will fire at the stunned target again because the period of the stun tower is set to 1.5

    I starting to understand this editor now!


    note: I don't use 'suspress movement' in the stun behavior because the creep wont continue moving after stunned time running out so I set a speed multiplyer to 0.01 :) :)
  9. Dave312

    Dave312 Censored for your safe viewing

    +269 / 0 / -0
    1) why do you ask?
    2) I did know about this, but as Siretu said, the weapon will stop attacking if all units in range have been poisoned (that just seems backwards to me). What I was trying to do was make it such that the tower preferred attacking non-poisoned units but would still attack poisoned units if it had to.
  10. Siretu

    Siretu Starcraft 2 Editor Moderator Staff Member

    +295 / 0 / -0
    It's great to see that you're starting to understand how the data editor works :)
  11. MissKerrigan

    MissKerrigan Active Member

    +23 / 0 / -0
    Well Dave, it's a poison tower so it wont need to fire if a target got poisoned
    And if it must target poisoned units, I'll make a validator behavior compare with a behavior for like 0.5 seconds so it will find other target and if it doesn't it finally will target the same creep
  12. MissKerrigan

    MissKerrigan Active Member

    +23 / 0 / -0
    Alright Siretu,

    It is working now, my tower first shoots the targets which are not poisoned

    But the tower is NOT facing to it's target
    It's facing to the target it should fire at normally
    But the launch-missile goes to the target which is told by the target sort

    anyway, it feels like I learned another thing in the editor :)
  13. MissKerrigan

    MissKerrigan Active Member

    +23 / 0 / -0
    Alright let me give a good example:

    - 1 roach followed by 9 stalkers walking pass my marine-tower
    - my marine tower has the priority to shoot the stalker rather than the roach
    - so the marine shoots at the roach, facing the roach and damages the roach
    - but as soon the stalkers coming in range, the marine STILL facing the roach but the STALKER is taking damage

    so the target sort I created IS working but the only problem I've left is that the marine must FACE to the unit it fires at

    Anything unclear about this?

    (the post above was just a few months old)

Share This Page