I'd like to be able to set an Event trigger to the equivalent of "If a unit has changed owners" but haven't had much luck.
Has anybody already been successful at that, or have any bright ideas?
I moved on to trying to create a custom Event, but that's been hellish, with the compiler screaming "Wrong number of Parameters!" at me constantly...I think I can solve the problem with some clever logic and a variable here or there - but it'd be nice to have it done cleanly with a simple Event.
I haven't messed around with ownership too much but I don't remember any way to change the owner of a unit except with triggers.
If you're using triggers to change the owner of a unit I don't see why you would need to detect when it happens since you're the one who is making it happen in the first place. So you just do whatever you need to do after changing the owner.
I you're somehow changing the owner some other way, and there is no event to detect this action; the only way to check for it would be to use a periodic timer that checks the owner and stores the result in a variable, if the owner does not equal the stored variable, the owner has changed.
At what times is it possible for a unit in your game to change owners? Maybe you can use a trigger to catch that event? Like when they can only change users if a certain ability is used or something.
Otherwise i think i know a very complicated workaround, but i don't think it's really useful (would be laggy with lots of units)...
Edit: Hehe, hddante beats me :) Actually that was the workaround i was thinking of, but for lots of units and a smal interval i don't know how it would perform, but i haven't that much experience in that matter.
You do not need to detect the change if another trigger causes the change. Simply, after the change, call the trigger/function that should occur following the change. There is a Run Trigger command, or you can use a custom action. No events = less execution time :)
Short answer: Any time a unit Enters/Leaves/Dies in a region it's counted in an array. A trigger procs every second and compares the numbers of units in the array and stores the index corresponding to the largest value in a separate variable. Then an action sets ownership of the region to the value of that separate variable.
I have regions which switch control to the player with the most units inside of them - the triggers take into account entering/leaving/dying units.
Once a player has taken control of a region I want them to gain some kind of bonus. In the Blizz library I found an action that supposedly returns the owner of a unit, but I couldn't actually find it in the GUI to use - figured I would store the current owner in a variable and check for a change. I've tried making my own custom Event which would monitor for changes in ownership, but I get that damned "Wrong number of parameters!" error and I haven't figured out why yet (NOTE: I have no internet at my house, so I'm running Patch 10 (?) version of the Editor - not the latest by 2 patches I think, maybe 3 - could be some unfixed bugs I'm unaware of).
1. I didn't think about attaching the effects to the trigger which causes the ownership change in the first place. I could take a look and see if that'll fit what I want to do - but it feels like it'd be cleaner to have a separate event.
2. I didn't want to just run a timer - I haven't had many discussions re: lag caused by triggers and timers so I kinda wanted to exercise my brain and try to sort out an Event - but yeah...I could use a timer and check for an ownership change with a variable.
3. I can probably 'jury-rig' it to work with your ideas above - but damn, more than anything I'd love to make my own Event, and especially know why I'm getting the damned wrong number of parameters crap.
Can you do it with this are isnt it possible.
2 variables : OldOwner and NewOwner which are both integers.
<> - Test
Events
Timer - Every 5.0 seconds of Game Time
Local Variables
Conditions
Actions
Variable - Set OldOwner = NewOwner
Variable - Set NewOwner = (Owner of (Picked unit))
General - If (Conditions) then do (Actions) else do (Actions)
If
Not
Conditions
NewOwner == OldOwner
Then
------- Action-------
Else
If I understand your trigger correctly, I'm not exactly sure why you need a trigger to needlessly proc every second. Though maybe there's more to it that I don't know about. I *think* if a unit dies within a region, a "unit leaves region" event is procced, but I could be mistaken, so I'd test it before taking my word on it. The following 2 global variables and 2 triggers should switch the ownership of a region when one player has more units than the current owner of the region without proccing the trigger once every 1.0 seconds.
GlobalVariables:NumOfUnitsInRegion[X]={0,0...}// Adjust 'X' to the number of playersCurrentRegionOwner=0// '0' denotes player 1
EventsUnit-AnyUnitEnters<Region>LocalVariablesConditionsActionsSetNumOfUnitsInRegion[((Triggeringplayer)-1)] = (NumOfUnitsInRegion[((Triggeringplayer)-1)] + 1)
General - If (Conditions) then do (Actions) else do (Actions)
If
And
((Triggering player) - 1) != CurrentRegionOwner
NumOfUnitsInRegion[CurrentRegionOwner]< NumOfUnitsInRegion[((Triggeringplayer)-1)]ThenCurrentRegionOwner =((Triggeringplayer)-1)Else
EventsUnit-AnyUnitLeaves<Region>LocalVariablesPlayerNum=0ConditionsActionsSetNumOfUnitsInRegion[((Triggeringplayer)-1)] = (NumOfUnitsInRegion[((Triggeringplayer)-1)] - 1)
General - If (Conditions) then do (Actions) else do (Actions)
If
((Triggering player) - 1) == CurrentRegionOwner
Then
//Adjust "X" to the number of players in your map below
For each integer PlayerNum from 0 to X with increment 1, do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
NumOfUnitsInRegion[CurrentRegionOwner]< NumOfUnitsInRegion[PlayerNum]ThenCurrentRegionOwner =PlayerNumElseElse
I'd like to be able to set an Event trigger to the equivalent of "If a unit has changed owners" but haven't had much luck.
Has anybody already been successful at that, or have any bright ideas?
I moved on to trying to create a custom Event, but that's been hellish, with the compiler screaming "Wrong number of Parameters!" at me constantly...I think I can solve the problem with some clever logic and a variable here or there - but it'd be nice to have it done cleanly with a simple Event.
How are you changing the unit's owner ?
I haven't messed around with ownership too much but I don't remember any way to change the owner of a unit except with triggers.
If you're using triggers to change the owner of a unit I don't see why you would need to detect when it happens since you're the one who is making it happen in the first place. So you just do whatever you need to do after changing the owner.
I you're somehow changing the owner some other way, and there is no event to detect this action; the only way to check for it would be to use a periodic timer that checks the owner and stores the result in a variable, if the owner does not equal the stored variable, the owner has changed.
At what times is it possible for a unit in your game to change owners? Maybe you can use a trigger to catch that event? Like when they can only change users if a certain ability is used or something.
Otherwise i think i know a very complicated workaround, but i don't think it's really useful (would be laggy with lots of units)...
Edit: Hehe, hddante beats me :) Actually that was the workaround i was thinking of, but for lots of units and a smal interval i don't know how it would perform, but i haven't that much experience in that matter.
@ Above two.
You do not need to detect the change if another trigger causes the change. Simply, after the change, call the trigger/function that should occur following the change. There is a Run Trigger command, or you can use a custom action. No events = less execution time :)
@ShadowLightX: Go
It would be awesome if you could read the post you're replying to next time.
Short answer: Any time a unit Enters/Leaves/Dies in a region it's counted in an array. A trigger procs every second and compares the numbers of units in the array and stores the index corresponding to the largest value in a separate variable. Then an action sets ownership of the region to the value of that separate variable.
I have regions which switch control to the player with the most units inside of them - the triggers take into account entering/leaving/dying units.
Once a player has taken control of a region I want them to gain some kind of bonus. In the Blizz library I found an action that supposedly returns the owner of a unit, but I couldn't actually find it in the GUI to use - figured I would store the current owner in a variable and check for a change. I've tried making my own custom Event which would monitor for changes in ownership, but I get that damned "Wrong number of parameters!" error and I haven't figured out why yet (NOTE: I have no internet at my house, so I'm running Patch 10 (?) version of the Editor - not the latest by 2 patches I think, maybe 3
- could be some unfixed bugs I'm unaware of).1. I didn't think about attaching the effects to the trigger which causes the ownership change in the first place. I could take a look and see if that'll fit what I want to do - but it feels like it'd be cleaner to have a separate event. 2. I didn't want to just run a timer - I haven't had many discussions re: lag caused by triggers and timers so I kinda wanted to exercise my brain and try to sort out an Event - but yeah...I could use a timer and check for an ownership change with a variable. 3. I can probably 'jury-rig' it to work with your ideas above - but damn, more than anything I'd love to make my own Event, and especially know why I'm getting the damned wrong number of parameters crap.
Can you do it with this are isnt it possible.
2 variables : OldOwner and NewOwner which are both integers.
<> - Test
Events
Timer - Every 5.0 seconds of Game Time
Local Variables
Conditions
Actions
Variable - Set OldOwner = NewOwner
Variable - Set NewOwner = (Owner of (Picked unit))
General - If (Conditions) then do (Actions) else do (Actions)
If
Not
Conditions
NewOwner == OldOwner
Then
------- Action-------
Else
Khazr - that's one of the solutions I considered.
Ultimately I decided to go with just proc'ing the region effect trigger when the ownership changed.
If I understand your trigger correctly, I'm not exactly sure why you need a trigger to needlessly proc every second. Though maybe there's more to it that I don't know about. I *think* if a unit dies within a region, a "unit leaves region" event is procced, but I could be mistaken, so I'd test it before taking my word on it. The following 2 global variables and 2 triggers should switch the ownership of a region when one player has more units than the current owner of the region without proccing the trigger once every 1.0 seconds.
Azkit, in my tests, a unit dying inside a region did not count as a unit leaving a region.
And actually - at a quick glance, your script looks more efficient than mine. I need some time to evaluate it vs. what I have and see if it works.
EDIT: Went back and implemented Azkit's suggestion - it's cleaner (eliminates a spammed trigger) and more compact so I implemented it. Thanks Azkit :)