| 01-17-2004, 04:23 AM | #1 |
I want to have a trigger than detects a unit within 60 of (last created unit) and put them into CountUnits (a unit group var). Then, if the number of units in unit group is not equal to 0, then do remove (last created unit) from the game. Then, to make sure it doesn't stay at 0, I did a 'Unit group - clear units from (Countunits) Here are the triggers so far Conditions : -(Unit-type of (Last created unit)) Equal to Circle of Power Actions : -Unit Group - Pick every unit in (Units within 60.00 of (Position of (Last created unit))) and do (Unit Group - Add (Picked unit) to CountUnits) -If ((Number of units in CountUnits) Not equal to 0) then do (Unit - Remove (Last created unit) from the game) else do (Do nothing) -Unit Group - Remove all units from CountUnits I have this trigger run every time a circle of power is created. Basically, I dont want to have a circle of power spawned under a unit. When I do what I have shown, none of the circle of powers appear. Help is appreciated! |
| 01-17-2004, 04:30 AM | #2 |
It's quite simple, really. There can never be 0 units within range, since the circle of power itself is an unit. Just replace '0' with '1', and it should work. |
| 01-17-2004, 04:39 AM | #3 |
Ok I tried what you did, and it seems im one step closer to getting it right. But now, even when I set the range to 0 or such, there are still no circles being created. For some reason, they are all being removed. . . |
| 01-17-2004, 04:51 AM | #4 |
Did you try just changing "((Number of units in CountUnits) Not equal to 0)" to "((Number of units in CountUnits) Not equal to 1)"? If that somehow failed to work, here's how I would do it, if I was the one making the map. No real need to use unit groups in the first place, if you're just going to count the units in them. (Disregard any minor errors, since I'm just typing this up instead of copying it from the trigger editor. Code:
Conditions : -(Unit-type of (Last created unit)) Equal to Circle of Power Actions : -Set counterInt = 0 -Unit Group - Pick every unit in (Units within 60.00 of (Position of (Last created unit)) matching (Matching Unit is alive)) and do (Set counterInt = counterInt +1) -If (counterInt Not equal to 1) then do (Unit - Remove (Last created unit) from the game) else do (Do nothing) -Set counterInt = 0 |
| 01-17-2004, 05:04 AM | #5 |
Ok, works just as well. But I have discovered that there is a problem with using (last created unit). It works when using a preplaced unit, but somehow, (last created unit) doesnt respond. I have tested this with debug text messages and found that a preplaced unit works, but using last created unit, does not. Here are the unit creation triggers : -Unit - Create 1 Circle of Power for PlayerTurn at ((Position of HumanSelectedUnit) offset by (128.00, 0.00)) facing Default building facing degrees -Trigger - Run DetectUnit <gen> (checking conditions) -Unit - Create 1 Circle of Power for PlayerTurn at ((Position of HumanSelectedUnit) offset by (256.00, 0.00)) facing Default building facing degrees -Trigger - Run DetectUnit <gen> (checking conditions) and so forth. I have NO idea why its not working edit - the unit isnt even being CREATED!! yet ive gone over my triggers a thousand times and i can't see any reason why the trigger shouldnt be run. . . i did a text message to enter the name of LastCreatedCoP (variable = last created unit) and it didnt give me anything. I have to look over this harder . . . edit 2 - the unit creation trigger is being run, but the unit creation actions themselves are not. This is a major confusion and im getting really pissed off. this is the most bizzare trigger problem i have run into. edit 3 - I FIGURED IT OUT!!! and im not going to tell you why, because im way to embarrased to show you how retarded i am. lets just say it had something to do with a variable that hadnt been set . . . |
| 01-17-2004, 05:32 AM | #6 |
Well of course it ain't gonna work. Just think about it in JASS terms man. Last created unit is a local variable, meaning it has no effect on other triggers unless responding to that event. Make a global variable (normal variable that you would make with the GUI) and set (your variable) = Last created unit. In the other trigger instead of calling for the last created unit, call for your variable. If you ever have an event response, it is treated as a local variable so it can't be used outside of that function unless it is assigned to a global variable. [edit] as i was writing you posted your edit 3 on the existing post, lol :ggani: |
| 01-17-2004, 05:32 AM | #7 |
Ok new question - How do i detect the unit that has been removed from the game? |
| 01-17-2004, 05:37 AM | #8 |
If you told it to remove the unit, then it will. But if you want to run another trigger as the unit is being removed, then make your if-then-else in the if-then-else multiple stuff format. Put the remove unit in and tell it to run another trigger also. In the trigger that is run you can then do whatever you want. Some examples would be; set a boolean equal to true, set an integer equal to itself + 1, do the actions you wish to do, whatever. Have fun!:ggani: |
| 01-17-2004, 05:57 AM | #9 |
Wow it works perfectly. Thank you all, you will all be in my credits with shooting stars around your names! |
