| 07-25-2004, 04:20 PM | #1 |
Hi, can someone help me with a trigger? I want to do a single player map where the player controls 5 heroes. My question is: Is it possible to use arrow keys to select the "next" hero? For example, camera is locked on HeroA and I want to it to lock to HeroB by pressing the "-->" key and lock to HeroC by pressing the "-->" again, etc. If I press the "<--" it go back to the previous hero. If this is possible to do, can someone help me with this, please? Thanks. |
| 07-25-2004, 04:51 PM | #2 |
Do something like this: Set Up Events: Elapsed time is 0.1 game time seconds Actions: Set Heroes[1]= Blademaster Set Heroes[2]= Mountain King Set Controlled Hero= Heroes[1] (by defualt) Switch Events: Player 1 presses the right arrow key. Actions: For each (Integer A) from 1 to 2, do (Actions) Loop - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions Controlled Hero equal to Heroes[1] Then - Actions set Controlled Hero = Heroes[2] --Insert change camera view, cosmetic changes and all that stuff here. Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions Controlled Hero equal to Heroes[2] set Controlled Hero = Heroes[2] --Insert change camera view, cosmetic changes and all that stuff here. Then - Actions Else - Actions You'll just have to do it the other way around for the left key. Heroes is a Unit Array variable Controlled Hero is a Unit variable Hope that helped. |
| 07-25-2004, 04:56 PM | #3 |
Yes, it is entirely possible. Go to the variable editor and make a unit variable array (in my triggers, I will use a name for it "Heroes") and an integer variable (I call it "SelectedHero"). Then you need the following triggers: Code:
[i]initialization trigger[/i] Events: Map initialization Conditions: Actions: Set SelectedHero = 1 (this is a general - set variable action) Set Heroes[1] = The first hero on your map Set Heroes[2] = The second hero on your map ... Set Heroes[5] = The last hero on your map [i]You may have more or less than five heroes, this is just an example[/i] Code:
[i]move backwards through selection[/i]
Events:
Player - Player 1 (Red) Presses the Left Arrow key
Conditions:
Actions:
Set SelectedHero = SelectedHero - 1
If - then - else multiple functions
If - conditions:
SelectedHero = 0 (this is an integer comparison)
Then - actions:
Set SelectedHero = 5 (if you have more or less than 5 players, this number is different)
Else - actions:
Do nothing
If - then - else multiple functions
If - conditions:
Heroes[SelectedHero] is alive equal to false (this is a boolean comparison)
Then - Actions:
Trigger - Run [i]move backwards through selection[/i] (ignoring conditions) (this selects the next hero if the one you are trying to select is dead)
Skip remaining actions
Else - Actions:
Do nothing
Trigger - turn off [i]no deselecting[/i]
Selection - select Heroes[SelectedHero] for (triggering player)
Camera - Lock camera target for Player 1 (Red) to Heroes[SelectedHero], offset by (0.00, 0.00) using Default rotation
Trigger - turn on [i]no deselecting[/i]Code:
[i]move forward through selection[/i]
Events:
Player - Player 1 (Red) Presses the Right Arrow key
Conditions:
Actions:
Set SelectedHero = SelectedHero + 1
If - then - else multiple functions
If - conditions:
SelectedHero = 6 (this is an integer comparison)
Then - actions:
Set SelectedHero = 1
Else - actions:
Do nothing
If - then - else multiple functions
If - conditions:
Heroes[SelectedHero] is alive equal to false (this is a boolean comparison)
Then - Actions:
Trigger - Run [i]move forward through selection[/i] (ignoring conditions) (this selects the next hero if the one you are trying to select is dead)
Skip remaining actions
Else - Actions:
Do nothing
Trigger - turn off [i]no deselecting[/i]
Selection - select Heroes[SelectedHero] for (triggering player)
Camera - Lock camera target for Player 1 (Red) to Heroes[SelectedHero], offset by (0.00, 0.00) using Default rotation
Trigger - turn on [i]no deselecting[/i]Code:
[i]no deselecting[/i] Events: Player - Player 1 (Red) deselects a unit Conditions: Actions: Selection - select Heroes[SelectedHero] for (triggering player) |
| 07-25-2004, 06:10 PM | #4 | |
Quote:
i am utterly confused o_O but ill be sure to plug it in my map. it needs something like this really bad |
| 07-25-2004, 06:44 PM | #5 | |
Quote:
The first trigger runs at map initialization. It sets your heroes to an array variable (a normal variable that can store multiple values, in our case, multiple units), so you can acces them through this variable. Another important thing, it sets them in a specific order, so that if you have a hero selected that is stored in the third place in the array, then pressing the righ arrow key will select the hero that is fourth in the array, and the left arrow key will select the second in the array. The next two triggers are the ones that select another hero when you press left/right buttons. The left arrow selects the "previous" her in the array, the right arrow selects the "next" one. Which hero is selected is stored in the integer variable, so we modify the selection by decreasing or increasing that variable. Of course, if we increase the number so high that we have no heroes stored in the array under that number, the number must drop back to 1 (that is what the first if-then-else does in these triggers). Of course, when decreasing the number, we must change it to 5 when it drops below 1; this way, we keep circling through and through the heroes list. The second if - then - else is there to skip a hero if he is dead. So, if you want to swap from hero 3 to hero 2, the trigger will first swap down by 1, and if it sees that the hero 2 is dead, it will run itself again, swaping down again to hero 1. Of course, if hero 1 is dead as well, the trigger will notice this as well when it runs the second time, and then it will run again, the third time. This time, it would check for hero 0, but there is no hero 0, that's why the first if - then - else statement changes it to check the last hero, in my example hero 5. Of course, if all heroes are dead, trying to swap a hero selection would cause an infinite loop, crashing the game, you can solve this by disabling the hero swaping triggers if all heroes are dead. The last trigger just makes sure you can't deselect your hero; this is optional, you can also make it so thet you can select other units (in that case, you just don't put in this trigger), the camera will stay locked to the hero anyway. This is also why we disable this trigger in the hero swaping triggers; because, when those triggers select the other hero, the first one gets deselected, and we don't want this action to trigger the last trigger, so we disable it for that moment (again, if you don't choose to limit the player's selection to just the hero, you don't need the last trigger, so in that case, you don't need the actions in the swapping triggers to turn off that trigger, because that trigger isn't there.) |
| 07-25-2004, 08:43 PM | #6 |
Thanks for the help guys :D Anitarf, I was using the trigger you posted and it works great but I think I did something wrong. When I pressed the "--->" key, everything worked fine except that the camera doesn't lock on Hero 1 when he gets selected. The camera does lock on him when I selected him by using the "<---" key. Same goes for Hero 5 except it's the other way around. Camera doesn't lock on him when I selected him using "<---" but there is no problem when using "--->". Do you know what the problem might be? Thank again for all the help. |
| 07-25-2004, 09:33 PM | #7 |
That is wierd, the hero gets selected, but the camera doesn't lock on him? Now, I see why these situations are special; these are the situations when the trigger jumps from the end of the list back to the start, or from the start to the end when going backwards. I just can't see how this could affect anything. The switching-selection and the camera-locking happen one right after another at the end of the trigger, so it selects the right hero, but directly after that, it doesn't lock the camera onto him? That is strange. can you copy&paste the trigger here? (one of the two triggers will be enough, just right click the trigger name, select "copy as text" and paste it here in the [code] brackets) |
| 07-25-2004, 10:58 PM | #8 |
Forward: Events Player - Player 1 (Red) Presses the Right Arrow key Conditions Actions Set SelectedHero = (SelectedHero + 1) If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions SelectedHero Equal to 6 Then - Actions Set SelectedHero = 1 Else - Actions Do nothing If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Heroes[SelectedHero] is Dead) Equal to True Then - Actions Trigger - Run Forward <gen> (ignoring conditions) Else - Actions Do nothing Trigger - Turn off Deselect <gen> Selection - Select Heroes[SelectedHero] Camera - Lock camera target for Player 1 (Red) to Heroes[SelectedHero], offset by (0.00, 0.00) using Default rotation Trigger - Turn on Deselect <gen> It's weird but i think it does have something to do with the begining and end of the list. Take Hero 1 for example. If I press forward to Hero 2 and backward again to Hero 1, then go backward to Hero 5 and finally forward to Hero 1 again, then the camera locks on Hero 1. Now, If i keep going foward through the rest of the characters and end up on Hero 1 again, the camera doesn't lock on him. Kinda hard to explain o_O Other problems i noticed is that if i turn off the (No deselection), Hero 1 and Hero 5 doesn't get selected at all and if I press the farward and backward key too many times the game locks up :( |
| 07-25-2004, 11:03 PM | #9 |
I can't see anything incorrect with this. It's exactly what i and Anitarf said, the whoel thing seems really weird, but it has to have somethin to do with the conversion of 6 > 1 and 0 > 5. You could try to make the array larger so instead of 5, have 25 and hope nobody presses right to many times. That's not a very stable solution though =). |
| 07-26-2004, 08:36 AM | #10 |
Okay, let's try to debug. First of all, save a copy of the triggers, because we're going to start with deleting stuff. After you have a safe copy, delete the part that checks if a hero is dead (you forgot to put "skip remaining actions" in this part, but that can't possibly be the cause of your problem, so we'll just try first without the hero-is-dead detection). Also, delete the trigger that prevents hero deselection. And, for the end, put at the end of the two swaping triggers the action "game - display message to all players (convert integer to string(SelectedHero))"Now try out how is it working. Whenever swaping, the triggers will also display the number of hero that is chosen. |
| 07-26-2004, 04:59 PM | #11 |
Forward: Events Player - Player 1 (Red) Presses the Right Arrow key Conditions Actions Set SelectedHero = (SelectedHero + 1) If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions SelectedHero Equal to 6 Then - Actions Set SelectedHero = 1 Else - Actions Do nothing Game - Display to (All players) the text: (String(SelectedHero)) This shows a number corresponding to the hero when I press the arrow keys. no camera lock and and heroes don't get selected. on the original triggers, if I add in an action "lock camera to Heroes[SelectedHero]", it would work nicely except that it would also lock on the dead heroes :( . |
| 07-26-2004, 05:20 PM | #12 |
I think you deleted too many things. The trigger should still have "lock selection on hero" and "select hero" at the end besides just the "display text message". When you have that (which is the same as my original triggers except it doesn't have the "skip dead heroes" part), check if it still doesn't lock on hero 5 when you press the backwards button (if I remeber right, that was our original problem). If the trigger still doesn't work in that case, then post it again and we'll try to figure things out. Otherwise, if the trigger works ok, then re-add the "if - then - else" that checks for dead heroes (the triggers are a few posts back, don't forget to put in the "skip remaining actions" in this time). |
| 07-26-2004, 05:34 PM | #13 |
OK, I feel really stupid now lol. I found out what MY mistake is ^_^ the triggers worked. I had the 2nd part "If all conditions are true/check hero dead or alive" under the first action and that's what caused the problem. I feel like smacking myself now hehe. Sorry, for all the trouble and I really appreacite you taking the time to help me with this. Only question i have left is, If i add in a timer that I can selected between heroes, would that stop the game from crashing. It crashes if i keep spaming the arrow keys. |
| 07-26-2004, 08:45 PM | #14 |
Hmm, I don't know why the game crashes if you spam arrow keys, and I don't know if it won't crash if you spam slower, but an easy method to limit the speed with which you can use the arrow keys is by adding in another trigger: Code:
NoSwitchingForOneSecond Events: Conditions: Action: trigger - turn off SwitchForward trigger - turn off SwitchBackwards wait 1 second trigger - turn on SwitchForward trigger - turn on SwitchBackwards And then add this line to the very end of each of your two switching triggers: Code:
trigger - run NoSwitchingForOneSecond |
| 07-27-2004, 03:06 PM | #15 |
I think the game locks up when I spam the forward arrow key and then hit the backward arrow real quick before the the hero gets selected. I'll give this trigger a try. Thanks a lot for everything :D |
